Filtering binary image object based on area
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
darova
le 27 Sep 2019
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 commentaires
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!