资源简介
人脸表情识别,有做这个研究方向的朋友可以看看这个程序。挺不错的
代码片段和文件信息
% Karhunen-Loeve for face recognition
% By Alex Chirokov Alex.Chirokov@gmail.com
clear all;
% Load the ATT image set
k = 0;
for i=1:1:40
for j=1:1:10
filename = sprintf(‘C:\\MATLAB\\att_faces\\s%d\\%d.pgm‘ij);
image_data = imread(filename);
k = k + 1;
x(:k) = image_data(:);
anot_name(k:) = sprintf(‘%2d:%2d‘ij); % for plot annotations
end;
end;
nImages = k; %total number of images
imsize = size(image_data); %size of image (they all should have the same size)
nPixels = imsize(1)*imsize(2); %number of pixels in image
x = double(x)/255; %convert to double and normalize
%Calculate the average
avrgx = mean(x‘)‘;
for i=1:1:nImages
x(:i) = x(:i) - avrgx; % substruct the average
end;
subplot(221); imshow(reshape(avrgx imsize)); title(‘mean face‘)
%compute covariance matrix
cov_mat = x‘*x;
[VD] = eig(cov_mat); %eigen values of cov matrix
V = x*V*(abs(D))^-0.5;
subplot(222); imshow(ScaleImage(reshape(V(:nImages )imsize))); title(‘1st eigen face‘);
subplot(223); imshow(ScaleImage(reshape(V(:nImages-1)imsize))); title(‘2st eigen face‘);
subplot(224); plot(diag(D)); title(‘Eigen values‘);
%image decomposition coefficients
KLCoef = x‘*V;
%reconstruction of Image
%KLCoef(:1:1:1)= 0; % filtration
image_index = 12; %index of face to be reconstructed
reconst = V*KLCoef‘;
diff = abs(reconst(:image_index) - x(:image_index));
strdiff_sum = sprintf(‘delta per pixel: %e‘sum(sum(diff))/nPixels);
figure;
subplot(221); imshow((reshape(avrgx+reconst(:image_index) imsize))); title(‘Reconstructed‘);
subplot(222); imshow((reshape(avrgx+x(:image_index) imsize)));title(‘original‘);
subplot(223); imshow(ScaleImage(reshape(diff imsize))); title(strdiff_sum);
for i=1:1:nImages
dist(i) = sqrt(dot(KLCoef(1:)-KLCoef(i:) KLCoef(1:)-KLCoef(i:))); %euclidean
end;
subplot(224); plot(dist‘.-‘); title(‘euclidean distance from the first face‘);
%2D plot of first 2 decomposition coefficients with annotatons
% annotations have format Face:Extression i.e 5:6 means image was taken
% from s5/6.pgm expression 6 of the person in the set s5.
figure;
show_faces = 1:1:nImages/2;
plot(KLCoef(show_facesnImages) KLCoef(show_facesnImages-1)‘.‘); title(‘Desomposition: Numbers indicate (Face:expression)‘);
for i=show_faces
name = anot_name(i:);
text(KLCoef(inImages) KLCoef(inImages-1)name‘FontSize‘8);
end;
% Find similar faces variable ‘image_index‘ defines face used in comparison
image_index = 78;
for i=1:1:nImages
dist_comp(i) = sqrt(dot(KLCoef(image_index:)-KLCoef(i:) KLCoef(image_index:)-KLCoef(i:))); %euclidean
strDist(i) = cellstr(sprintf(‘%2.2f\n‘dist_comp(i)));
end;
[sorted sorted_index] = sort(dist_comp); % sort distances
figure; % open new figure
for i=1:1:9
subplot(33i); imshow((reshape(avrgx+x(:so
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3071 2005-02-24 15:03 Karhunen-Loeve Decomposition for Face Recognition\KarhunenLoeve.m
文件 114 2005-02-20 19:54 Karhunen-Loeve Decomposition for Face Recognition\ScaleImage.m
目录 0 2006-04-13 22:55 Karhunen-Loeve Decomposition for Face Recognition
----------- --------- ---------- ----- ----
3185 3
评论
共有 条评论