如何将圆的估计半径转换为其实际范围?

时间:2019-01-10 20:52:29

标签: matlab image-processing hough-transform

我生成一个1到2之间的随机数作为我的圆的半径。然后画出我的圆并将其另存为png。同样,在圆的内部和外部都会生成多个数据点,以使其嘈杂。 然后,我将使用霍夫变换来估计圆的半径,但是它返回的数字大于100。尽管它们是相同的圆(我作了画以确保)。

我尝试使用polyfit函数映射这两个数字,但是在某些示例中,估计的半径似乎小于实际的半径。映射后,它返回相同的数字。例如,随机半径为1.2,霍夫(Hough)估计为110,但是似乎应该接近1(因为我绘制了它,很明显它较小)。另外,对于霍夫变换,我正在使用此代码https://www.mathworks.com/matlabcentral/fileexchange/35223-circle-detection-using-hough-transforms 我尝试了预定义的Matlab函数(imfindcircles),但对于我的所有圈子,它都返回null。

r1 = 1 + abs((1)*randn(1,1));  %radius of inner circle
r1 = abs(r1);
r2 = (1.2)*r1;   %radius of outercircle
k  =  500;      %number of random numbers 

% circle coordinate points 
t  = 0:2*pi/59:2*pi;
xv = cos(t)';
yv = sin(t)';

%%%%%%%%random points

xq = 2*randn(k,1)-1;
yq = 2*randn(k,1)-1;     %distribution 1
xq1 = 2*(rand(k,1))-1;   %distribution 2
yq1 = 2*(rand(k,1))-1;
in = inpolygon(xq1,yq1,r1*xv,r1*yv);    %number of points inside the geometry 
in1= inpolygon(xq,yq,r2*xv,r2*yv);      %points inside outer circle
in2 = xor(in,in1);                      %points between circle
in3= inpolygon(xq1,yq1,r2*xv,r2*yv);    %points inside outer circle
fig = figure(22);hold on;


% Random points
 plot(xq(in2),yq(in2),'bo','MarkerFaceColor','r','MarkerSize',5,'Marker','o','MarkerEdgeColor','none');
axis equal;
    plot(xq1(~in2),yq1(~in2),'bo','MarkerFaceColor','r','MarkerSize',5,'Marker','o','MarkerEdgeColor','none');
 axis equal;

img= getframe(fig);
figure;
 imshow(img.cdata)
 hold on;
   [r,c,rad] = circlefinder(img.cdata);
   [m I] = max(rad);
       %ploting the bigest estimated circle
    angle = 2*pi*randn(k,1);
    haffpointX = rad(I).*cos(angle)+ c(I);
    haffpointY = rad(I).*sin(angle)+ r(I);

   scatter(haffpointX,haffpointY,'g');
   axis equal

我希望对于带有嘈杂数据的不同随机圆,霍夫变换估计其圆的范围在1到2之间,因此我可以使用其结果。

提前谢谢

0 个答案:

没有答案