[y,x,z]=size(I5);%返回I5各维的尺寸,存储在x,y,z中
myI=double(I5);%将I5转换成双精度
tic %tic表示计时的开始,toc表示计时的结束
Blue_y=zeros(y,1);%产生一个y*1的零阵
for i=1:y
for j=1:x
if(myI(i,j,1)==1)
%如果myI(i,j,1)即myI的图像中坐标为(i,j)的点值为1,即该点为车牌背景颜色蓝色
%则Blue_y(i,1)的值加1
Blue_y(i,1)= Blue_y(i,1)+1;%蓝色像素点统计
end
end
end
[temp MaxY]=max(Blue_y);%Y方向车牌区域确定
%temp为向量white_y的元素中的最大值,MaxY为该值的索引
PY1=MaxY;
while ((Blue_y(PY1,1)>=5)&&(PY1>1))
PY1=PY1-1;
end
PY2=MaxY;
while ((Blue_y(PY2,1)>=5)&&(PY2<y))
PY2=PY2+1;
end
IY=I(PY1:PY2,:,:);
%x方向车牌区域确定
%%%%%% X方向 %%%%%%%%%
Blue_x=zeros(1,x);%进一步确定x方向的车牌区域
for j=1:x
for i=PY1:PY2
if(myI(i,j,1)==1)
Blue_x(1,j)= Blue_x(1,j)+1;
end
end
end
PX1=1;
while ((Blue_x(1,PX1)<3)&&(PX1<x))
PX1=PX1+1;
end
PX2=x;
while ((Blue_x(1,PX2)<3)&&(PX2>PX1))
PX2=PX2-1;
end
PX1=PX1-1;%对车牌区域的校正
PX2=PX2+1;
dw=I(PY1:PY2-8,PX1:PX2,:);
t=toc;
figure(7),subplot(1,2,1),imshow(IY),title('行方向合理区域');%行方向车牌区域确定
figure(7),subplot(1,2,2),imshow(dw),title('定位裁剪后的车牌彩色图像');的车牌区域如下所示: