资源简介

单特征 MNIST库 手写数字识别实现(matlab),采用粗网格特征进行学习识别,首先提取MNIST数据库60000个训练样本手进行特征提取,然后对10000个测试样本进行测试,matlab 实现

资源截图

代码片段和文件信息

clear;
clc;
directory=uigetdir(‘‘‘选择学习图片路径‘);
ImageNum=60000;
numis=textread(‘study.txt‘‘%1d‘);  %numis 是正确的ImageNum个样本值
feasum=zeros(1016);      %10*16的特征之和数组
numsum=zeros(10);       %0-9的个数,0用10代替
h_w=waitbar(0‘请稍后,正在处理中>>>>>>>>‘);
for i=1:ImageNum
    impath=fullfile(directory[‘TrainImage_‘ num2str(i‘%05d‘) ‘.bmp‘]);
    rawim=imread(impath);
    xx=find(rawim<150);
    rawim(xx)=0;
    x=find(rawim>=150);
    rawim(x)=255;
    bwim=im2bw(rawim0.5);%二值化
    
    gridnum=[0000000000000000];%保存16个块的黑色像素个数
    xbase=1;
    ybase=1;
    for yz=0:3
        for xz=0:3          %这两个是4*4的大块
            for ybase=1:7
                for xbase=1:7       %这两个是在7*7的小块内
                    if(bwim(yz*7+ybasexz*7+xbase)==0)  %如果是黑色像素
                        gridnum(yz*4+xz+1)=gridnum(yz*4+xz+1)+1;
                    end
                end
            end
        end
    end
    
    jud=numis(i);
    if jud==0       %如果是0,放在第十个
        jud=10;
    end
    numsum(jud)=numsum(jud)+1;      %统计0-9的个数
    for t=1:16
        feasum(judt)=feasum(judt)+gridnum(t);
    end
    waitbar(i/ImageNum);
end
sum=zeros(10);      %sum保存0-9所有节点黑色像素总和,用于归一化
for i=1:10
    for j=1:16
        sum(i)=sum(i)+feasum(ij);
    end
end
feature=zeros(1016);
for i=1:10
    for j=1:16
        feature(ij)=feasum(ij)/sum(i);
    end
end
fid=fopen(‘features.txt‘‘w‘); %将特征值写到 feature.txt 文件
for i=1:10
fprintf(fid‘%1.8f %1.8f %1.8f %1.8f %1.8f %1.8f %1.8f %1.8f %1.8f %1.8f %1.8f %1.8f %1.8f %1.8f %1.8f %1.8f\n‘feature(i1)feature(i2)feature(i3)feature(i4)feature(i5)feature(i6)feature(i7)feature(i8)feature(i9)feature(i10)feature(i11)feature(i12)feature(i13)feature(i14)feature(i15)feature(i16));
end
fclose(fid);
close(h_w);

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1760  2011-11-12 10:04  44grid\features.txt

     文件       2257  2011-11-12 13:18  44grid\grid-recognition.asv

     文件       1860  2011-11-12 09:50  44grid\grid_study.asv

     文件       1945  2011-11-12 13:55  44grid\grid_study.m

     文件      94416  2011-11-15 18:48  44grid\log.txt

     文件    1072694  2011-11-15 18:58  44grid\ok.bmp

     文件       1654  2011-11-15 18:55  44grid\ok.fig

     文件        269  2011-11-12 14:56  44grid\ReadMe.txt

     文件       2330  2011-11-15 18:47  44grid\recognition.m

     文件     120000  2011-11-10 21:42  44grid\study.txt

     文件      20000  2011-11-10 21:32  44grid\test.txt

     文件       1320  2011-11-12 19:40  66splitline\features.txt

     文件       1989  2011-11-12 16:54  66splitline\grid_study.asv

     文件      91112  2011-11-15 18:58  66splitline\log.txt

     文件    1072694  2011-11-15 19:00  66splitline\ok.bmp

     文件        270  2011-11-12 17:23  66splitline\ReadMe.txt

     文件       1666  2011-11-12 18:57  66splitline\recognition.asv

     文件       2433  2011-11-15 18:57  66splitline\recognition.m

     文件       2286  2011-11-12 19:34  66splitline\study.m

     文件     120000  2011-11-10 21:42  66splitline\study.txt

     文件      20000  2011-11-10 21:32  66splitline\test.txt

     文件       5400  2011-11-12 15:17  77grid\features - 副本.txt

     文件       5403  2011-11-12 20:09  77grid\features.txt

     文件       1701  2011-11-12 14:20  77grid\grid_study.asv

     文件       1710  2011-11-12 20:05  77grid\grid_study.m

     文件      59668  2011-11-13 17:05  77grid\log.txt

     文件        269  2011-11-12 15:51  77grid\ReadMe.txt

     文件       2267  2011-11-12 14:31  77grid\recognition.asv

     文件       2277  2011-11-12 20:58  77grid\recognition.m

     文件     120000  2011-11-10 21:42  77grid\study.txt

............此处省略47个文件信息

评论

共有 条评论