【正文】
I4=imclose(I3,se)。%圖像聚類、填充圖像 subplot(3,2,5),imshow(I4),title(39。填充后圖像 39。)。 I5=bwareaopen(I4,2020)。%去除聚團灰度值小于 2020的部分 subplot(3,2,6),imshow(I5),title(39。形態(tài)濾波后圖像 39。)。 [y,x,z]=size(I5)。 I6=double(I5)。 Y1=zeros(y,1)。 for i=1:y for j=1:x if(I6(i,j,1)==1) Y1(i,1)= Y1(i,1)+1。 end end end [temp MaxY]=max(Y1)。 figure()。 subplot(3,2,1),plot(0:y1,Y1),title(39。行方向像素點灰度值累計和 39。),xlabel(39。行值 39。),ylabel(39。像素 39。)。 %%%%%%%求的車牌的行起始位置和終止位置 %%%%%%%%% PY1=MaxY。 while ((Y1(PY1,1)=50)amp。amp。(PY11)) PY1=PY11。 end PY2=MaxY。 while ((Y1(PY2,1)=50)amp。amp。(PY2y)) PY2=PY2+1。 end IY=I(PY1:PY2,:,:)。 X1=zeros(1,x)。 for j=1:x for i=PY1:PY2 if(I6(i,j,1)==1) X1(1,j)= X1(1,j)+1。 end end end subplot(3,2,2),plot(0:x1,X1),title(39。列方向像素點灰度值累計和 39。),xlabel(39。列值 39。),ylabel(39。像數(shù) 39。)。 %%%%%%%求的車牌的列起始位置和終止位置 %%%%%%%%% PX1=1。 while ((X1(1,PX1)3)amp。amp。(PX1x)) PX1=PX1+1。 end PX2=x。 while ((X1(1,PX2)3)amp。amp。(PX2PX1)) PX2=PX21。 end PX1=PX11。 PX2=PX2+1。 %分割出車牌圖像 % dw=I(PY1:PY2,PX1:PX2,:)。 subplot(3,2,3),imshow(dw),title(39。定位剪切后的彩色車牌圖像 39。) 車牌字符分割 確定車牌位置后下一步的任務就是進行字符切分分離出車牌號碼的全部字符圖像 。 if isrgb(I) I1 = rgb2gray(I)。 %將 RGB圖像轉(zhuǎn)化為灰度圖像 else I1=I; end g_max=double(max(max(I1)))。 g_min=double(min(min(I1)))。 T=round(g_max(g_maxg_min)/3)。 % T 為二值化的閾值 [m,n]=size(I1)。% d:二值圖像 %h=graythresh(I1)。 I1=i