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

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

Réponses (1)

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 commentaires

I know the image above have lines but I put as an example just, I have another images same way just I want to keep roundness shape and remove others ,like image which attached know so please just I want a code for detect roundness and keep it and remove the other objects , then calculate the area and centroid for the roundness object which I detected , can you please put the full code from the begging read image to the end . thank you so much
Mr Image Analyst, Could you give an opinion about how to solve this problem? https://la.mathworks.com/matlabcentral/answers/index/?s_tid=gn_mlc_an
I think you may open my mind about it
alaa, are your white blobs going to be closed/connected contours, or open ended curves/lines? You'd possibly have different algorithms for the two cases.
Dear image analyst , I think my question clear I put another example image , I have many segmented image each one have different object shape just I want in general a code for check each object in the image and keep the roundness one and remove others , then fined all measurements for roundness object like centroid ,area,convex , solidity and so on
about your question my rounded shape some times in the image appear not connected , but it seems rounded shape so I want to detect also cause already have rounded shape
waiting your code please ,and please let the code from reading the image until end thank you so much
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.
i don't now how to applied , can you help me by write the code from beginning please

Connectez-vous pour commenter.

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by