Toggle Menu
Prev Up Next

scikit-learn 1.3.2
Other versions

Please cite us if you use the software.

# `sklearn.feature_extraction.image`.img_to_graph

sklearn.feature_extraction.image.img_to_graph(img, *, mask=None, return_as=<class 'scipy.sparse._coo.coo_matrix'>, dtype=None)

  Graph of the pixel-to-pixel gradient connections.

  Edges are weighted with the gradient values.

  Read more in the User Guide.

  Parameters:
    img array-like of shape (height, width) or (height, width, channel)

      2D or 3D image.

    mask ndarray of shape (height, width) or (height, width, channel), dtype=bool, default=None

      An optional mask of the image, to consider only part of the pixels.

    return_as np.ndarray or a sparse matrix class, default=sparse.coo_matrix

      The class to use to build the returned adjacency matrix.

    dtype dtype, default=None

      The data of the returned sparse matrix. By default it is the dtype of img.

  Returns:
    graph ndarray or a sparse matrix class

      The computed adjacency matrix.

  Notes

  For scikit-learn versions 0.14.1 and prior, return_as=np.ndarray was handled by returning a dense np.matrix instance. Going forward, np.ndarray returns an np.ndarray, as expected.

  For compatibility, user code relying on this method should wrap its calls in `np.asarray` to avoid type issues.