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