%
%
% Main Program of KSVD-NN based facial expression recognition.
%
% Ziyang Zhang
clear
datadim='37x30';
%datadim='50x40';
%datadim='gabor_all';
testmethod='unfamiliar';
% prepare image data
[data,label] = PrepareData(datadim,testmethod,9);
% direct nearest neighbor classification
testresult = nearestNeighbor( data.train , label.train , data.test );
rate = length( find( ( testresult - label.test ) == 0 ) ) / length(label.test);
clear testresult;
fprintf('\n Direct nearest neighbot on pixel values: rec rate: %f \n',rate);
% training process using KSVD
param.L = 12;
param.K = 90;
param.numIteration = 20;
param.errorFlag = 0;
param.preserveDCAtom = 0;
param.InitializationMethod = 'DataElements';
param.displayProgress = 1;
disp('Starting to train the dictionary');
tt=cputime;
[Dictionary,KSVDout] = KSVD(data.train,param);
fprintf('\ntime of K-SVD: %f\n\n' , cputime - tt);
%I=showdict(Dictionary,[37,30],10,8,'lines') ;
%imshow(I);
%KSVDout.CoefMatrix = full( KSVDout.CoefMatrix );
tt=cputime;
% Using OMP to find the sparse coefficients for test samples
coeftest = OMP(Dictionary,data.test,param.L);
%coeftest = full( coeftest );
% nearest neighbor classification
testresult = nearestNeighbor( KSVDout.CoefMatrix , label.train , coeftest );
fprintf('\ntime of testing: %f\n\n' , cputime - tt);
rate = length( find( ( testresult - label.test ) == 0 ) ) / length(label.test);
fprintf('\n The result when image dimension: %s test-method: %s \n' , datadim, testmethod );
fprintf(' L(sparsity of coef) = %d, K(number of atoms) = %d : recognition rate: %f \n\n\n',param.L , param.K , rate);
% direct pixal values
testresult = nearestNeighbor( data.train , label.train , data.test );
rate = length( find( ( testresult - label.test ) == 0 ) ) / length(label.test);
完整代码或者代写添加QQ1575304183
往期回顾>>>>>>
【图像识别】基于cnn卷积神经网络之验证码识别matlab源码
【图像识别】基于svm植物叶子疾病检测和分类matlab源码
【图像识别】路面裂缝识别含GUI源码matlab源码
【图像识别】基于RGB和BP神经网络的人民币识别系统含GUI界面matlab源码
【图像识别】条形码识别系统matlab源码
【图像识别】基于不变矩的数字验证码识别含GUI界面matlab源码
【图像识别】基于模板匹配之手写数字识别系统GUI界面matlab源码
【图像识别】条形码识别系统matlab源码
【图像分类】基于极限学习分类器对遥感图像分类matlab源码
【图像识别】基于反馈神经Hopfield的数字识别matlab源码
【图像识别】基于二值膨胀差分和椒盐滤波之教室内人数识别系统matlab源码
【模式识别】基于 Hough变换视频车道线检测matlab源码
【模式识别】基于差影法之三维人体姿态行为识别matlab源码
【图像识别】基于组合BCOSFIRE过滤器进行墙体裂缝识别matlab源码
【模式识别】基于贝叶斯最小错误率手写数字识别matlab 源码
【图像识别】基于模板匹配之人脸表情识别matlab源码含GUI
【图像识别】基于LBP+LPQ算法融合人脸表情识别matlab源码