handwritings.m

来自「支持向量机的手写数字识别,绝对原创,识别率100%」· M 代码 · 共 40 行

M
40
字号
function features = HandWritings(f,para)
  
if ndims(f) == 3
   f = rgb2gray(f);
end

[Row,Col] = find(f == 0);
minCol = min(Col);
maxCol = max(Col);
minRow = min(Row);
maxRow = max(Row);
Width = maxCol - minCol;
Hight = maxRow - minRow;
WidthStep = floor(Width/5);
HightStep = floor(Hight/5);
startPoints = [];
for t = 1 : 25
    startPoints  = [startPoints;[minRow,minCol] + [floor((t - 1)/5)*HightStep , mod(t - 1,5)*WidthStep]];
end

fs = {};

for t = 1 : 25
    fs  = [fs,f(startPoints(t,1):startPoints(t,1)+HightStep, startPoints(t,2):startPoints(t,2)+WidthStep)];
end

if nargin == 2
   for t = 1:25
       subplot(5,5,t);
       image(fs{t});
       axis off;
   end    
end

features = [];
SumNum = WidthStep * HightStep;
for t = 1:25
    Nums = sum(sum(fs{t}==0))/SumNum;
    features = [features,Nums];
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?