Reputation: 37313
I a new to MATLAB and i am trying to apply circle fitting technique to the following image.
Image
Expected Output
I used the following code with no luck:
[centers, radii] = imfindcircles(W,[30 65],'ObjectPolarity','bright');
figure,imshow(W);% title('Sobel gradient');
viscircles(centers,radii,'Color','b');
Note that the circle size can vary between picture
Any suggestions.
Upvotes: 1
Views: 622
Reputation: 2462
So close! You just have to adjust the sensitivity a bit. It ranges from 0 to 1, the higher the more circles are found. By default it is 0.85. Also had to adjust the radius a bit:
imshow(W) % assuming W is logical
[centers,radii] = imfindcircles(W,[40 60],'ObjectPolarity','bright','Sensitivity',0.925)
viscircles(centers, radii,'EdgeColor','b');
I don't think it's possible to find the lower circle without also getting some false positives first - ultimately it's not very round.
Upvotes: 4
Reputation: 23675
I tried to play a little bit with this image despite not being a good digital images analyst. I found the following approach much more flexible:
img = imread('1GBtO.png');
img = im2bw(img);
rp = regionprops('table',img,'Centroid','Eccentricity','EquivDiameter','MajorAxisLength','MinorAxisLength');
rp.Radii = mean([rp.MajorAxisLength rp.MinorAxisLength],2) / 2;
rp([rp.Eccentricity] > 0.75,:) = [];
rp(rp.EquivDiameter < 10 | rp.EquivDiameter > 30,:) = [];
imshow(img);
hold on;
viscircles(rp.Centroid,rp.Radii);
hold off;
The output is far from being the desired one, but I feel it's an improvement over your first trial:
But I think that you can obtain the desired result by finding the right algorithm to adjust the radii and by tweaking the criterions to exclude unwanted regions.
Upvotes: 1