Pattern Recognition For HandWritten with Semeion Data

来源:互联网 发布:搜狗打字软件 编辑:程序博客网 时间:2024/05/22 05:30

We can get the semeion handwritten digi data set  from http://archive.ics.uci.edu/ml/. You can read the data description firstly. 

First , statistic the mean of each species. Then compute sample for each species euclidean distance. Find the min distance and recognise it .

Matlab code:

load semeion.dataimg = semeion(:,1:256);%%%%%%%%%%%%%恢复成624*640的图像%%%%%%%handwrite = zeros(16,16);handwritemap = zeros(25488,16);for n=1:1593for m=1:16    left = (m-1)*16+1;    right = left + 15;    height = (n-1)*16 +1;    handwrite(m,1:16) = img(n,left:right);endhandwritemap(height:height+15,1:16)=handwrite(1:16,1:16);endhandwritemap2 = zeros(624,640);height = 0;for m=1:39    for n=1:40        xindex = 16*(n-1)+1;        yindex = 16*(m-1)+1;        handwritemap2(yindex:yindex+15,xindex:xindex+15) = handwritemap(height*16+1:height*16+16,1:16);        height = height+1;    endendimshow(handwritemap2); %%%%%显示样本图像imwrite(handwritemap2,'handwritemap2.bmp','bmp');%%%%%%%%统计召回率,精度label = semeion(:,257:266); %每个样本的标签labeldec = zeros(1593,1);for i=1:10  %将标签的值转化为10进制    tmp = find(label(:,i));    labeldec(tmp,1) = i;endsamplesize = size(img,1);%训练样本大小dim = size(img,2);%样本维数Labels = unique(labeldec);Labelsize = length(Labels);%标签的种类Templates = zeros(Labelsize,dim);for i = 1:Labelsize%统计训练样本集    id = labeldec==i; %matlab自动优化的,原来为id = find (lebaldec = i);    Templates(i,:) = mean(img(id,:));%每种类别的均值endDist = pdist2(img,Templates);%识别,识别的集合也是img,返回Euclidean距离[y,id] = min(Dist,[],2);%找到每个识别对象的最小距离Out = Labels(id);acceptarray = zeros(Labelsize,1);recall = zeros(Labelsize,1);recognition = zeros(Labelsize,1);precious =  zeros(Labelsize,1);right = 0;for n = 1:samplesize        b = Out(n,1);        recognition(b,1) = recognition(b,1) + 1;%统计出识别的数量endfor i = 1:10    accept = 0;    tmp = find(label(:,i));    tmpsize = size(tmp);    for m = 1:tmpsize        if Out(tmp(m,1),1)==i        accept = accept + 1;    end    end     acceptarray(i,1) = accept;     recall(i,1) = accept/tmpsize(1,1);%召回率     precious(i,1) = accept/recognition(i,1);%精确度     right = right + accept;endrateofright = right/samplesize;%无法使用ClassificationKNN.fit,因为这是2012a之后才添加的,我的版本是2010a% model = ClassificationKNN.fit(img,labelK,'NumNeighbors',1);% Z = predict(model,img);


handwrite:


the result of precious:


recall:




0 0
原创粉丝点击