how i can detect the roudness object in binary image and remove other objects from image using regionprops
Afficher commentaires plus anciens
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)
Image Analyst
le 16 Fév 2018
Modifié(e) : Image Analyst
le 16 Fév 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 commentaires
alaa shamasneh
le 16 Fév 2018
Philippe Corner
le 16 Fév 2018
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
Image Analyst
le 16 Fév 2018
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.
alaa shamasneh
le 17 Fév 2018
Image Analyst
le 17 Fév 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.
alaa shamasneh
le 17 Fév 2018
Catégories
En savoir plus sur Image Processing Toolbox dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!