?? jianliyangben.m
字號:
%輸入源樣本 1,2,3,4為不同字體數字
clear all
for pcolum=0:39
p1=ones(30,30); %建立全為1的樣本矩陣
m=strcat('F:\MyMATLAB\sjwl\num\',int2str(pcolum),'.jpg');
I=imread(m); %循環讀入0-39個樣本數字文件
I1=im2bw(I,0.3); %對輸入圖像進行二值化處理 采用全局閾值0.3
[m,n]=find(I1==0);
rowmin=min(m);
rowmax=max(m);
colummin=min(n);
colummax=max(n);
I2=I1(rowmin:rowmax,colummin:colummax); %截取是入圖像中的數字部分
rate=30/max(size(I2));
I3=imresize(I2,rate); %對輸入文件變尺寸處理
[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 {0,10,20,30}
t(pcolum+1)=0 %數字0
case{1,11,21,31}
t(pcolum+1)=1 %數字1
case{2,12,22,32}
t(pcolum+1)=2 %數字2
case{3,13,23,33}
t(pcolum+1)=3 %數字3
case{4,14,24,34}
t(pcolum+1)=4 %數字4
case{5,15,25,35}
t(pcolum+1)=5 %數字5
case{6,16,26,36}
t(pcolum+1)=6 %數字6
case{7,17,27,37}
t(pcolum+1)=7 %數字7
case{8,18,28,38}
t(pcolum+1)=8 %數字8
case{9,19,29,39}
t(pcolum+1)=9 %數字9
end %建立與訓練樣本對應的輸出值t
end
save 51ET p t;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -