Filtering binary image object based on area
3 ビュー (過去 30 日間)
古いコメントを表示
I have a binary image below:
![Capture.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/240028/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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/240029/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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/240030/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?
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!