Dr Ema
Dr Ema

Reputation: 35

How to display a connected component image with threshold of some specific property say 'Area'

I found an image's connected components using

La=bwlabel(labeledImage,8); %%% labeledImage is a binary image
figure,imshow(La,[]);
coloredLabel = label2rgb (La, 'hsv', 'k', 'shuffle');
imshow(coloredLabel);

now I want to show (display), in Matlab, connected components (in color) which have area less than that of '7' pixels and more than '7' separately, as two different images. Can someone Help me please.

Thanks in advance...

Upvotes: 2

Views: 611

Answers (1)

Shai
Shai

Reputation: 114856

A bit tricky, but here's one way of doing this using regionprops:

pr = regionprops( La, 'Area', 'PixelIdxList' );

smallArea = La;
small_select = [pr.Area] <= 7; %// select regions smaller than 7 pixels
smallArea( vertcat( pr(~small_select).PixelIdxList ) ) = 0; %// set all other regions to zero
imshow( smallArea ); colormap( rand(max(smallArea(:)), 3) );

Upvotes: 2

Related Questions