-
[, pathname] = uigetfile({'*.jpg',
'JPEG
文件
(*.jpg)';'*.bmp','BMP
文件
(*.
bmp)';});
if( == 0), return, end
global
%
声明全局变量
= [pathname ];
I=imread();
imshow(I);
%
显示图像
I
I1=rgb2gray(I);%RGB
< br>图转化为灰度图
figure,imshow(I1);
w1=medfilt2(I1);
figure,imshow(w1);
s1=histeq(w1,256);
figure,imshow(s1);
t1=imadjust(s1);
figure,imshow(t1);
I2=edge(t1,'robert',0.15,'both');
%
用
ROB
ERT
算子提取图像边缘
figure,imshow(I2);
se=[1;1;1];
I3=imerode(I2,se); %
弱化二进制图像<
/p>
I2
的边缘
f
igure,imshow(I3);%
为定位车牌,将白色区域膨胀,腐蚀去无关的小
物件,包括车牌字符
(
下
面两句
)
se=strel('rectangle',[25,20]);
%
用来腐蚀的形状为矩形,面积
20*25
I4=imclose(I3,se);
figure,imshow(I4);
I5=bwareaopen(I4,2000);
%
去除图像中面积过小的,可以肯定不是车牌的区域。
figure,imshow(I5);
[y,x,z]=size(I5);
%z=1
。
y
,
x
分别为
I5
图像的高和宽
myI=double(I5)
%myI=I5;
tic
%begin
横向扫描
white_y=zeros(y,1); %white_
y
为
y
行
1<
/p>
列的零矩阵
for i=1:y
for j=1:x
if(myI(i,j,1)==1)
p>
%
如果
myI(i,j,1)
即
myI
图像中坐标为
(i
,j)
的点为白色
%
则
whi
te_y
的相应行的元素
white_y(i,1)
值加
1
white_y(i,1)=
white_y(i,1)+1;
end
end
end
[temp
MaxY]=max(white_y);
%temp
为向量
white_y
的元素中的最大值,<
/p>
MaxY
为该值的索
引(在向量中的位置
)
PY1=MaxY;
while
((white_y(PY1,1)>=80)&&(PY1>1))
PY1=PY1-1;
end
PY2=MaxY;
while
((white_y(PY2,1)>=80)&&(PY2
PY2=PY2+1;
end
IY=I(PY1:PY2,:,:); %IY
为原始图像<
/p>
I
中截取的纵坐标在
PY1
:
PY2
之间的部分
%end
横向扫描
%begin
纵向扫描
white_x=zeros(1,x);
for j=1:x
for i=PY1:PY2
if(myI(i,j,1)==1)
white_x(1,j)= white_x(1,j)+1;
end
end
end
PX1=1;
while ((white_x(1,PX1)<3)&&(PX1
PX1=PX1+1;
end
PX2=x;
while ((white_x(1,PX2)<3)&&(PX2>PX1))
PX2=PX2-1;
end
%end
纵向扫描
PX1=PX1-2;
PX2=PX2+2;
Plate=I(PY1:PY2,:);
t=toc
figure,plot(white_y);grid
figure,plot(white_x);grid
figure,imshow(IY);
figure,imshow(Plate);
% if
isrgd(Plate);
Plate3=rgb2gray(Plate);
%else
%
Plate2=Plate;
%end
-
-
-
-
-
-
-
-
-
上一篇:《软件测试基础》期中考试A卷
下一篇:宏景hr数据字典