How to label objects based on their area?

3 ビュー (過去 30 日間)
Meshooo
Meshooo 2014 年 1 月 21 日
編集済み: Meshooo 2014 年 1 月 23 日
Dear all,
I have an image that contains many objects. I want to label each object with different color such that objects with the same area will have the same label color. In the same way, small objects will appear with a color located down of the jet color map (dark blue), while larger object will have a color located up of the jet color map (dark red). I am now using this code which label the objects randomly with different color
img = imread('real_sampel_dilate1.tif'); % input image attached here
%
I = im2bw(img);
I = ~I;
I = (I==0);
cc = bwconncomp(I,8);
s = regionprops(cc,img,'all');
L = labelmatrix(cc);
RGB_label = label2rgb(L, @jet, 'k', 'shuffle');
%
imshow(RGB_label); % the result randomly labeled of object attached here
Do anyone knows how to do such area-based labeling?
Any suggestion will be appreciated.
Best, Meshoo

回答 (1 件)

Explorer
Explorer 2014 年 1 月 21 日
編集済み: Explorer 2014 年 1 月 21 日
Have a look on answer of Image Analyst. He has labeled face and hand on the basis of area.
  2 件のコメント
Meshooo
Meshooo 2014 年 1 月 21 日
Thank you very much. I tried the following code but it doesn't work..
img = imread('real_sampel_dilate1.tif');
%
I = im2bw(img);
I = ~I;
I = (I==0); % invert the image
cc = bwconncomp(I,8); % could use 4-connected neighborhood also
s = regionprops(cc,img,'all');
L = labelmatrix(cc);
RGB_label = label2rgb(L, @jet, 'k', 'shuffle');
imshow(RGB_label);
Label the image
labeledImage = bwlabel(I);
measurements = regionprops(labeledImage, 'BoundingBox', 'Area');
for k = 1 : length(measurements)
thisBB = measurements(k).BoundingBox;
rectangle('Position', [thisBB(1),thisBB(2),thisBB(3),thisBB(4)],...
'EdgeColor','r','LineWidth',2 )
end
Explorer
Explorer 2014 年 1 月 21 日
These below mentioned lines are for drawing bounding box around every object in image.
for k = 1 : length(measurements)
thisBB = measurements(k).BoundingBox;
rectangle('Position', [thisBB(1),thisBB(2),thisBB(3),thisBB(4)],...
'EdgeColor','r','LineWidth',2 )
end

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

カテゴリ

Help Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by