1 简介

基于稀疏表示的分类方法关键之一就是字典的学习。欧阳琰等[9]直接将图像的表情特征作为字典元素,然后以该字典为基础进行表情分类。

【图像识别】基于ksvd字典学习实现表情识别matlab代码_类方法

【图像识别】基于ksvd字典学习实现表情识别matlab代码_类方法_02

2 部分代码

%
  • 1.
%
  • 1.
% Main Program of KSVD-NN based facial expression recognition.
  • 1.
%
  • 1.
% Ziyang Zhang
  • 1.
clear
  • 1.
datadim='37x30';
  • 1.
%datadim='50x40';
  • 1.
%datadim='gabor_all';
  • 1.
testmethod='unfamiliar';
  • 1.
% prepare image data
  • 1.
[data,label] = PrepareData(datadim,testmethod,9);
  • 1.
% direct nearest neighbor classification
  • 1.
testresult = nearestNeighbor( data.train , label.train , data.test );
  • 1.
rate = length( find( ( testresult - label.test ) == 0 ) ) / length(label.test);
  • 1.
clear testresult;
  • 1.
fprintf('\n Direct nearest neighbot on pixel values: rec rate: %f \n',rate);
  • 1.
% training process using KSVD
  • 1.
param.L = 12;
  • 1.
param.K = 90;
  • 1.
param.numIteration = 20;
  • 1.
param.errorFlag = 0;
  • 1.
param.preserveDCAtom = 0;
  • 1.
param.InitializationMethod = 'DataElements';
  • 1.
param.displayProgress = 1;
  • 1.
disp('Starting to train the dictionary');
  • 1.
tt=cputime;
  • 1.
[Dictionary,KSVDout] = KSVD(data.train,param);
  • 1.
fprintf('\ntime of K-SVD: %f\n\n' , cputime - tt);
  • 1.
%I=showdict(Dictionary,[37,30],10,8,'lines') ;
  • 1.
%imshow(I);
  • 1.
%KSVDout.CoefMatrix = full( KSVDout.CoefMatrix );
  • 1.
tt=cputime;
  • 1.
% Using OMP to find the sparse coefficients for test samples
  • 1.
coeftest = OMP(Dictionary,data.test,param.L);
  • 1.
%coeftest = full( coeftest );
  • 1.
% nearest neighbor classification
  • 1.
testresult = nearestNeighbor( KSVDout.CoefMatrix , label.train , coeftest );
  • 1.
fprintf('\ntime of testing: %f\n\n' , cputime - tt);
  • 1.
rate = length( find( ( testresult - label.test ) == 0 ) ) / length(label.test);
  • 1.
fprintf('\n The result when image dimension: %s test-method: %s \n' , datadim, testmethod );
  • 1.
fprintf(' L(sparsity of coef) = %d, K(number of atoms) = %d : recognition rate: %f \n\n\n',param.L , param.K , rate);
  • 1.
% direct pixal values
  • 1.
testresult = nearestNeighbor( data.train , label.train , data.test );
  • 1.
rate = length( find( ( testresult - label.test ) == 0 ) ) / length(label.test);
  • 1.

3 仿真结果

【图像识别】基于ksvd字典学习实现表情识别matlab代码_类方法_03

【图像识别】基于ksvd字典学习实现表情识别matlab代码_参考文献_04

4 参考文献

[1]刘清泉. 基于低秩稀疏的人脸表情识别方法研究. (Doctoral dissertation, 昆明理工大学).

【图像识别】基于ksvd字典学习实现表情识别matlab代码_参考文献_05