Can I make bwareafilt keep any ties for n-th place?
1 view (last 30 days)
Show older comments
I've been using bwareafilt, but keep getting warnings that there are ties for n-th place, and that the ties were not selected. Is there any way to make it keep any ties for n-th place?
0 Comments
Accepted Answer
Image Analyst
on 18 Oct 2017
Please post your binary image where this happens. Also state the criteria where you'd delete one. For example, if you take the two largest blobs and they are both exactly 10,000 pixels and it keeps them both, then do you just want to randomly select one for deletion? Or just delete the one on top (or left, right, bottom)?
3 Comments
Image Analyst
on 19 Oct 2017
Use bwareafilt() in a different way. See demo below:
mask = false(640, 480);
mask(50:100, 50:100) = true;
mask(150:200, 150:200) = true;
mask(350:370, 100:120) = true;
subplot(2, 2, 1);
imshow(mask);
title('Mask', 'FontSize', 30);
% Keep largest blob only. See if it keeps both since they are tied.
mask2 = bwareafilt(mask, 1);
subplot(2, 2, 2);
imshow(mask2);
title('Filtered Mask', 'FontSize', 30);
% It does not keep both!
% To keep both we need to measure the size and
% use bwareafilt() in a different way
props = regionprops(mask, 'Area');
allAreas = [props.Area]
maxArea = max(allAreas)
mask3 = bwareafilt(mask, [maxArea, inf]);
% Now keep anything maxArea or larger
subplot(2, 2, 3);
imshow(mask3);
title('Filtered Mask', 'FontSize', 30);
% This will keep both.
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!