算法思想:
算法通过最小化约束条件4ac-b^2 = 1,最小化距离误差。利用最小二乘法进行求解,首先引入拉格朗日乘子算法获得等式组,然后求解等式组得到最优的拟合椭圆。
算法的优点:
a、椭圆的特异性,在任何噪声或者遮挡的情况下都会给出一个有用的结果;
b、不变性,对数据的Euclidean变换具有不变性,即数据进行一系列的Euclidean变换也不会导致拟合结果的不同;
c、对噪声具有很高的鲁棒性;
d、计算高效性。
算法原理:
代码实现(Matlab):
1 %2 function a =fitellipse(X,Y)3
4 % FITELLIPSE Least-squares fit of ellipse to2D points.5 % A = FITELLIPSE(X,Y) returns the parameters of the best-fit6 % ellipse to2D points (X,Y).7 % The returned vector A contains the center, radii, andorientation8 % of the ellipse, stored as(Cx, Cy, Rx, Ry, theta_radians)9 %10 % Authors: Andrew Fitzgibbon, Maurizio Pilu, Bob Fisher11 % Reference: "Direct Least Squares Fitting of Ellipses", IEEE T-PAMI, 1999
12 %13 % @Article{Fitzgibbon99,14 % author = "Fitzgibbon, A.~W.and Pilu, M. and Fisher, R.~B.",15 % title = "Direct least-squares fitting of ellipses",16 % journal = pami,17 % year = 1999,18 % volume = 21,19 % number = 5,20 % month = may,21 % pages = "476--480"22 %}
23 %24 % This is a more bulletproof version than that inthe paper, incorporating25 % scaling to