该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
%Step1 获取图像 装入待处理彩色图像并显示原始图像
Scolor = imread('car1.jpg');
%将彩色图像转换为黑白并显示
Sgray = rgb2gray(Scolor);
figure,imshow(Scolor),title('原始彩色图像');
figure,imshow(Sgray),title('原始黑白图像'); %Step2 图像预处理 对Sgray 原始黑白图像进行开操作得到图像背景
s=strel('disk',10);
Bgray=imopen(Sgray,s);
figure,imshow(Bgray);title('背景图像');
%用原始图像与背景图像作减法,增强图像
Egray=imsubtract(Sgray,Bgray);
figure,imshow(Egray);title('增强黑白图像'); %Step3 取得最佳阈值,将图像二值化
[m,n]=size(Scolor);
fmax1=double(max(max(Egray)));
fmin1=double(min(min(Egray)));
level=(fmax1-(fmax1-fmin1)/3)/255;
bw2=im2bw(Egray,level);
figure,imshow(bw2);title('图像二值化'); %Step4 对得到二值图像作开闭操作进行滤波
grd=edge(bw2,'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 = regionprops(L,'basic');% 用来度量图像区域属性的函数
Area=[Feastats.Area]; % Area: 前景区域面积,即不为0区域面积
BoundingBox=[Feastats.BoundingBox]; %[x y width height]
RGB = label2rgb(L, 'spring', 'k', 'shuffle');
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('车牌二值子图');
运行结果显示:Undefined function or variable 'startrow'.
请问怎么修改啊?