How can we filter the binary objects from image based on custom properties?

2 次查看(过去 30 天)
Let say I have a binary image with many rings of different thickness. Now if I want to filter out the image based on the thickness of the ring? How can I do that? I know we can filter out the image by area, perimeter etc using bwpropfilt.

采纳的回答

Image Analyst
Image Analyst 2019-1-12
You forgot to attach your image. Usually when people ask for image processing advice, they attach an image.
I would compute the Euclidean Distance Transform for the binary image with bwdist().
edtImage = bwdist(binaryImage);
Then ask regionprops for the pixel values of the EDT image.
labeledImage = bwlabel(binaryImage);
props = regionprops(labeledImage, edtImage, 'PixelValues');
If the max pixel value for that ring is acceptable, store that index.
numRings = length(props)
keepers = false(1, numRings)
for k = 1 : numRings
if max(props(k).PixelValues) > someValue
% This ring is thick enough. So keep it.
keepers(k) = true;
end
end
Then use ismember(mask, indexes) to extract just the rings that meet your criteria.
filteredBinaryImage = ismember(labeledImage, find(keepers));
The code is just off the top of my head - untested, so you may have to adapt it some. If you want the average thickness of the ring, then you'll have to call bwmorph() to skeletonize it and then multiply the skeleton image by the EDT image to get the thickness just along the centerlines. Then get the mean of all those pixels.
If you need more help, post your image and ring thickness criteria for keeping and excluding rings.

更多回答(1 个)

Deependra Mishra
Deependra Mishra 2019-1-14
I have attached a test image here. In the above solution we are filtering by pixel values and pixel values is just the no. of pixels in the ring. It does not necessarily mean the thickness of the ring. My thought was to calculate the thickness of the ring and then associated that thickness with the ring object and then filter it.
Ring could be of irregular shaped, so I believe calculting the average thickness would be a better idea. Please let me know if you have any other better ideas.
Thank you in advance.

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by