人脸识别课程设计附带代码(4)

2019-04-09 10:49

%Recognition

function OutputName = Recognition(TestImage, m, A, Eigenfaces) % Recognizing step.... %

% Description: This function compares two faces by projecting the images into facespace and

% measuring the Euclidean distance between them. %

% Argument: TestImage - Path of the input test image

%

% m - (M*Nx1) Mean of the training

% database, which is output of 'EigenfaceCore' function.

%

% Eigenfaces - (M*Nx(P-1)) Eigen vectors of the

% covariance matrix of the training

% database, which is output of 'EigenfaceCore' function.

%

% A - (M*NxP) Matrix of centered image

% vectors, which is output of 'EigenfaceCore' function.

%

% Returns: OutputName - Name of the recognized image in the training database.

%

% See also: RESHAPE, STRCAT

% Original version by Amir Hossein Omidvarnia, October 2007

% Email: aomidvar@ece.ut.ac.ir

%%%%%%%%%%%%%%%%%%%%%%%% Projecting centered image vectors into facespace

% All centered images are projected into facespace by multiplying in

% Eigenface basis's. Projected vector of each face will be its corresponding

% feature vector.

ProjectedImages = [];

Train_Number = size(Eigenfaces,2); for i = 1 : Train_Number

temp = Eigenfaces'*A(:,i); % Projection of centered images into facespace

ProjectedImages = [ProjectedImages temp]; end

%%%%%%%%%%%%%%%%%%%%%%%% Extracting the PCA features from test image

InputImage = imread(TestImage); temp = InputImage(:,:,1);

[irow icol] = size(temp);

InImage = reshape(temp',irow*icol,1);

Difference = double(InImage)-m; % Centered test image

ProjectedTestImage = Eigenfaces'*Difference; % Test image feature vector

%%%%%%%%%%%%%%%%%%%%%%%% Calculating Euclidean distances % Euclidean distances between the projected test image and the projection

% of all centered training images are calculated. Test image is % supposed to have minimum distance with its corresponding image in the

% training database.

Euc_dist = [];

for i = 1 : Train_Number q = ProjectedImages(:,i);

temp = ( norm( ProjectedTestImage - q ) )^2; Euc_dist = [Euc_dist temp]; end

[Euc_dist_min , Recognized_index] = min(Euc_dist); OutputName = strcat(int2str(Recognized_index),'.jpg');


人脸识别课程设计附带代码(4).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:18.中国知识产权保护的新进展

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: