当前位置:首页 > 代码 > 正文

包含matlabpca人脸识别代码的词条

admin 发布:2022-12-19 16:57 131


本篇文章给大家谈谈matlabpca人脸识别代码,以及对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

matlab中PCA的人脸识别,最后得出的识别率是什么意思啊!

识别率指的是通过人脸识别技术识别正确数占识别总数的百分比。

人脸识别算法分类

基于人脸特征点的识别算法(Feature-based recognition algorithms)。

基于整幅人脸图像的识别算法(Appearance-based recognition algorithms)。

基于模板的识别算法(Template-based recognition algorithms)。

利用神经网络进行识别的算法(Recognition algorithms using neural network)。

神经网络识别

基于光照估计模型理论

提出了基于Gamma灰度矫正的光照预处理方法,并且在光照估计模型的基础上,进行相应的光照补偿和光照平衡策略。

优化的形变统计校正理论

基于统计形变的校正理论,优化人脸姿态;

强化迭代理论

强化迭代理论是对DLFA人脸检测算法的有效扩展;

独创的实时特征识别理论

该理论侧重于人脸实时数据的中间值处理,从而可以在识别速率和识别效能之间,达到最佳的匹配效果

matlab人脸识别系统pca 算法

%一个修改后的PCA进行人脸识别的Matlab代码

% calc xmean,sigma and its eigen decomposition

allsamples=[];%所有训练图像

for i=1:40

for j=1:5

a=imread(strcat('D:\rawdata\ORL\s',num2str(i),'\',num2str(j),'.pgm'));

% imshow(a);

b=a(1:112*92); % b是行矢量 1×N,其中N=10304,提取顺序是先列后行,即从上到下,从左到右

b=double(b);

allsamples=[allsamples; b]; % allsamples 是一个M * N 矩阵,allsamples 中每一行数据代表一张图片,其中M=200

end

end

samplemean=mean(allsamples); % 平均图片,1 × N

for i=1:200 xmean(i,:)=allsamples(i,:)-samplemean; % xmean是一个M × N矩阵,xmean每一行保存的数据是“每个图片数据-平均图片”

end;

sigma=xmean*xmean'; % M * M 阶矩阵

[v d]=eig(sigma);

d1=diag(d);

[d2 index]=sort(d1); %以升序排序

cols=size(v,2);% 特征向量矩阵的列数

for i=1:cols

vsort(:,i) = v(:, index(cols-i+1) ); % vsort 是一个M*col(注:col一般等于M)阶矩阵,保存的是按降序排列的特征向量,每一列构成一个特征向量

dsort(i) = d1( index(cols-i+1) ); % dsort 保存的是按降序排列的特征值,是一维行向量

end %完成降序排列

%以下选择90%的能量

dsum = sum(dsort);

dsum_extract = 0;

p = 0;

while( dsum_extract/dsum 0.9)

p = p + 1;

dsum_extract = sum(dsort(1:p));

end

i=1;

% (训练阶段)计算特征脸形成的坐标系

while (i=p dsort(i)0)

base(:,i) = dsort(i)^(-1/2) * xmean' * vsort(:,i); % base是N×p阶矩阵,除以dsort(i)^(1/2)是对人脸图像的标准化,详见《基于PCA的人脸识别算法研究》p31

i = i + 1;

end

% add by wolfsky 就是下面两行代码,将训练样本对坐标系上进行投影,得到一个 M*p 阶矩阵allcoor

allcoor = allsamples * base;

accu = 0;

% 测试过程

for i=1:40

for j=6:10 %读入40 x 5 副测试图像

a=imread(strcat('D:\rawdata\ORL\s',num2str(i),'\',num2str(j),'.pgm'));

b=a(1:10304);

b=double(b);

tcoor= b * base; %计算坐标,是1×p阶矩阵

for k=1:200

mdist(k)=norm(tcoor-allcoor(k,:));

end;

%三阶近邻

[dist,index2]=sort(mdist);

class1=floor( index2(1)/5 )+1;

class2=floor(index2(2)/5)+1;

class3=floor(index2(3)/5)+1;

if class1~=class2 class2~=class3

class=class1;

elseif class1==class2

class=class1;

elseif class2==class3

class=class2;

end;

if class==i

accu=accu+1;

end;

end;

end;

accuracy=accu/200 %输出识别率

函数调用是定义函数,然后用函数名进行调用就可以了

我的QQ382101365

高分求matlab pca人脸识别程序

function pca (path, trainList, subDim)

%

% PROTOTYPE

% function pca (path, trainList, subDim)

%

% USAGE EXAMPLE(S)

% pca ('C:/FERET_Normalised/', trainList500Imgs, 200);

%

% GENERAL DESCRIPTION

% Implements the standard Turk-Pentland Eigenfaces method. As a final

% result, this function saves pcaProj matrix to the disk with all images

% projected onto the subDim-dimensional subspace found by PCA.

%

% REFERENCES

% M. Turk, A. Pentland, Eigenfaces for Recognition, Journal of Cognitive

% Neurosicence, Vol. 3, No. 1, 1991, pp. 71-86

%

% M.A. Turk, A.P. Pentland, Face Recognition Using Eigenfaces, Proceedings

% of the IEEE Conference on Computer Vision and Pattern Recognition,

% 3-6 June 1991, Maui, Hawaii, USA, pp. 586-591

%

%

% INPUTS:

% path - full path to the normalised images from FERET database

% trainList - list of images to be used for training. names should be

% without extension and .pgm will be added automatically

% subDim - Numer of dimensions to be retained (the desired subspace

% dimensionality). if this argument is ommited, maximum

% non-zero dimensions will be retained, i.e. (number of training images) - 1

%

% OUTPUTS:

% Function will generate and save to the disk the following outputs:

% DATA - matrix where each column is one image reshaped into a vector

% - this matrix size is (number of pixels) x (number of images), uint8

% imSpace - same as DATA but only images in the training set

% psi - mean face (of training images)

% zeroMeanSpace - mean face subtracted from each row in imSpace

% pcaEigVals - eigenvalues

% w - lower dimensional PCA subspace

% pcaProj - all images projected onto a subDim-dimensional space

%

% NOTES / COMMENTS

% * The following files must either be in the same path as this function

% or somewhere in Matlab's path:

% 1. listAll.mat - containing the list of all 3816 FERET images

%

% ** Each dimension of the resulting subspace is normalised to unit length

%

% *** Developed using Matlab 7

%

%

% REVISION HISTORY

% -

%

% RELATED FUNCTIONS (SEE ALSO)

% createDistMat, feret

%

% ABOUT

% Created: 03 Sep 2005

% Last Update: -

% Revision: 1.0

%

% AUTHOR: Kresimir Delac

% mailto: kdelac@ieee.org

% URL:

%

% WHEN PUBLISHING A PAPER AS A RESULT OF RESEARCH CONDUCTED BY USING THIS CODE

% OR ANY PART OF IT, MAKE A REFERENCE TO THE FOLLOWING PAPER:

% Delac K., Grgic M., Grgic S., Independent Comparative Study of PCA, ICA, and LDA

% on the FERET Data Set, International Journal of Imaging Systems and Technology,

% Vol. 15, Issue 5, 2006, pp. 252-260

%

% If subDim is not given, n - 1 dimensions are

% retained, where n is the number of training images

if nargin 3

subDim = dim - 1;

end;

disp(' ')

load listAll;

% Constants

numIm = 3816;

% Memory allocation for DATA matrix

fprintf('Creating DATA matrix\n')

tmp = imread ( [path char(listAll(1)) '.pgm'] );

[m, n] = size (tmp); % image size - used later also!!!

DATA = uint8 (zeros(m*n, numIm)); % Memory allocated

clear str tmp;

% Creating DATA matrix

for i = 1 : numIm

im = imread ( [path char(listAll(i)) '.pgm'] );

DATA(:, i) = reshape (im, m*n, 1);

end;

save DATA DATA;

clear im;

% Creating training images space

fprintf('Creating training images space\n')

dim = length (trainList);

imSpace = zeros (m*n, dim);

for i = 1 : dim

index = strmatch (trainList(i), listAll);

imSpace(:, i) = DATA(:, index);

end;

save imSpace imSpace;

clear DATA;

% Calculating mean face from training images

fprintf('Zero mean\n')

psi = mean(double(imSpace'))';

save psi psi;

% Zero mean

zeroMeanSpace = zeros(size(imSpace));

for i = 1 : dim

zeroMeanSpace(:, i) = double(imSpace(:, i)) - psi;

end;

save zeroMeanSpace zeroMeanSpace;

clear imSpace;

% PCA

fprintf('PCA\n')

L = zeroMeanSpace' * zeroMeanSpace; % Turk-Pentland trick (part 1)

[eigVecs, eigVals] = eig(L);

diagonal = diag(eigVals);

[diagonal, index] = sort(diagonal);

index = flipud(index);

pcaEigVals = zeros(size(eigVals));

for i = 1 : size(eigVals, 1)

pcaEigVals(i, i) = eigVals(index(i), index(i));

pcaEigVecs(:, i) = eigVecs(:, index(i));

end;

pcaEigVals = diag(pcaEigVals);

pcaEigVals = pcaEigVals / (dim-1);

pcaEigVals = pcaEigVals(1 : subDim); % Retaining only the largest subDim ones

pcaEigVecs = zeroMeanSpace * pcaEigVecs; % Turk-Pentland trick (part 2)

save pcaEigVals pcaEigVals;

% Normalisation to unit length

fprintf('Normalising\n')

for i = 1 : dim

pcaEigVecs(:, i) = pcaEigVecs(:, i) / norm(pcaEigVecs(:, i));

end;

% Dimensionality reduction.

fprintf('Creating lower dimensional subspace\n')

w = pcaEigVecs(:, 1:subDim);

save w w;

clear w;

% Subtract mean face from all images

load DATA;

load psi;

zeroMeanDATA = zeros(size(DATA));

for i = 1 : size(DATA, 2)

zeroMeanDATA(:, i) = double(DATA(:, i)) - psi;

end;

clear psi;

clear DATA;

% Project all images onto a new lower dimensional subspace (w)

fprintf('Projecting all images onto a new lower dimensional subspace\n')

load w;

pcaProj = w' * zeroMeanDATA;

clear w;

clear zeroMeanDATA;

save pcaProj pcaProj;

寻matlab大牛指点PCA人脸识别代码运行问题

%更多给我邮件 我的空间有邮件地址

function pca (path, trainList, subDim)

%

% PROTOTYPE

% function pca (path, trainList, subDim)

%

% USAGE EXAMPLE(S)

% pca ('C:/FERET_Normalised/', trainList500Imgs, 200);

%

% GENERAL DESCRIPTION

% Implements the standard Turk-Pentland Eigenfaces method. As a final

% result, this function saves pcaProj matrix to the disk with all images

% projected onto the subDim-dimensional subspace found by PCA.

%

% REFERENCES

% M. Turk, A. Pentland, Eigenfaces for Recognition, Journal of Cognitive

% Neurosicence, Vol. 3, No. 1, 1991, pp. 71-86

%

% M.A. Turk, A.P. Pentland, Face Recognition Using Eigenfaces, Proceedings

% of the IEEE Conference on Computer Vision and Pattern Recognition,

% 3-6 June 1991, Maui, Hawaii, USA, pp. 586-591

%

%

% INPUTS:

% path - full path to the normalised images from FERET database

% trainList - list of images to be used for training. names should be

% without extension and .pgm will be added automatically

% subDim - Numer of dimensions to be retained (the desired subspace

% dimensionality). if this argument is ommited, maximum

% non-zero dimensions will be retained, i.e. (number of training images) - 1

%

% OUTPUTS:

% Function will generate and save to the disk the following outputs:

% DATA - matrix where each column is one image reshaped into a vector

% - this matrix size is (number of pixels) x (number of images), uint8

% imSpace - same as DATA but only images in the training set

% psi - mean face (of training images)

% zeroMeanSpace - mean face subtracted from each row in imSpace

% pcaEigVals - eigenvalues

% w - lower dimensional PCA subspace

% pcaProj - all images projected onto a subDim-dimensional space

%

% NOTES / COMMENTS

% * The following files must either be in the same path as this function

% or somewhere in Matlab's path:

% 1. listAll.mat - containing the list of all 3816 FERET images

%

% ** Each dimension of the resulting subspace is normalised to unit length

%

% *** Developed using Matlab 7

%

%

% REVISION HISTORY

% -

%

% RELATED FUNCTIONS (SEE ALSO)

% createDistMat, feret

%

% ABOUT

% Created: 03 Sep 2005

% Last Update: -

% Revision: 1.0

%

% AUTHOR: Kresimir Delac

% mailto: kdelac@ieee.org

% URL:

%

% WHEN PUBLISHING A PAPER AS A RESULT OF RESEARCH CONDUCTED BY USING THIS CODE

% OR ANY PART OF IT, MAKE A REFERENCE TO THE FOLLOWING PAPER:

% Delac K., Grgic M., Grgic S., Independent Comparative Study of PCA, ICA, and LDA

% on the FERET Data Set, International Journal of Imaging Systems and Technology,

% Vol. 15, Issue 5, 2006, pp. 252-260

%

% If subDim is not given, n - 1 dimensions are

% retained, where n is the number of training images

if nargin 3

subDim = dim - 1;

end;

disp(' ')

load listAll;

% Constants

numIm = 3816;

% Memory allocation for DATA matrix

fprintf('Creating DATA matrix\n')

tmp = imread ( [path char(listAll(1)) '.pgm'] );

[m, n] = size (tmp); % image size - used later also!!!

DATA = uint8 (zeros(m*n, numIm)); % Memory allocated

clear str tmp;

% Creating DATA matrix

for i = 1 : numIm

im = imread ( [path char(listAll(i)) '.pgm'] );

DATA(:, i) = reshape (im, m*n, 1);

end;

save DATA DATA;

clear im;

% Creating training images space

fprintf('Creating training images space\n')

dim = length (trainList);

imSpace = zeros (m*n, dim);

for i = 1 : dim

index = strmatch (trainList(i), listAll);

imSpace(:, i) = DATA(:, index);

end;

save imSpace imSpace;

clear DATA;

% Calculating mean face from training images

fprintf('Zero mean\n')

psi = mean(double(imSpace'))';

save psi psi;

% Zero mean

zeroMeanSpace = zeros(size(imSpace));

for i = 1 : dim

zeroMeanSpace(:, i) = double(imSpace(:, i)) - psi;

end;

save zeroMeanSpace zeroMeanSpace;

clear imSpace;

% PCA

fprintf('PCA\n')

L = zeroMeanSpace' * zeroMeanSpace; % Turk-Pentland trick (part 1)

[eigVecs, eigVals] = eig(L);

diagonal = diag(eigVals);

[diagonal, index] = sort(diagonal);

index = flipud(index);

pcaEigVals = zeros(size(eigVals));

for i = 1 : size(eigVals, 1)

pcaEigVals(i, i) = eigVals(index(i), index(i));

pcaEigVecs(:, i) = eigVecs(:, index(i));

end;

pcaEigVals = diag(pcaEigVals);

pcaEigVals = pcaEigVals / (dim-1);

pcaEigVals = pcaEigVals(1 : subDim); % Retaining only the largest subDim ones

pcaEigVecs = zeroMeanSpace * pcaEigVecs; % Turk-Pentland trick (part 2)

save pcaEigVals pcaEigVals;

% Normalisation to unit length

fprintf('Normalising\n')

for i = 1 : dim

pcaEigVecs(:, i) = pcaEigVecs(:, i) / norm(pcaEigVecs(:, i));

end;

% Dimensionality reduction.

fprintf('Creating lower dimensional subspace\n')

w = pcaEigVecs(:, 1:subDim);

save w w;

clear w;

% Subtract mean face from all images

load DATA;

load psi;

zeroMeanDATA = zeros(size(DATA));

for i = 1 : size(DATA, 2)

zeroMeanDATA(:, i) = double(DATA(:, i)) - psi;

end;

clear psi;

clear DATA;

% Project all images onto a new lower dimensional subspace (w)

fprintf('Projecting all images onto a new lower dimensional subspace\n')

load w;

pcaProj = w' * zeroMeanDATA;

clear w;

clear zeroMeanDATA;

save pcaProj pcaProj;

matlabpca人脸识别代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、matlabpca人脸识别代码的信息别忘了在本站进行查找喔。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/14415.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载