Graph of the pixel-to-pixel connections.
Edges exist if 2 voxels are connected.
Dimension in x axis.
Dimension in y axis.
Dimension in z axis.
An optional mask of the image, to consider only part of the pixels.
The class to use to build the returned adjacency matrix.
The data of the returned sparse matrix. By default it is int.
The computed adjacency matrix.
>>> import numpy as np >>> from sklearn.feature_extraction.image import grid_to_graph >>> shape_img = (4, 4, 1) >>> mask = np.zeros(shape=shape_img, dtype=bool) >>> mask[[1, 2], [1, 2], :] = True >>> graph = grid_to_graph(*shape_img, mask=mask) >>> print(graph) <COOrdinate sparse matrix of dtype 'int64' with 2 stored elements and shape (2, 2)> Coords Values (0, 0) 1 (1, 1) 1
© 2007–2025 The scikit-learn developers
Licensed under the 3-clause BSD License.
https://scikit-learn.org/1.6/modules/generated/sklearn.feature_extraction.image.grid_to_graph.html