資源描述:
《霍夫變換檢測(cè)圓和直線.doc》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、霍夫變換檢測(cè)任意形狀一、實(shí)驗(yàn)?zāi)康?.掌握MATLAB軟件的使用,以及其設(shè)計(jì)流程;2.掌握霍夫變換的實(shí)現(xiàn)方法;3.用MATLAB語(yǔ)言設(shè)計(jì)基于霍夫變換的任意圖形的識(shí)別。二、實(shí)驗(yàn)儀器或設(shè)備裝MATLAB軟件的微機(jī)一臺(tái)三、總體設(shè)計(jì)原理及流程圖1、程序設(shè)計(jì)的原理霍夫變換的基本思想就是把圖像平面上的點(diǎn)對(duì)應(yīng)到參數(shù)平面上的曲線,最后通過(guò)統(tǒng)計(jì)特性來(lái)解決問(wèn)題。具有良好的抗噪聲性能和對(duì)部分遮蓋的不敏感等特性。2、程序流程圖程序開始打開圖形基于霍夫曼變換的簡(jiǎn)單圖形識(shí)別霍夫變換檢測(cè)直線霍夫變換檢測(cè)圓識(shí)別得到的圖像保存圖像程序結(jié)束一、主要程序代碼1、霍夫變換
2、檢測(cè)圓程序clearall;closeall;clc;%[cr,st]=circle_product;%st(1)->x,st(2)->y,st(3)->rcr=imread('sample.bmp');%circle1.bmpfigure;imshow(cr);[row,range]=size(cr);p=row*range;a=0;Y=zeros(1,p);Q=zeros(1,p);fork1=1:1:rowfork2=1:1:rangeifcr(k1,k2)==0a=a+1;XXX=k2-1;YYY=row+1-k1;Y(a
3、)=YYY;Q(a)=XXX;endendendfork3=1:1:pifY(k3)==0&Q(k3)==0break;endend%z=ones(1,5);%a=1:1:300;b=1:1:300;%z1=sqrt((a-Q(1)).^2+(b-Y(1)).^2);%z2=sqrt((a-Q(2)).^2+(b-Y(2)).^2);%z3=sqrt((a-Q(3)).^2+(b-Y(3)).^2);%z4=sqrt((a-Q(4)).^2+(b-Y(4)).^2);%z5=sqrt((a-Q(5)).^2+(b-Y(5)).^2
4、);%%z1=sqrt((a-Q(1))*(a-Q(1))+(b-Y(1))*(b-Y(1)));%%Z1=(a-Q(1)).^2+(b-Y(1)).^2;r0=(abs(z1-z2)<=0.1&abs(z1<=z3)<=0.1&abs(z1<=z4)<=0.1&abs(z1<=z5)<=0.1&abs(z2<=z3)<=0.1&abs(z2<=z4)<=0.1&abs(z2<=z5)<=0.1);%r=r0.*z1;%aa=r0.*a;%bb=r0.*b;%rrr=round(r(r0~=0))%aaa=aa(r0~=0)%bb
5、b=bb(r0~=0)k7=floor(k3/6);k5=2;a=1:1:300;b=1:1:300;rrr=zeros(1,p);aaa=zeros(1,p);bb=zeros(1,p);k6=0;as=0;k11=1;fork5=1:1:k7%k6=0;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%z1=sqrt((a-Q(k5)).^2+(b-Y(k5)).^2);z2=sqrt((a-Q(k5+1)).
6、^2+(b-Y(k5+1)).^2);z3=sqrt((a-Q(k5+2)).^2+(b-Y(k5+2)).^2);z4=sqrt((a-Q(k5+3)).^2+(b-Y(k5+3)).^2);z5=sqrt((a-Q(k5+4)).^2+(b-Y(k5+4)).^2);z6=sqrt((a-Q(k5+5)).^2+(b-Y(k5+5)).^2);r0=(abs(z1-z2)<=.1&abs(z1<=z3)<=.1&abs(z1<=z4)<=.1&abs(z1<=z5)<=.1&abs(z1<=z6)<=.1&abs(z2<=z3
7、)<=1&abs(z2<=z4)<=.1&abs(z2<=z5)<=.1&abs(z2<=z6)<=.1);rr=r0.*z1;aa=r0.*a;bb=r0.*b;[m,n]=size(rr);ifrr==zeros(1,n);as=as+1;continue;end[pz1,pz]=size(rr(r0~=0));rrr=round(rr(r0~=0))aaa=aa(r0~=0)bbb=bb(r0~=0)pz2=pz+k11-1;k9=1;fork8=k11:pz2RR(k8)=rrr(k9);XX(k8)=aaa(k9);YY
8、(k8)=bbb(k9);k9=k9+1;endk11=k8+1;%ifrr==zeros(1,n);%as=as+1;continue;%endend%ifaa==zeros(1,300)%as=1%endrangex=1:1:range;row