skimage2.graph.rag_mean_color#
- skimage2.graph.rag_mean_color(image, labels, connectivity=2, mode='distance', sigma=255.0)[source]#
Compute the Region Adjacency Graph using mean colors.
Given an image and its initial segmentation, this method constructs the corresponding Region Adjacency Graph (RAG). Each node in the RAG represents a set of pixels within
imagewith the same label inlabels. The weight between two adjacent regions represents how similar or dissimilar two regions are depending on themodeparameter.- Parameters:
- imagendarray, shape(M, N[, âĶ, P], 3)
Input image.
- labelsndarray, shape(M, N[, âĶ, P])
The labelled image. This should have one dimension less than
image. Ifimagehas dimensions(M, N, 3)labelsshould have dimensions(M, N).- connectivityint, optional
Pixels with a squared distance less than
connectivityfrom each other are considered adjacent. It can range from 1 tolabels.ndim. Its behavior is the same asconnectivityparameter inscipy.ndimage.generate_binary_structure.- mode{âdistanceâ, âsimilarityâ}, optional
The strategy to assign edge weights.
âdistanceâ : The weight between two adjacent regions is the \(|c_1 - c_2|\), where \(c_1\) and \(c_2\) are the mean colors of the two regions. It represents the Euclidean distance in their average color.
âsimilarityâ : The weight between two adjacent is \(e^{-d^2/sigma}\) where \(d=|c_1 - c_2|\), where \(c_1\) and \(c_2\) are the mean colors of the two regions. It represents how similar two regions are.
- sigmafloat, optional
Used for computation when
modeis âsimilarityâ. It governs how close to each other two colors should be, for their corresponding edge weight to be significant. A very large value ofsigmacould make any two colors behave as though they were similar.
- Returns:
- outRAG
The region adjacency graph.
References
[1]Alain Tremeau and Philippe Colantoni âRegions Adjacency Graph Applied To Color Image Segmentationâ DOI:10.1109/83.841950
Examples
>>> from _skimage2 import data, segmentation, graph >>> img = data.astronaut() >>> labels = segmentation.slic(img) >>> rag = graph.rag_mean_color(img, labels)