的字符了。
问题求解: matlab代码:
主函数
function [d]=main(jpg) close all clc
I=imread('Car.jpg');%读入车牌图像Car.jpg I1=rgb2gray(I);
I2=edge(I1,'roberts',0.15,'both'); se=[1;1;1]; I3=imerode(I2,se);
se=strel('rectangle',[25,25]); I4=imclose(I3,se); I5=bwareaopen(I4,2000);
figure(1),imshow(I5);title('从对象中移除小对象');
[y,x,z]=size(I5);%图像以(y,x,z)表达灰度集,x,y为坐标,z为对应位置的值 myI=double(I5);%转化为双精度,便于确定范围
tic % 测定算法执行的时间,开始计时 Blue_y=zeros(y,1); for i=1:y for j=1:x
if(myI(i,j,1)==1) % 寻找y轴方向的白色区域
Blue_y(i,1)= Blue_y(i,1)+1; % 是蓝色区域的则进行计数 end end end
[temp MaxY]=max(Blue_y);%Y方向车牌区域确定 temp(最多点数):所有行中,最多的累积 PY1=MaxY;
while ((Blue_y(PY1,1)>=5)&&(PY1>1)) PY1=PY1-1; end %Y轴方向的上限 PY2=MaxY;
 while ((Blue_y(PY2,1)>=5)&&(PY2  %%%%%% X方向 %%%%%%%%%  Blue_x=zeros(1,x);%进一步确定x方向的车牌区域   for j=1:x       for i=PY1:PY2  %只需要扫描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  end     %确定x轴的右边界  PX2=x;   while ((Blue_x(1,PX2)<3)&&(PX2>PX1))         PX2=PX2-1;  end   %确定x轴的左边界  PX1=PX1-1;%对车牌区域的校正  PX2=PX2+1;  dw=I(PY1:PY2-8,PX1:PX2,:);   %确定图片的截取区域  t=toc;   % 读取程序的运行时间  a=imread('dw.jpg');  %读入已经截取好的图像 A=size(a);  if length(A)==3    b=rgb2gray(a); else    b=a; end  figure(8);subplot(3,2,1),imshow(b),title('1.车牌灰度图像') g_max=double(max(max(b))); g_min=double(min(min(b)));  T=round(g_max-(g_max-g_min)/3); % T 为二值化的阈值 [m,n]=size(b);  d=(double(b)>=T);  % d:二值图像 imwrite(d,'2.车牌二值图像.jpg');  figure(8);subplot(3,2,2),imshow(d),title('2.车牌二值图像') figure(8),subplot(3,2,3),imshow(d),title('3.均值滤波前')  % 滤波  h=fspecial('average',3);  %进行均值滤波 imwrite(d,'4.均值滤波后.jpg');  figure(8),subplot(3,2,4),imshow(d),title('4.均值滤波后')   % 某些图像进行操作 % 膨胀或腐蚀