一、简介

【人脸识别】基于matlab ksvd字典学习人脸表情识别【含Matlab源码 460期】_实例分析

二、源代码

%
%
% 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);

四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] 蔡利梅.MATLAB图像处理——理论、算法与实例分析[M].清华大学出版社,2020.
[2]杨丹,赵海滨,龙哲.MATLAB图像处理实例详解[M].清华大学出版社,2013.
[3]周品.MATLAB图像处理与图形用户界面设计[M].清华大学出版社,2013.
[4]刘成龙.精通MATLAB图像处理[M].清华大学出版社,2015.
[5]孟逸凡,柳益君.基于PCA-SVM的人脸识别方法研究[J].科技视界. 2021,(07)
[6]张娜,刘坤,韩美林,陈晨.一种基于PCA和LDA融合的人脸识别算法研究[J].电子测量技术. 2020,43(13)
[7]陈艳.基于BP神经网络的人脸识别方法分析[J].信息与电脑(理论版). 2020,32(23)
[8]戴骊融,陈万米,郭盛.基于肤色模型和SURF算法的人脸识别研究[J].工业控制计算机. 2014,27(02)