Issue with finding circle and it's center in the image
2 次查看(过去 30 天)
显示 更早的评论
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!!
0 个评论
回答(1 个)
Matt J
2024-3-20
编辑:Matt J
2024-3-27
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
imshow(Image); hold on
plot(cfit); hold off
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!