assigning color to binary image
Afficher commentaires plus anciens
I have an image consisting of values 1 to 7. I want to show each value with specific color (green,blue,yellow,cyan,magenta,maroon, and sea green). I think I need to use colormap function but dont know how. Any suggestion please?
imshow(BW)
colormap(?)
Réponse acceptée
Plus de réponses (2)
Image Analyst
le 27 Déc 2011
That's not a binary image. It's probably a labeled image, which is a double. Look at this snippet of code that assigns a multitude of different colors to the regions:
% Label each blob with 8-connectivity, so we can make measurements of it
[labeledImage numberOfBlobs] = bwlabel(binaryImage, 8);
% Apply a variety of pseudo-colors to the regions.
coloredLabelsImage = label2rgb (labeledImage, 'hsv', 'k', 'shuffle');
% Display the pseudo-colored image.
imshow(coloredLabelsImage);
Sukuchha
le 27 Déc 2011
first of all if your image is binary, you cant have values from 1 to 7.
if you have image with values 1 to 7, first you have label the connected components.
CC = bwconncomp(BW);
L = labelmatrix(CC);
RGB = label2rgb(L);
figure, imshow(RGB)taken from help file of label2rgb
see doc label2rgb
4 commentaires
Hassan
le 27 Déc 2011
Walter Roberson
le 27 Déc 2011
I suspect you only need
cmap = [0 0 0; 0 1 0; 0 0 1; ... ]; %black then each color
colormap(cmap);
RGB = label2rgb(YourImage);
image(RGB)
Hassan
le 27 Déc 2011
Image Analyst
le 27 Déc 2011
Funny, same function as I used, label2rgb. But you're saying now that you don't have a labeled image and that you don't care about labels or connected regions. So that if you had 15 blobs with gray level 4, then all 15 of those should be the same color. And if you had 42 blobs with gray level 5, then all 42 of those should be the same color (but different than the color used for gray level 4). You can do that with just the regular colormap, like my answer below, without having to use label2rgb at all.
Catégories
En savoir plus sur Blue dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!