Finding a circle in an image

2 次查看(过去 30 天)
Hello
I am trying to find a circle in the attached image
Can someone help me, please?

采纳的回答

KSSV
KSSV 2018-5-24
How about this approach?
I = imread('image.png') ;
% crop the image to remove white borders around
I = imcrop(I) ;
I1 = rgb2gray(I) ;
[y,x] = find(I1) ;
%%get circle data
C = size(I1)./2 ; % center of circle
d = pdist2(C,[x y]) ;
nbins = 10 ;
[N,edges,bin] = histcounts(d,nbins) ;
figure(1)
imshow(I)
hold on
for i = 1:nbins
plot((x(bin==i)),y(bin==i),'.','color',rand(1,3)) ;
end
%
%%Circle's radii and center
Circ = cell(nbins,1) ;
for i = 1:nbins
[xc1,yc1,R] = circfit(x(bin==i),y(bin==i)) ;
Circ{i} = [xc1 yc1 R] ;
end
figure(2)
imshow(I)
hold on
th = linspace(0,2*pi) ;
for i = 1:nbins
xc = Circ{i}(1)+Circ{i}(3)*cos(th) ;
yc = Circ{i}(2)+Circ{i}(3)*sin(th) ;
plot(xc,yc,'color',rand(1,3),'linewidth',3) ;
end
Circ is cell, which centers and Radii of circles. You can download the function circfit from this link: http://matlab.wikia.com/wiki/FAQ#How_can_I_fit_a_circle_to_a_set_of_XY_data.3F

更多回答(1 个)

Image Analyst
Image Analyst 2018-5-24
Another approach is to use dbscan https://en.wikipedia.org/wiki/DBSCAN to find the dividing line and then use the faq http://matlab.wikia.com/wiki/FAQ#How_can_I_fit_a_circle_to_a_set_of_XY_data.3F to fit the dividing line to a circle.
  1 个评论
Rishabh Sharma
Rishabh Sharma 2018-5-24
This a great approach and probably would give me more accurate fit. Thanks a bunch! I admire your work a lot.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by