📄 jianliyangben.m
字号:
%输入源样本 1,2,3,4为不同字体数字
clear all
for pcolum=1:5
p1=ones(30,30); %建立全为1的样本矩阵
m=strcat('D:\matlab7\work\test_allen\face\',int2str(pcolum),'.bmp');
I=imread(m); %循环读入0-39个样本数字文件
I1=im2bw(I,0.3); %对输入图像进行二值化处理 采用全局阈值0.3
%imshow(I1);
[m,n]=find(I1==0);
rowmin=min(m);
rowmax=max(m);
colummin=min(n);
colummax=max(n);
I2=I1(rowmin:rowmax*0.85,colummin:colummax); %截取是入图像中的数字部分
imshow(I2);
rate=30/max(size(I2));
I3=imresize(I2,rate); %对输入文件变尺寸处理
imshow(I3);
[i,j]=size(I3);
row=round((30-i)/2);
colum=round((30-j)/2);
p1(row+1:row+i,colum+1:colum+j)=I3; %建立起30*30的矩阵
p1=-1*p1+ones(30,30); %反色处理
for hh=1:30
p((hh-1)*30+1:(hh-1)*30+30,pcolum+1)=p1(hh,1:30);
end %将处理的源样本输入供神经网络训练的样本 pcolum是样本数循环变量
switch pcolum
case {1,11,21,310}
t(pcolum+1)=1 %数字0
case{2,12,22,32}
t(pcolum+1)=2 %数字1
case{3,13,23,33}
t(pcolum+1)=3 %数字2
case{4,14,24,3}
t(pcolum+1)=4 %数字3
case{5,15,25,35}
t(pcolum+1)=5 %数字4
end %建立与训练样本对应的输出值t
end
save 51ET p t;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -