how i can detect the roudness object in binary image and remove other objects from image using regionprops

1 次查看(过去 30 天)
I already segmented my image using LOG so I have a binary image. I want to keep round objects in it and remove others. After that I want to know the centroid and area for the round object.
Please I attached the image if you can help to write a code on it

回答(1 个)

Image Analyst
Image Analyst 2018-2-16
编辑:Image Analyst 2018-2-16
All your objects are lines, but one has a rounded shape because the ends are close together. What I'd do is to compute the areas and endpoints and see if the endpoints are farther away or closer than some ratio, like 0.2 or 0.5 or whatever. Something like (untested, off the top of my head):
keepers = [];
props = regionprops(binaryImage, 'area', 'PixelList');
for k = 1 : length(props)
thisArea = props(k).Area; % Get length of line.
x1 = props(k).PixelList(1,1); % Get endpoints.
y1 = props(k).PixelList(1,2);
x2 = props(k).PixelList(2,1);
y2 = props(k).PixelList(2,2);
separationDistance = sqrt((x2-x1)^2+(y2-y1)^2); % Compute distance.
if separationDistance < 0.5 * thisArea
% Ends are close together. Keep it.
keepers = [keepers, k];
end
end
% Get new binary image.
binaryImage = ismember(binaryImage, keepers);
Adjust the 0.5 to be smaller if you want the ends to be closer together.
Then call bwconvhull() to "fill it in" and call regionprops() again, this time asking for centroid.
binaryImage = bwconvhull(binaryImage, 'objects');
props = regionprops(binaryImage, 'Centroid', 'Area');
allAreas = [props.Area];
allCentroids = [props.Centroid];
xCentroids = allCentroids (1:2:end);
yCentroids = allCentroids (2:2:end);
  6 个评论
Image Analyst
Image Analyst 2018-2-17
So use regionprops and get the Euler number to determine if the contour is closed or not. For open curves, use the algorithm I already gave. For closed contours, fill them then use bwboundaries to get the perimeter. Then use regionprops to get the centroid. Compute the distances from the centroid to the individual perimeter pixels and get the standard deviation of those distances. It should be smaller for rounded shapes than stick-like shapes. Give it a try, it's only a few lines of code.

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by