Fitting some circles to the corner points of an image

4 次查看(过去 30 天)
Hi everyone,
I am working on the image of asphalt aggregates and I am going to extract some properties of them ( such as roundness). To compute this index, I need the circles which fitted to the curved part of the object(as can be seen in the image that I have uploaded). As you can see in the picture, I need the radius of the green circles. Do you know how can I extract them?
For finding the coordinates of boundary points from images, I used the following functions;
b=imread('aggregate.png');
BW = im2bw(b,0.36);
boundaries = bwboundaries(BW);
numberOfBoundaries = size(boundaries, 1);
hold on;
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k};
x = thisBoundary(:,2);
y= thisBoundary(:,1);
end
And then I tried to use function 'circfit' to fit a circle to the corner(or curved part) but I couldnt.

回答(1 个)

Amit Dhakite
Amit Dhakite 2023-6-8
Hi Narges,
To find out details about the circles from an image, you can consider the following code which detects circles in an image and returns their centers as well as radii using "imfindcircles()" functon.
% Read the image
rgb = imread("https://www.mathworks.com/matlabcentral/answers/uploaded_files/1201918/aggregate.png");
imshow(rgb);
% Extract their centers and radii using imfindcircles()
[centers,radii] = imfindcircles(rgb,[20 25],"ObjectPolarity","dark", "Sensitivity",0.955, ...
"Method","twostage")
centers = 13×2
126.8243 287.0383 230.9788 34.8596 39.4499 90.2341 194.4755 28.4751 35.2372 180.0830 118.9220 34.4879 168.5649 287.8998 155.1586 297.6892 99.9062 38.0896 220.7053 194.3157
radii = 13×1
25 24 25 24 24 24 24 22 25 22
fprintf("Number of circles detected: %d", length(centers));
Number of circles detected: 13
To know more about detecting circles in an image, kindly refer to the following links:
  1. Detecting circles: https://www.mathworks.com/help/images/detect-and-measure-circular-objects-in-an-image.html
  2. imfindcircles(): https://www.mathworks.com/help/images/ref/imfindcircles.html

Community Treasure Hunt

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

Start Hunting!

Translated by