close all
clear all
net=BPnet_creat;
while(1)
test=input('please input the images name :','s'); % 提示输入待识别的图片的名称(输入0~9的数字即可)
if abs(test)<abs('0') || abs(test)>abs('9') % 输入不存在的图片名称时退出程序(需为单字符)
close all
clear all
return
else
x=imread(test,'bmp'); % 读入图片
x=x(1:2:size(x,1),1:2:size(x,2));
subplot(3,1,1);
imshow(x);
title('待测样本原始图');
x1=imnoise(x,'gaussian',0,0.02); % 给图片加噪声
subplot(3,1,2);
imshow(x1); % 显示加噪声的图片
title('待测样本加噪图');
for m=0:size(x,1)-1 % 按列抽取x,形成测试向量
p(m*size(x,1)+1:(m+1)*size(x,1),1)=double(x1(1:size(x,1),m+1));
end
[y,Pf,Af]=sim(net,p); % 对网络仿真
disp(strcat('The recogrized num is: ',num2str(y)));
y=round(y); % 输出识别的结果
switch y
case 0
subplot(3,1,3);
x2=imread('0.bmp','bmp');
imshow(x2);
title('识别出的数');
case 1
subplot(3,1,3);
x2=imread('1.bmp','bmp');
imshow(x2);
title('识别出的数');
case 2
subplot(3,1,3);
x2=imread('2.bmp','bmp');
imshow(x2);
title('识别出的数');
case 3
subplot(3,1,3);
x2=imread('3.bmp','bmp');
imshow(x2);
title('识别出的数');
case 4
subplot(3,1,3);
x2=imread('4.bmp','bmp');
imshow(x2);
title('识别出的数');
case 5
subplot(3,1,3);
x2=imread('5.bmp','bmp');
imshow(x2);
title('识别出的数');
case 6
subplot(3,1,3);
x2=imread('6.bmp','bmp');
imshow(x2);
title('识别出的数');
case 7
subplot(3,1,3);
x2=imread('7.bmp','bmp');
imshow(x2);
title('识别出的数');
case 8
subplot(3,1,3);
x2=imread('8.bmp','bmp');
imshow(x2);
title('识别出的数');
case 9
subplot(3,1,3);
x2=imread('9.bmp','bmp');
imshow(x2);
title('识别出的数');
end
end
end