user288609
user288609

Reputation: 13025

the output of color.label2rgb in skimage

In the normalized cut code segment, I am not very clear about the output of color.label2rgb.

labels1 = segmentation.slic(img, compactness=30, n_segments=400)
out1 = color.label2rgb(labels1, img, kind='avg')

when I output the result of labels1 and the different dimensions of out1, looks like the result of out1 does not match the entry values in labels1. What are the meanings of the entry values in out1. How do they relate to the label IDs in labels1?

enter image description here

Upvotes: 1

Views: 5875

Answers (1)

seralouk
seralouk

Reputation: 33147

segmentation.slic will segment the image using k-means clustering in Color-(x,y,z) space.

np.unique(labels1) will give you the labels.


Next, color.label2rgb returns an RGB image where color-coded labels are painted over the image.

out1.shape returns (400, 600, 3) and this is the result of blending a cycling colormap (colors) for each distinct value in label with the image, at a certain alpha value.

Also, there is a default input argument in color.label2rgb named kind.

The kind of color image desired. ‘overlay’ cycles over defined colors and overlays the colored labels over the original image. ‘avg’ replaces each labeled segment with its average color, for a stained-class or pastel painting appearance.

So in your case, you replace each labeled segment with its average color, for a stained-class or pastel painting appearance.

Upvotes: 1

Related Questions