识别主程序
rotI = imread('2.jpg');
if ndims(rotI) == 3
rotI = rgb2gray(rotI);
end
gmax = double(max(max(rotI)));
gmin = double(min(min(rotI)));
T=round(gmax-(gmax-gmin)/3);% T 为二值化的阈值
rotI=im2bw(rotI,T/256);
subplot(3,2,1);
imshow(rotI)
title('二值化图像');
bw=bwareaopen(rotI,50);
subplot(3,2,2);
imshow(bw);
title('形态学滤波后的二值化图像');
thre = 20;
[y1,x1,z1]=size(bw);
I3=double(bw);
TT=1; %%%%%%%去除图像顶端和底端的不感兴趣区域%%%%%
Y1=zeros(y1,1);
for i=1:y1
for j=1:x1
if(I3(i,j,1)==1)
Y1(i,1)= Y1(i,1)+1 ;
end
end
end
Py1=1;
Py0=1;
while ((Y1(Py0,1)<thre)&&(Py0<y1))
Py0=Py0+1;
end
Py1=Py0;
while((Y1(Py1,1)>=thre)&&(Py1<y1))
Py1=Py1+1;
end
bw=bw(Py0:Py1,:,:);
subplot(3,2,3);
imshow(bw);
title('目标图像区域');
%%%