Convert RGB image to label
Show older comments
This function converts my labeled image into an RGB https://www.mathworks.com/help/images/ref/label2rgb.html Is it possible to convert an RGB image into a labeled one ? Because the algorithm I am running returns me a color per label but I need the label only.
I tried the solution posted below but it didnt give me the right results. The first image is the output of the algorithm, each cluster in the image has its own color. The second image is the result of running the code below.
BW = im2bw(I, graythresh(I));
CC = bwconncomp(BW);
L = labelmatrix(CC);
imagesc(L);


Accepted Answer
More Answers (1)
Jan
on 14 Jul 2017
Did you see the examples in the doc of label2rgb?
BW = im2bw(I, graythresh(I));
CC = bwconncomp(BW);
L = labelmatrix(CC);
bwlabeln might be useful also, but you need a BW image at first.
Categories
Find more on Modify Image Colors in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!