How to color code a black and white image by area?

11 ビュー (過去 30 日間)
Bennett Lambert
Bennett Lambert 2015 年 8 月 4 日
編集済み: Walter Roberson 2015 年 8 月 5 日
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

採用された回答

Walter Roberson
Walter Roberson 2015 年 8 月 5 日
編集済み: Walter Roberson 2015 年 8 月 5 日
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);
  1 件のコメント
Bennett Lambert
Bennett Lambert 2015 年 8 月 5 日
This worked perfect! I just added:
map = colormap;
map(1,:) = [0,0,0];
colormap(map)
to get them to display on a black background and it's exactly what I was looking for.
Thanks!

サインインしてコメントする。

その他の回答 (1 件)

Bennett Lambert
Bennett Lambert 2015 年 8 月 5 日
Thanks so much for taking the time to answer!

カテゴリ

Help Center および File ExchangeWhite についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by