问题:手写数字识别
数据集
数据集链接请点击我
代码
%mat2vector.m
function [data_]= mat2vector(data,num)
[row,col,~]= size(data);
data_=zeros(num,row*col);
for page =1:num
for rows =1:row
for cols=1:col
data_(page,((rows-1)*col+cols))= im2double(data(rows,cols,page));
end
end
end
end
image = cell(1,10);
for i= 0:9
filename = sprintf('E:/fig/model/%d.bmp',i);
image{1,i+1} = mat2vector(imresize(imread(filename),[28,28]),1);
end
correct_num=0;
for index = 0:9
distance =zeros(1,10);
fname=sprintf('E:/fig/test/%d.1.bmp',index);
sample =mat2vector(imresize(imread(fname),[28,28]),1);
for j= 1:10
distance(j)=pdist2(sample,image{1,j},'euclidean');
end
[m,p]= min(distance);
if p-1==index
correct_num=correct_num+1;
end
fprintf('数字%d到模板的最小距离为:%d,匹配到的类别为:%d\n',[index,m,p-1]);
end
fprintf('共测试10个样本,正确匹配个数为%d个\n',correct_num);
执行结果
补充(数据集文件夹的注意事项)
有问题联系xylwork@yeah.net