Issue with finding circle and it's center in the image

2 views (last 30 days)
Hello! I am having an issue with finding the circle and it's center in the image.
Here is the image that I want to track the circle. The circle that I want to get is the bright one (bigest one).
I used the d=drawline to find the range of the radii of the circle and it was [400 600].
However even if I am using the code as following, the circle isn't being presented.
(I already had installed the tool box to use imfindcircles function)
<MATLAB code>
%loading and showing the image
load("imageDataArray.mat");
circ=imageDataArray(:,:,20);
imgshow(circ);
%finding the circle in the image
[centers,radii]=imfindcircles(circ,[400 600], "ObjectPolarity","bright","Sensitivity",0.95,"Method","twostage");
h=viscircles(centers,radii,"Color","g");
I would like to know the reason why it's not working. Since I am using the twostage method and the contrast of the circle edge is pretty high, I think it should track the circle automatically.
Thank you so much!!

Answers (1)

Matt J
Matt J on 20 Mar 2024
Edited: Matt J on 27 Mar 2024
Your posted code cannot be run by us and tested because input data and your homemade imgshow() function are not provided. However, below is an alternative which uses circularFit() from this FEX download,
If nothing else, you can compare the radius and center calculated this way with the result you get from imfindcircles(). You can also use it to validate/invalidate the [400,600] radius range you have used.
load Image
A=bwconvhull(imbinarize(Image));
E=bwmorph(A,'remove');
E(end,:)=0;
[y,x]=find(E);
keep=':';
for i=1:5 %Iterate the fit several times to remove outliers
xy=[x(keep), y(keep)]; %discard outliers
cfit = circularFit(xy'); %Perform the fit
keep=abs(vecnorm([x,y]-cfit.center,2,2)-cfit.radius)<2; %revise outliers
end
cfit
cfit =
circularFit with properties: center: [254.0551 384.4935] radius: 221.9686
imshow(Image); hold on
plot(cfit); hold off

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!