1 简介
研究了一种基于最小二乘的不完整椭圆拟合算法.基于几何距离的拟合算法可达到较高的拟合精度,但迭代过程敏感于初始条件;由于不完整的椭圆样本点及噪声的存在,简单线性拟合方法可能使拟合结果退化为开放的双曲线,引起拟合失败,基于椭圆约束的代数距离拟合方法可保证拟合结果一定是椭圆,从而为迭代提供适当的初值;利用多个待估计椭圆参数之间的相互约束,即使非常短的椭圆弧也可得到稳定的拟合结果.仿真结果与实际图像应用验证了算法的有效性.
2 部分代码
clc; clear all; im=imread('1.jpg'); im0=rgb2gray(im);%变彩色为黑白 im1=medfilt2(im0,[3 3]);%中值滤波函数 BW = edge(im1,'sobel'); %边缘检测,边缘为1,其余为0 [imx,imy]=size(BW);%获取矩阵行数和列数 L = bwlabel(BW,8);% Calculating connected components mx=max(max(L)) % There will be mx connected components.Here U can give a value between 1 and mx for L or in a loop you can extract all connected components % If you are using the attached car image, by giving 1,2,3 to L you can extract the number plate completely. [r,c] = find(L==3); rc = [r c]; [sx sy]=size(rc); n1=ones(imx,imy);%zeros for i=1:sx x1=rc(i,1); y1=rc(i,2); n1(x1,y1)=0; end % Storing the extracted image in an array figure,imshow(n1); title('边缘提取'); [S]=ellipsefit(c,r) a=S.Phi; jdg(S.Xc,S.Yc,S.A,S.B,a,n1)%plot ellipse
3 仿真结果
4 参考文献
[1]邹益民, & 汪渤. (2006). 一种基于最小二乘的不完整椭圆拟合算法. 仪器仪表学报, 27(007), 808-812.