skimage2.graph.pixel_graph#

skimage2.graph.pixel_graph(image, *, mask=None, edge_function=None, connectivity=1, spacing=None)[source]#

Create an adjacency graph of pixels in an image.

Pixels where the mask is True are nodes in the returned graph, and they are connected by edges to their neighbors according to the connectivity parameter. By default, the value of an edge when a mask is given, or when the image is itself the mask, is the Euclidean distance between the pixels.

However, if an int- or float-valued image is given with no mask, the value of the edges is the absolute difference in intensity between adjacent pixels, weighted by the Euclidean distance.

Parameters:
imagearray

The input image. If the image is of type bool, it will be used as the mask as well.

maskarray of bool

Which pixels to use. If None, the graph for the whole image is used.

edge_functioncallable

A function taking an array of pixel values, and an array of neighbor pixel values, and an array of distances, and returning a value for the edge. If no function is given, the value of an edge is just the distance.

connectivityint

The square connectivity of the pixel neighborhood: the number of orthogonal steps allowed to consider a pixel a neighbor. See scipy.ndimage.generate_binary_structure for details.

spacingtuple of float

The spacing between pixels along each axis.

Returns:
graphscipy.sparse.csr_array

A sparse adjacency matrix in which entry (i, j) is 1 if nodes i and j are neighbors, 0 otherwise.

nodesarray of int

The nodes of the graph. These correspond to the raveled indices of the nonzero pixels in the mask.