本文介绍了使用Hough变换椭圆检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Hough变换,我怎么可以检测并得到(X0,Y0)坐标和A和B在二维空间中的椭圆形?
的这是ellipse01.bmp:
I = imread('ellipse01.bmp');
[M N] =尺寸(Ⅰ);
C = 0;
对于i = 1:M
对于j = 1:N
如果我(I,J)== 1
C = C + 1;
P(C,1)= I;
P(C,2)= j的;
结束
结束
结束
边=转置(对);
Size_Ellipse =大小(边);
B = 1为:ceil(Size_Ellipse(1)/ 2);
度Acc =零(长度(B),1);
A1 = 0; A2 = 0; B1 = 0; B2 = 0;
Ellipse_Minor = []; Ellipse_Major = []; Ellipse_X0 = []; Ellipse_Y0 = [];
Global_Threshold = CEIL(Size_Ellipse(2)/ 6);%用于长轴比较
Local_Threshold = CEIL(Size_Ellipse(1)/ 25);%用于短轴比较
[Y,X] =找到(边);
极限= numel(Y);
脱粒= 150;
帕拉= [];
对于Count_01 = 1:(限-1)
对于Count_02 =(Count_01 + 1):限制
如果((Count_02>限制)||(Count_01>限制))
继续
结束
A1 = Y(Count_01); B1 = X(Count_01);
A2 = Y(Count_02); B2 = X(Count_02);
Dist_01 =(SQRT((A1-A2)^ 2 +(B1-B2)^ 2));
如果(Dist_01> Global_Threshold)
Center_X0 =(B1 + B2)/ 2; Center_Y0 =(A1 + A2)/ 2;
主要= Dist_01 / 2.0;α= ATAN((A2-A1)/(B2-B1));
如果(阿尔法== 0)
对于Count_03 = 1:极限
如果((Count_03〜= Count_01)||(Count_03〜= Count_02))
A3 = Y(Count_03); B3 = X(Count_03);
Dist_02 =(开方((A3 - Center_Y0)^ 2 +(B3 - Center_X0)^ 2));
如果(Dist_02> Local_Threshold)
Cos_Tau =((主要)^ 2 +(Dist_02)^ 2 - (A3-A2)^ 2 - (B3-B2)^ 2)/(2 *主要* Dist_02);
Sin_Tau = 1 - (Cos_Tau)^ 2;
Minor_Temp =((主要* Dist_02 * Sin_Tau)^ 2)/(主要^ 2 - ((Dist_02 * Cos_Tau)^ 2));
如果((Minor_Temp→1)及及(Minor_Temp< B(完)))
ACC(圆(Minor_Temp))= ACC(圆(Minor_Temp))+ 1;
结束
结束
结束
结束
结束
小=找到(ACC == MAX(ACC(:)));
如果(ACC(次要)GT; Thresh的)
Ellipse_Minor(完+ 1)=小(1); Ellipse_Major(完+ 1)=少校;
Ellipse_X0(完+ 1)= Center_X0; Ellipse_Y0(完+ 1)= Center_Y0;
对数= 1:numel(X)
Para_X =((X(计数)-Ellipse_X0(完))^ 2)/(Ellipse_Major(完)^ 2);
Para_Y =((Y(计数)-Ellipse_Y0(完))^ 2)/(Ellipse_Minor(完)^ 2);
如果(((Para_X + Para_Y)GT; = - 2)及及((Para_X + Para_Y)其中; = 2))
边(X(计数),Y(计数))= 0;
结束
结束
结束
ACC =零(大小(ACC));
结束
结束
结束
解决方案
如果你用圆圈粗糙的变换给出RHO = X * COS(THETA)+ Y * SIN(THETA)对于椭圆既然是
您可以转换方程 RHO = A * X * COS(THETA)+ B * Y * SIN(THETA)虽然我不知道你是否使用标准Hough变换,为椭圆状的转换,你可以操纵的第一个给定的函数。
using Hough Transform, how can I detect and get coordinates of (x0,y0) and "a" and "b" of an ellipse in 2D space?
This is ellipse01.bmp:
I = imread('ellipse01.bmp');
[m n] = size(I);
c=0;
for i=1:m
for j=1:n
if I(i,j)==1
c=c+1;
p(c,1)=i;
p(c,2)=j;
end
end
end
Edges=transpose(p);
Size_Ellipse = size(Edges);
B = 1:ceil(Size_Ellipse(1)/2);
Acc = zeros(length(B),1);
a1=0;a2=0;b1=0;b2=0;
Ellipse_Minor=[];Ellipse_Major=[];Ellipse_X0 = [];Ellipse_Y0 = [];
Global_Threshold = ceil(Size_Ellipse(2)/6);%Used for Major Axis Comparison
Local_Threshold = ceil(Size_Ellipse(1)/25);%Used for Minor Axis Comparison
[Y,X]=find(Edges);
Limit=numel(Y);
Thresh = 150;
Para=[];
for Count_01 =1:(Limit-1)
for Count_02 =(Count_01+1):Limit
if ((Count_02>Limit) || (Count_01>Limit))
continue
end
a1=Y(Count_01);b1=X(Count_01);
a2=Y(Count_02);b2=X(Count_02);
Dist_01 = (sqrt((a1-a2)^2+(b1-b2)^2));
if (Dist_01 >Global_Threshold)
Center_X0 = (b1+b2)/2;Center_Y0 = (a1+a2)/2;
Major = Dist_01/2.0;Alpha = atan((a2-a1)/(b2-b1));
if(Alpha == 0)
for Count_03 = 1:Limit
if( (Count_03 ~= Count_01) || (Count_03 ~= Count_02))
a3=Y(Count_03);b3=X(Count_03);
Dist_02 = (sqrt((a3 - Center_Y0)^2+(b3 - Center_X0)^2));
if(Dist_02 > Local_Threshold)
Cos_Tau = ((Major)^2 + (Dist_02)^2 - (a3-a2)^2 - (b3-b2)^2)/(2*Major*Dist_02);
Sin_Tau = 1 - (Cos_Tau)^2;
Minor_Temp = ((Major*Dist_02*Sin_Tau)^2)/(Major^2 - ((Dist_02*Cos_Tau)^2));
if((Minor_Temp>1) && (Minor_Temp<B(end)))
Acc(round(Minor_Temp)) = Acc(round(Minor_Temp))+1;
end
end
end
end
end
Minor = find(Acc == max(Acc(:)));
if(Acc(Minor)>Thresh)
Ellipse_Minor(end+1)=Minor(1);Ellipse_Major(end+1)=Major;
Ellipse_X0(end+1) = Center_X0;Ellipse_Y0(end+1) = Center_Y0;
for Count = 1:numel(X)
Para_X = ((X(Count)-Ellipse_X0(end))^2)/(Ellipse_Major(end)^2);
Para_Y = ((Y(Count)-Ellipse_Y0(end))^2)/(Ellipse_Minor(end)^2);
if (((Para_X + Para_Y)>=-2)&&((Para_X + Para_Y)<=2))
Edges(X(Count),Y(Count))=0;
end
end
end
Acc = zeros(size(Acc));
end
end
end
解决方案
If you use circle for rough transform is given as rho = x*cos(theta) + y*sin(theta)For ellipse since it is
You could transform the equation as rho = a*x*cos(theta) + b*y*sin(theta)Although I am not sure if you use standard Hough Transform, for ellipse-like transforms, you could manipulate the first given function.
这篇关于使用Hough变换椭圆检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!