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.
alaa shamasneh
alaa shamasneh 2018년 2월 17일
i don't now how to applied , can you help me by write the code from beginning please

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by