资源简介
基于MATLAB的KL人脸识别程序(可运行).rar
代码片段和文件信息
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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(s
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3351 2017-12-18 19:14 基于MATLAB的KL人脸识别程序(可运行)\KLshibie.m
文件 394 2017-12-18 19:14 基于MATLAB的KL人脸识别程序(可运行)\liulantupian.m
目录 0 2017-12-18 19:15 基于MATLAB的KL人脸识别程序(可运行)
----------- --------- ---------- ----- ----
3745 3
- 上一篇:模糊综合评价matlab程序
- 下一篇:Simuli
nk单向感应电动机仿真模型
相关资源
- 用matlab打造自己的注册机.zip
- matlab坐标平移旋转源代码.zip
- 3.2.2kalman_tempreture.m
- DLM_constant_delta.m
- binary.m
- svgensim4.mdl
- magsint.m
- xiangganleiji.m
- 298496基于Matlab的m序列发生器的设计与
- 有源四阶切比雪夫滤波器.ms12
- sy3_2DPSK.mdl
- Matlab.vR2016b_NMac.to.torrent
- 欺骗的艺术-凯文·米特尼克.mobi
- Boost(1).mdl
- bd503b752b2ccf3d8e0912b7522098d7.m
- PD.m
- PIDTUNING.mlappinstall
- u0xaoz.ms10
- MATLAB的系统动力学仿真.pdf
- lung_test.m
- matlab使用libsvm进行分类代码.rar
- 高频单调谐回路放大器.ms11
- 无刷直流电机MATLAB模型.rar
- 基于MATLAB的质点弹道计算与外弹道优
- yw5bth.m
- s_niblack3.m
- matlab2014中文.txt
- zw_matlab形成节点导纳矩阵的程序.zip
- zw_MATLAB实现图像去噪滤波锐化边缘检
- 分支定界法Matlab程序实现与验证.pdf
评论
共有 条评论