how can I remove small objects from binary image?

I have a binary Image that is attached hear.my problem is small objects that are on the right side of image. how can I delete them such that the external border of breast(second border) is preserved and fill the breast ROI?thanks

답변 (1개)

Image Analyst
Image Analyst 2016년 10월 25일

1 개 추천

Well there are lots of ways. One is to try bwareafilt() and tell it a size range you want to extract. Another way is to try bwareaopen(). Another way might be to use regionprops and throw out blobs based on their x centroid location. Another way might be to scan down line by line, finding the first non-zero pixel, then moving over about 10 pixels and then erasing to the right of that. You might even combine some of them if one method does not get them all.

댓글 수: 4

nadia
nadia 2016년 10월 25일
dear Image Analyst thanks for your answer, but I do not know how to use regionprops answer. can you explain for me or insert any code? thanks in advance.
Try this:
labeledImage = bwlabel(binaryImage);
props = regionprops(labeledImage, 'Centroid', 'Area');
allCentroids = [props.Centroid];
xCentroids = allCentroids(1:2:end)
% Find centroids to the left of 500, or whatever.
keepers = xCentroids < 500;
indexes = find(keepers);
% Use ismember to get those out into a new image
binaryImage = ismember(labeledImage, indexes);
You could also use bwpropfilt().
Torkan
Torkan 2019년 10월 18일
Hi analyst,
Now, that we use the last line how can we create new image without those objects?
If youi wanted to remove them instead of keep them just set the labeled image to zero there and re-measure your properties:
% Use ismember to get those out into a new image
blobsToExclude = ismember(labeledImage, indexes); % These are blobs we don't want.
% Erase those blobs from our original binary image.
binaryImage(blobsToExclude) = false;
% Re-measure what's left.
labeledImage = bwlabel(binaryImage);
props = regionprops(labeledImage, 'Centroid', 'Area');

댓글을 달려면 로그인하십시오.

질문:

2016년 10월 25일

댓글:

2019년 10월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by