How to color code a black and white image by area?
11 views (last 30 days)
Show older comments
Bennett Lambert
on 4 Aug 2015
Edited: Walter Roberson
on 5 Aug 2015
Hi Everyone,
I have a black and white image that I've done some morphological operations on and then run regionprops to get information about region areas and perimeters.
My question is how would I go about creating an image that has these regions color coded by the area found using region props? I've searched all over the internet and can't seem to find any leads.
Thanks for your help
0 Comments
Accepted Answer
Walter Roberson
on 5 Aug 2015
Edited: Walter Roberson
on 5 Aug 2015
labelBW = bwlabel(YourBWImage);
reginfo = regionprops(labelBW, 'Area');
all_area = [reginfo.Area];
rel_area = all_area(:) ./ max(all_area);
Now that we have relative areas, we need to color code. We could easily convert to grayscale but that would not be very colorfull. So for lack of better instructions as to how to code the colors, code the relative area as being the hue. Do not just take the raw relative area as that would range 0 to 1 and hue 1 is the same as hue 0 (it wraps around). To prevent color confusion, we limit the upper value of the hue
hue = rel_area * 0.85;
hsvtab = [hue, ones(size(hue,1),2)];
rgbtab = hsv2rgb(hsvtab);
Now that we have an RGB color table we can display the image and activate the colormap
image(labelBW);
colormap(rgbtab);
More Answers (1)
See Also
Categories
Find more on White in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!