edge robert matlab,哪位熟悉matlab的大神路过瞄一眼哈
cxfx(believe truth believe me)
UID240430
帖子100
精華積分1755
蛋蛋幣1755 枚
威望0
BT積分0
閱讀權限60
性別男
在線時間125 小時
注冊時間2013-3-27
??
鴕鳥蛋
主樓
大中
小發表于 2013-5-13 21:30?只看該作者
哪位熟悉matlab的大神路過瞄一眼哈
求大神指點迷津那!誰來幫著看一下這個程序那,這個程序感覺存在bug,意圖是通過blue像素點確定出想要的區域,問題在于這段程序好像跳過了色彩像素區程序段,怎么解決那???基于MATLAB的車牌號碼識別程序如下:
I=imread('car.jpg');
figure(1),imshow(I);title('原圖');
I1=rgb2gray(I);
figure(2),subplot(1,2,1),imshow(I1);title('灰度圖');
figure(2),subplot(1,2,2),imhist(I1);title('灰度圖直方圖');
I2=edge(I1,'robert',0.08,'both');
figure(3),imshow(I2);title('robert算子邊緣檢測')
se=[1;1;1];
I3=imerode(I2,se);
figure(4),imshow(I3);title('腐蝕后圖像');
se=strel('rectangle',[40,40]);
I4=imclose(I3,se);
figure(5),imshow(I4);title('平滑圖像的輪廓');
I5=bwareaopen(I4,2000);
figure(6),imshow(I5);title('從對象中移除小對象');
[y,x,z]=size(I5);
myI=double(I5);
%begin橫向掃描
tic
Blue_y=zeros(y,1);
for i=1:y
for j=1:x
if(myI(i,j,1)==1)
%如果myI(i,j,1)即myI圖像中坐標為(i,j)的點為藍色
%則Blue_y的相應行的元素white_y(i,1)值加1
Blue_y(i,1)= Blue_y(i,1)+1;%藍色像素點統計
end
end
end
[temp MaxY]=max(Blue_y);%temp為向量white_y的元素中的最大值,MaxY為該值的索引(
在向量中的位置)
PY1=MaxY;
while ((Blue_y(PY1,1)>=120)&&(PY1>1))
PY1=PY1-1;
end
PY2=MaxY;
while ((Blue_y(PY2,1)>=40)&&(PY2
PY2=PY2+1;
end
IY=I(PY1:Y2,:,;)
%IY為原始圖像I中截取的縱坐標在PY1:PY2之間的部分
%end橫向掃描
%begin縱向掃描
Blue_x=zeros(1,x);%進一步確定x方向的車牌區域
for j=1:x
for i=PY1:Y2
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
PX1=PX1+1;
end
PX2=x;
while ((Blue_x(1,PX2)<3)&&(PX2>pX1))
PX2=PX2-1;
end
%end縱向掃描
PX1=PX1-2;%對車牌區域的校正
PX2=PX2+2;
dw=I(pY1:pY2,:,;)
t=toc;
figure(7),subplot(1,2,1),imshow(IY),title('行方向合理區域');
figure(7),subplot(1,2,2),imshow(dw),title('定位剪切后的彩色車牌圖像')
imwrite(dw,'dw.jpg');
[filename,filepath]=uigetfile('dw.jpg','輸入一個定位裁剪后的車牌圖像');
jpg=strcat(filepath,filename);
a=imread('dw.jpg');
b=rgb2gray(a);
imwrite(b,'1.車牌灰度圖像.jpg');
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);
d=im2bw(round(filter2(h,d)));
imwrite(d,'4.均值濾波后.jpg');
figure(8),subplot(3,2,4),imshow(d),title('4.均值濾波后')
% 某些圖像進行操作
% 膨脹或腐蝕
% se=strel('square',3); % 使用一個3X3的正方形結果元素對象對創建的圖像膨脹
% 'line'/'diamond'/'ball'...
se=eye(2); % eye(n) returns the n-by-n identity matrix 單位矩陣
[m,n]=size(d);
if bwarea(d)/m/n>=0.365
d=imerode(d,se);
elseif bwarea(d)/m/n<=0.235
d=imdilate(d,se);
end
imwrite(d,'5.膨脹或腐蝕處理后.jpg');
figure(8),subplot(3,2,5),imshow(d),title('5.膨脹或腐蝕處理后')
% 尋找連續有文字的塊,若長度大于某閾值,則認為該塊有兩個字符組成,需要分割
d=qiege(d);
[m,n]=size(d);
figure,subplot(2,1,1),imshow(d),title(n)
k1=1;k2=1;s=sum(d);j=1;
while j~=n
while s(j)==0
j=j+1;
end
k1=j;
while s(j)~=0 && j<=n-1
j=j+1;
end
k2=j-1;
if k2-k1>=round(n/6.5)
[val,num]=min(sum(d(:,[k1+5:k2-5])));
d(:,k1+num+5)=0;??% 分割
end
end
% 再切割
d=qiege(d);
% 切割出 7 個字符
y1=10;y2=0.25;flag=0;word1=[];
while flag==0
[m,n]=size(d);
left=1;wide=0;
while sum(d(:,wide+1))~=0
wide=wide+1;
end
if wide
d(:,[1:wide])=0;
d=qiege(d);
else
temp=qiege(imcrop(d,[1 1 wide m]));
[m,n]=size(temp);
all=sum(sum(temp));
two_thirds=sum(sum(temp([round(m/3):2*round(m/3)],));
if two_thirds/all>y2
flag=1;word1=temp;? ?% WORD 1
end
d(:,[1:wide])=0;d=qiege(d);
end
end
% 分割出第二個字符
[word2,d]=getword(d);
% 分割出第三個字符
[word3,d]=getword(d);
% 分割出第四個字符
[word4,d]=getword(d);
% 分割出第五個字符
[word5,d]=getword(d);
% 分割出第六個字符
[word6,d]=getword(d);
% 分割出第七個字符
[word7,d]=getword(d);
figure(9),imshow(word1),title('1');
figure(10),imshow(word2),title('2');
figure(11),imshow(word3),title('3');
figure(12),imshow(word4),title('4');
figure(13),imshow(word5),title('5');
figure(14),imshow(word6),title('6');
figure(15),imshow(word7),title('7');
[m,n]=size(word1);
% 商用系統程序中歸一化大小為 40*20,此處演示
word1=imresize(word1,[40 20]);
word2=imresize(word2,[40 20]);
word3=imresize(word3,[40 20]);
word4=imresize(word4,[40 20]);
word5=imresize(word5,[40 20]);
word6=imresize(word6,[40 20]);
word7=imresize(word7,[40 20]);
figure(16),
subplot(3,7,8),imshow(word1),title('1');
subplot(3,7,9),imshow(word2),title('2');
subplot(3,7,10),imshow(word3),title('3');
subplot(3,7,11),imshow(word4),title('4');
subplot(3,7,12),imshow(word5),title('5');
subplot(3,7,13),imshow(word6),title('6');
subplot(3,7,14),imshow(word7),title('7');
imwrite(word1,'1.jpg');
imwrite(word2,'2.jpg');
imwrite(word3,'3.jpg');
imwrite(word4,'4.jpg');
imwrite(word5,'5.jpg');
imwrite(word6,'6.jpg');
imwrite(word7,'7.jpg');
liccode=char(['0':'9' 'A':'Z' '魯蘇豫陜']);??%建立自動識別字符代碼表
SubBw2=zeros(40,20);
l=1;
for I=1:7
ii=int2str(I);
t=imread([ii,'.jpg']);
SegBw2=imresize(t,[40 20],'nearest');
if l==1? ?? ?? ?? ?? ???%第一位漢字識別
kmin=37;
kmax=40;
elseif l==2? ?? ?? ?? ? %第二位 A~Z 字母識別
kmin=11;
kmax=36;
else l>=3? ?? ?? ?? ?? ?%第三位以后是字母或數字識別
kmin=1;
kmax=36;
end
for k2=kmin:kmax
fname=strcat('字符模板\',liccode(k2),'.jpg');
SamBw2 = imread(fname);
for??i=1:40
for j=1:20
SubBw2(i,j)=SegBw2(i,j)-SamBw2(i,j);
end
end
% 以上相當于兩幅圖相減得到第三幅圖
Dmax=0;
for k1=1:40
for l1=1:20
if??( SubBw2(k1,l1) > 0 | SubBw2(k1,l1) <0 )
Dmax=Dmax+1;
end
end
end
Error(k2)=Dmax;
end
Error1=Error(kmin:kmax);
MinError=min(Error1);
findc=find(Error1==MinError);
l=l+1;
end
figure(17),subplot(3,1,2),imshow(dw),title ('車牌號碼: 魯N·X8158');
%子程序:(getword子程序)
function [word,result]=getword(d)
word=[];flag=0;y1=8;y2=0.5;
while flag==0
[m,n]=size(d);
wide=0;
while sum(d(:,wide+1))~=0 && wide<=n-2
wide=wide+1;
end
temp=qiege(imcrop(d,[1 1 wide m]));
[m1,n1]=size(temp);
if widey2
d(:,[1:wide])=0;
if sum(sum(d))~=0
d=qiege(d);??% 切割出最小范圍
else word=[];flag=1;
end
else
word=qiege(imcrop(d,[1 1 wide m]));
d(:,[1:wide])=0;
if sum(sum(d))~=0;
d=qiege(d);flag=1;
else d=[];
end
end
end
result=d;
% (qiege子程序)
function e=qiege(d)
[m,n]=size(d);
top=1;bottom=m;left=1;right=n;? ?% init
while sum(d(top,==0 && top<=m
top=top+1;
end
while sum(d(bottom,==0 && bottom>1
bottom=bottom-1;
end
while sum(d(:,left))==0 && left
left=left+1;
end
while sum(d(:,right))==0 && right>=1
right=right-1;
end
dd=right-left;
hh=bottom-top;
e=imcrop(d,[left top dd hh]);
[本帖最后由 cxfx 于 2013-5-13 21:55 編輯]
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的edge robert matlab,哪位熟悉matlab的大神路过瞄一眼哈的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 肾脏杀手——“马兜铃酸”
- 下一篇: 什么是输卵管造影