车牌分割matlab开发程序
来源于人民邮电出版社Visual C++/MATLAB 图像处理与识别实用案例精选,具体原理自己看书吧I=imread('Car.jpg');
=size(I);
myI=double(I);
%%%%%%%%%%% RGB to HSI %%%%%%%%
tic % 测定算法执行的时间,开始计时
%%%%%%%%%%% 统计分析 %%%%%%%%%%%%%%%
%%%%%%%% Y 方向 %%%%%%%%%%
Blue_y=zeros(y,1);
for i=1:y
for j=1:x
if((myI(i,j,1)<=30)&&((myI(i,j,2)<=62)&&(myI(i,j,2)>=51))&&((myI(i,j,3)<=142)&&(myI(i,j,3)>=119)))
% 蓝色RGB的灰度范围
Blue_y(i,1)= Blue_y(i,1)+1; % 蓝色象素点统计
end
end
end
=max(Blue_y); % Y方向车牌区域确定
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 方向 %%%%%%%%%%
Blue_x=zeros(1,x); % 进一步确定X方向的车牌区域
for j=1:x
for i=PY1:PY2
if((myI(i,j,1)<=30)&&((myI(i,j,2)<=62)&&(myI(i,j,2)>=51))&&((myI(i,j,3)<=142)&&(myI(i,j,3)>=119)))
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-2; % 对车牌区域的修正
PX2=PX2+2;
Plate=I(PY1:PY2,PX1-2:PX2,:);
t=toc % 读取计时
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure,imshow(I);
figure,plot(Blue_y);grid
figure,plot(Blue_x);grid
figure,imshow(IY);
figure,imshow(Plate);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%文字识别子函数
function =Recognition(StrokeTop,StrokeLeft,StrokeRight,StrokeBottom,Comp)
% 采用四边的轮廓结构特征和笔划统计(仅针对 0 和 8)识别残缺数字
% Comp 是用于识别 0和8 的底部补充信息
StrT='T';
StrL='T';
StrR='T';
StrB='T';
RStr='T'; % 用于保存识别出的数字
=size(StrokeTop);
=size(StrokeLeft);
=size(StrokeRight);
%=size(StrokeBottom);
for Ti=2:XT
if (StrokeTop(Ti)=='C')
if ((XL==2)&&(XR==2))
if ((Comp>=3)||((StrokeBottom(2)~='C')&&(StrokeLeft(2)=='C')&&(StrokeRight(2)=='C')))
RStr='8';
else
RStr='0';
end
else if ((StrokeLeft(XL)=='L')&&(StrokeLeft(XL-1)=='P')&&(StrokeLeft(2)~='C'))
RStr='2';
else if ((StrokeLeft(2)=='C')&&(XL>=3)&&(StrokeLeft(3)=='P'))
RStr='9';
else if (XL>2)
for Li=2:XL
if (StrokeLeft(Li)=='P')
RStr='3';
end
end
else if (XL==2)
for Ri=2:XR-1
if (StrokeRight(Ri)=='P')
RStr='6';
end
end
end
end
end
end
end
else if (StrokeTop(Ti)=='V') % Top
if ((XR==2)&&(StrokeRight(2)=='C')) % 数字 3 右端只有一个结构
RStr='3';
else if ((XR==2)&&((StrokeLeft(2)=='P')||(StrokeLeft(3)=='P')||(StrokeLeft(XL)=='V')))
RStr='7';
else if (XR>2)
for Ri=2:XR
if (StrokeRight(Ri)=='P')
RStr='5';
end
end
end
end
end
else if ((StrokeTop(Ti)=='L')) % Top
if ((StrokeRight(XR)=='V')&&(XR<=2))
RStr='4';
else
for Ri=2:XR
if ((StrokeRight(Ri)=='L')||(StrokeRight(Ri)=='C'))
RStr='6';
end
end
end
end
end %对应于'V'
end % 对应于'C'
end % 对应于第一个 for 循环
Numeral=RStr; 来源研学论坛
Matlab实现
① 装入待处理图象并显示原始图象,如①图所示:
clear;
close all;
i=imread('原始图象');
figure,imshow(i);
......
Matlab程序:
clear;
close all;
i=imread('原始图象');
figure,imshow(i);
%装入待处理图象并显示原始图象
s=strel('disk',10);
bg=imopen(i,s);
figure,imshow(bg);
%对‘原始图象’进行开操作得到图象背景
bw=imsubtract(i,bg);
figure,imshow(bw);
%用原始图象与背景图象作减法
%figure,imhist(i);
%求图象直方图
level=0.5;
bw2=im2bw(bw,level);
figure,imshow(bw2);
%通过图象的直方图取得阈值,将图象二值化 好的,学习中! :victory: ding ha 个人看法:若能给齐Car.jpg此文件, 可能较容易学习!
页:
[1]