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

1 view (last 30 days)
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

Answers (1)

Image Analyst
Image Analyst on 16 Feb 2018
Edited: Image Analyst on 16 Feb 2018
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 Comments
Image Analyst
Image Analyst on 17 Feb 2018
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!