rag_mean_color
-
skimage.future.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
image
with the same label inlabels
. The weight between two adjacent regions represents how similar or dissimilar two regions are depending on themode
parameter.Parameters: image : ndarray, shape(M, N, [..., P,] 3)
Input image.
labels : ndarray, shape(M, N, [..., P,])
The labelled image. This should have one dimension less than
image
. Ifimage
has dimensions(M, N, 3)
labels
should have dimensions(M, N)
.connectivity : int, optional
Pixels with a squared distance less than
connectivity
from each other are considered adjacent. It can range from 1 tolabels.ndim
. Its behavior is the same asconnectivity
parameter inscipy.ndimage.generate_binary_structure
.mode : {‘distance’, ‘similarity’}, optional
The strategy to assign edge weights.
‘distance’ : The weight between two adjacent regions is the , where and are the mean colors of the two regions. It represents the Euclidean distance in their average color.
‘similarity’ : The weight between two adjacent is where , where and are the mean colors of the two regions. It represents how similar two regions are.
sigma : float, optional
Used for computation when
mode
is “similarity”. It governs how close to each other two colors should be, for their corresponding edge weight to be significant. A very large value ofsigma
could make any two colors behave as though they were similar.Returns: out : RAG
The region adjacency graph.
References
[R226] Alain Tremeau and Philippe Colantoni “Regions Adjacency Graph Applied To Color Image Segmentation” http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.11.5274 Examples
>>> from skimage import data, segmentation >>> from skimage.future import graph >>> img = data.astronaut() >>> labels = segmentation.slic(img) >>> rag = graph.rag_mean_color(img, labels)
Please login to continue.