Filtering binary image object based on area
3 次查看(过去 30 天)
显示 更早的评论
I have a binary image below:
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:
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:
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?
0 个评论
回答(1 个)
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!