matlab车牌识别图像调整程序,matlab完整车牌识别程序,包括报告及图像
大俠,我下載了你程序,然后根據自己的想法修改了圖像的預處理部分代碼,為何運行到下面
sbw1=bw2(startrow:startrow+hight,startcol:startcol+width-1); %獲取車牌二值子圖
subcol1=Sgray(startrow:startrow+hight,startcol:startcol+width-1);%獲取車牌灰度子圖
這一步的時候系統提示:
??? Undefined function or variable "startrow".
Error in ==> dingweizijia at 51
sbw1=w(startrow:startrow+hight,startcol:startcol+width-1); %獲取車牌二值子圖
這是樓主的源代碼:
clear ;
close all;
%Step1 獲取圖像? ?裝入待處理彩色圖像并顯示原始圖像
Scolor = imread('H:\迅雷下載\車牌識別下載\車牌識別 研究版\新建文件夾\work\3.jpg');%imread函數讀取圖像文件
%將彩色圖像轉換為黑白并顯示
Sgray = rgb2gray(Scolor);%rgb2gray轉換成灰度圖
figure,imshow(Scolor),title('原始彩色圖像');%figure命令同時顯示兩幅圖像
figure,imshow(Sgray),title('原始黑白圖像');
%Step2 圖像預處理? ?對Sgray 原始黑白圖像進行開操作得到圖像背景
s=strel('disk',13);%strel函數
Bgray=imopen(Sgray,s);%打開sgray s圖像
figure,imshow(Bgray);title('背景圖像');%輸出背景圖像
%用原始圖像與背景圖像作減法,增強圖像
Egray=imsubtract(Sgray,Bgray);%兩幅圖相減
figure,imshow(Egray);title('增強黑白圖像');%輸出黑白圖像
%Step3 取得最佳閾值,將圖像二值化
fmax1=double(max(max(Egray)));%egray的最大值并輸出雙精度型
fmin1=double(min(min(Egray)));%egray的最小值并輸出雙精度型
level=(fmax1-(fmax1-fmin1)/3)/255;%獲得最佳閾值
bw22=im2bw(Egray,level);%轉換圖像為二進制圖像
bw2=double(bw22);
%Step4 對得到二值圖像作開閉操作進行濾波
figure,imshow(bw2);title('圖像二值化');%得到二值圖像
grd=edge(bw2,'canny')%用canny算子識別強度圖像中的邊界
figure,imshow(grd);title('圖像邊緣提取');%輸出圖像邊緣
bg1=imclose(grd,strel('rectangle',[5,19]));%取矩形框的閉運算
figure,imshow(bg1);title('圖像閉運算[5,19]');%輸出閉運算的圖像
bg3=imopen(bg1,strel('rectangle',[5,19]));%取矩形框的開運算
figure,imshow(bg3);title('圖像開運算[5,19]');%輸出開運算的圖像
bg2=imopen(bg3,strel('rectangle',[19,1]));%取矩形框的開運算
figure,imshow(bg2);title('圖像開運算[19,1]');%輸出開運算的圖像
%Step5 對二值圖像進行區域提取,并計算區域特征參數。進行區域特征參數比較,提取車牌區域
[L,num] = bwlabel(bg2,8);%標注二進制圖像中已連接的部分
Feastats = imfeature(L,'basic');%計算圖像區域的特征尺寸
Area=[Feastats.Area];%區域面積
BoundingBox=[Feastats.BoundingBox];%[x y width height]車牌的框架大小
RGB = label2rgb(L, 'spring', 'k', 'shuffle'); %標志圖像向RGB圖像轉換
figure,imshow(RGB);title('圖像彩色標記');%輸出框架的彩色圖像
lx=0;
for l=1:num
width=BoundingBox((l-1)*4+3);%框架寬度的計算
hight=BoundingBox((l-1)*4+4);%框架高度的計算
if (width>98 & width<160 & hight>25 & hight<50)%框架的寬度和高度的范圍
lx=lx+1;
Getok(lx)=l;
end
end
for k= 1:lx
l=Getok(k);
startcol=BoundingBox((l-1)*4+1)-2;%開始列
startrow=BoundingBox((l-1)*4+2)-2;%開始行
width=BoundingBox((l-1)*4+3)+8;%車牌寬
hight=BoundingBox((l-1)*4+4)+2;%車牌高
rato=width/hight;%計算車牌長寬比
if rato>2 & rato<4
break;
end
end
sbw1=bw2(startrow:startrow+hight,startcol:startcol+width-1); %獲取車牌二值子圖
subcol1=Sgray(startrow:startrow+hight,startcol:startcol+width-1);%獲取車牌灰度子圖
figure,subplot(2,1,1),imshow(subcol1);title('車牌灰度子圖');%輸出灰度圖像
subplot(2,1,2),imshow(sbw1);title('車牌二值子圖');%輸出車牌的二值圖
下面是我修改后的代碼:
i=imread('C:\Documents and Settings\Administrator\桌面\大眾1.bmp'); %輸入RGB圖像
j=rgb2gray(i);? ?? ?? ?? ?? ?? ?? ???%圖像灰度化
k=imadjust(j);? ?? ?? ?? ?? ?? ?? ???%灰度拉伸調整,增強亮度
I=im2bw(k);? ?? ?? ?? ?? ?? ?? ?? ???%二值化處理
m=medfilt2(I);? ?? ?? ?? ?? ?? ?? ???%中值濾波
w=double(m);? ?? ?? ?? ?? ?? ?? ?? ? %Unit8轉換成雙精度型,便于后面的圖像處理
g=edge(w,'sobel',0.4,'both');? ?? ???%邊緣檢測
[g,t]=edge(w,'sobel','both');? ?? ???%返回閾值
t
se90=strel('line',3,90);
se0=strel('line',3,0);
p=imdilate(g,[se90,se0]);? ?? ?? ?? ?%膨脹操作,填補邊緣的縫隙
n=imfill(p,'holes');? ?? ?? ?? ?? ???%填充操作,為使順利分割
t=imclearborder(n,4);? ?? ?? ?? ?? ? %清除與邊界連通的背景
c=strel('square',28);
f=imclose(t,c);? ?? ?? ?? ?? ?? ?? ? %形態學閉運算
e=imopen(f,c);? ?? ?? ?? ?? ?? ?? ???%形態學開運算
x=imclearborder(e,4);? ?? ?? ?? ?? ? %再次清除與邊界連通的背景
se=strel('square',1);
y=imerode(x,se);
y=imerode(y,se);? ?? ?? ?? ?? ?? ?? ?%平滑處理
[L,num] = bwlabel(y,8);? ?? ?? ?? ???%標注二進制圖像中已連接的部分
Feastats = imfeature(L,'basic');? ???%計算圖像區域的特征尺寸
Area=[Feastats.Area];? ?? ?? ?? ?? ? %區域面積
BoundingBox=[Feastats.BoundingBox];??%[x y width height]車牌的框架大小
RGB = label2rgb(L, 'spring', 'k', 'shuffle'); %標志圖像向RGB圖像轉換
subplot(2,2,1),imshow(k);? ?? ?? ?? ?%灰色圖像
subplot(2,2,2),imshow(x);? ?? ?? ?? ?%消除后的圖像
subplot(2,2,3),imshow(y);
subplot(2,2,4),imshow(RGB);title('圖像彩色標記');%輸出框架的彩色圖像
lx=0;
for l=1:num
width=BoundingBox((l-1)*4+3);%框架寬度的計算
hight=BoundingBox((l-1)*4+4);%框架高度的計算
if (width>98 & width<160 & hight>25 & hight<50)%框架的寬度和高度的范圍
lx=lx+1;
Getok(lx)=l;
end
end
for k= 1:lx
l=Getok(k);
startcol=BoundingBox((l-1)*4+1)-2;%開始列
startrow=BoundingBox((l-1)*4+2)-2;%開始行
width=BoundingBox((l-1)*4+3)+8;%車牌寬
hight=BoundingBox((l-1)*4+4)+2;%車牌高
rato=width/hight;%計算車牌長寬比
if rato>2 & rato<4
break;
end
end
sbw1=w(startrow:startrow+hight,startcol:startcol+width-1); %獲取車牌二值子圖
subcol1=k(startrow:startrow+hight,startcol:startcol+width-1);%獲取車牌灰度子圖
figure,subplot(2,1,1),imshow(subcol1);title('車牌灰度子圖');%輸出灰度圖像
subplot(2,1,2),imshow(sbw1);title('車牌二值子圖');%輸出車牌的二值圖
%Step6 計算車牌水平投影,并對水平投影進行峰谷分析
histcol1=sum(sbw1);? ?? ?%計算垂直投影
histrow=sum(sbw1');? ?? ?%計算水平投影
figure,subplot(2,1,1),bar(histcol1);title('垂直投影(含邊框)');%輸出垂直投影
subplot(2,1,2),bar(histrow);? ???title('水平投影(含邊框)');%輸出水平投影
figure,subplot(2,1,1),bar(histrow);? ???title('水平投影(含邊框)');%輸出水平投影
subplot(2,1,2),imshow(sbw1);title('車牌二值子圖');%輸出二值圖
能否解釋一下?
總結
以上是生活随笔為你收集整理的matlab车牌识别图像调整程序,matlab完整车牌识别程序,包括报告及图像的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 游长江有感
- 下一篇: AMEsim2019.2的安装和matl