Filtering binary image object based on area

조회 수: 4 (최근 30일)
Stewart Tan
Stewart Tan 2019년 9월 27일
답변: darova 2019년 9월 27일
I have a binary image below:
Capture.PNG
and the four straight objects are trees which i want to keep and the blob below is an unwanted object in the binary image. I'm using bwareafilt to extract only the objects i want, which in this case would be the four trees. However, by using:
regionprops(binimg, 'Area')
I get:
Capture2.PNG
and the unfortunate thing is that the area of fourth tree (3557), is lesser than the area of the unwanted blob below. Hence if i use:
newbw = bwareafilt(binimg, [3900 5000])
the fourth tree will be filtered out leaving only:
Capture3.PNG
If the area of the unwanted object is larger than the object i want to keep in the binary image, how do i handle this?

답변 (1개)

darova
darova 2019년 9월 27일
What about centroid?
I = imread('Capture.png');
I1 = rgb2gray(I);
L = bwlabel(I1);
pp = regionprops(L,'centroid');
xy = cat(1, pp.Centroid); % concatenation
[~,n] = max(xy(:,2)); % find bottom label
I1(L==n) = 0; % fill bottom
imshow(I1)
hold on
plot(xy(:,1),xy(:,2),'or')
hold off

Community Treasure Hunt

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

Start Hunting!

Translated by