資源描述:
《車牌識別-MATLAB代碼》由會員上傳分享,免費在線閱讀,更多相關內(nèi)容在應用文檔-天天文庫。
1、clear;closeall;%Step1獲取圖像裝入待處理彩色圖像并顯示原始圖像Scolor=imread('C:UserslenovoDesktop程序chepail2.jpg');%將彩色圖像轉(zhuǎn)換為黑白并顯示Sgray=rgb2gray(Scolor);figure,imshow(Scolor),title('原始彩色圖像');figure,imshow(Sgray),title('原始灰度圖像');%bw3=medfilt2(Sgray,[55]);%figure,imshow(bw3);tit
2、le('圖像中值濾波');%bw4=imfilter(bw3,fspecial('laplacian'));%figure,imshow(bw4);title('圖像中值濾波');%Egray=imsubtract(bw3,bw4);%figure,imshow(Egray);%Step2圖像預處理對Sgray原始黑白圖像進行開操作得到圖像背景s=strel('disk',10);Bgray=imopen(Sgray,s);figure,imshow(Bgray);title('背景圖像');%用原始圖像與背景圖像
3、作減法,增強圖像Egray=imsubtract(Sgray,Bgray);figure,imshow(Egray);title('增強黑白圖像');%Step3取得最佳閾值,將圖像二值化%fmax1=double(max(max(Egray)));%fmin1=double(min(min(Egray)));%level=(fmax1-(fmax1-fmin1)/3)/255;%level=graythresh(Egray);%%bw3=filter2(fspecial('average',3),Egray);%
4、%Egray=medfilt2(Egray,[33]);%figure,imshow(Egray);title('圖像中值濾波');bw2=im2bw(Egray,level);figure,imshow(bw2);title('圖像二值化');%bw4=im2bw(bw3,level);%figure,imshow(bw4);title('圖像二值化');%Step4對得到二值圖像作開閉操作進行濾波grd=edge(bw2,'canny');figure,imshow(grd);title('圖像邊緣提取');%
5、bg1=imclose(grd,strel('rectangle',[5,19]));%figure,imshow(bg1);title('圖像閉運算[5,19]');bg2=bwareaopen(bg1,2000);figure,imshow(bg2);title('小對象');bg2=imclose(bg2,strel('rectangle',[20,50]));%bg3=imclose(bg2,strel('rectangle',[20,50]));bg2=imopen(bg2,strel('rectangl
6、e',[5,20]));figure,imshow(bg2);title('圖像開運算[5,19]');bg2=imopen(bg2,strel('rectangle',[19,1]));figure,imshow(bg2);title('圖像開運算[19,1]');%Step5對二值圖像進行區(qū)域提取,并計算區(qū)域特征參數(shù)。進行區(qū)域特征參數(shù)比較,提取車牌區(qū)域[L,num]=bwlabel(bg2,8);Feastats=regionprops(L,'basic');Area=[Feastats.Area];Bound
7、ingBox=[Feastats.BoundingBox];%[xywidthheight]RGB=label2rgb(L,'spring','k','shuffle');figure,imshow(RGB);title('圖像彩色標記');lx=0;%Getok=zeros(1,5);forl=1:numwidth=BoundingBox((l-1)*4+3);hight=BoundingBox((l-1)*4+4);if(width>250&&width<500&&hight>70&&hight<150)lx=
8、lx+1;Getok(lx)=l;endendfork=1:lxl=Getok(k);startcol=BoundingBox((l-1)*4+1);%開始列startrow=BoundingBox((l-1)*4+2);%開始行width=BoundingBox((l-1)*4+3);%車牌寬hight=BoundingBox((l-1)*4+4);%車牌