• 大小: 917KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-16
  • 语言: Matlab
  • 标签: PCA  人脸识别  matlab  

资源简介

从网上的得到的资源,因此注释是英文的,不过,里面有我自己附加的代码解说,该matlab代码用的是PCA的方法进行人脸识别,里面举了两个实例来验证该代码,欢迎大家下来学习。

资源截图

代码片段和文件信息

function T = CreateDatabase(TrainDatabasePath)
% Align a set of face images (the training set T1 T2 ...  TM )
%
% Description: This function reshapes all 2D images of the training database
% into 1D column vectors. Then it puts these 1D column vectors in a row to 
% construct 2D matrix ‘T‘.
%  

% Argument:     TrainDatabasePath      - Path of the training database
%
% Returns:      T                      - A 2D matrix containing all 1D image vectors.
%                                        Suppose all P images in the training database 
%                                        have the same size of MxN. So the length of 1D 
%                                        column vectors is MN and ‘T‘ will be a MNxP 2D matrix.
%
% See also: STRCMP STRCAT RESHAPE

% Original version by Amir Hossein Omidvarnia October 2007
%                     Email: aomidvar@ece.ut.ac.ir                  

%%%%%%%%%%%%%%%%%%%%%%%% File management
TrainFiles = dir(TrainDatabasePath);
Train_Number = 0;

for i = 1:size(TrainFiles1)
    if not(strcmp(TrainFiles(i).name‘.‘)|strcmp(TrainFiles(i).name‘..‘)|strcmp(TrainFiles(i).name‘Thumbs.db‘))
        Train_Number = Train_Number + 1; % Number of all images in the training database
    end
end

%%%%%%%%%%%%%%%%%%%%%%%% Construction of 2D matrix from 1D image vectors
T = [];
for i = 1 : Train_Number
    
    % I have chosen the name of each image in databases as a corresponding
    % number. However it is not mandatory!
    str = int2str(i);
    str = strcat(‘\‘str‘.jpg‘);
    str = strcat(TrainDatabasePathstr);
    
    img = imread(str);
    img = rgb2gray(img);
    
    [irow icol] = size(img);
   
    temp = reshape(img‘irow*icol1);   % Reshaping 2D images into 1D image vectors
    T = [T temp]; % ‘T‘ grows after each turn                    
end

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-06-19 22:53  Face-Recognition-master\
     文件           6  2014-01-23 22:40  Face-Recognition-master\.gitignore
     文件        1818  2014-01-23 22:40  Face-Recognition-master\CreateDatabase.m
     文件        2871  2014-01-23 22:40  Face-Recognition-master\EigenfaceCore.m
     文件        1264  2014-01-23 22:40  Face-Recognition-master\example.m
     文件        1048  2014-01-23 22:40  Face-Recognition-master\Example2.m
     文件         495  2014-01-23 22:40  Face-Recognition-master\Readme.md
     文件        2480  2014-01-23 22:40  Face-Recognition-master\Recognition.m
     目录           0  2014-01-23 22:40  Face-Recognition-master\Test2\
     文件       91935  2014-01-23 22:40  Face-Recognition-master\Test2\1.jpg
     文件       81797  2014-01-23 22:40  Face-Recognition-master\Test2\2.jpg
     文件       92486  2014-01-23 22:40  Face-Recognition-master\Test2\3.jpg
     目录           0  2014-01-23 22:40  Face-Recognition-master\TestDatabase\
     文件        6264  2014-01-23 22:40  Face-Recognition-master\TestDatabase\1.jpg
     文件        6852  2014-01-23 22:40  Face-Recognition-master\TestDatabase\10.jpg
     文件        6007  2014-01-23 22:40  Face-Recognition-master\TestDatabase\2.jpg
     文件        5680  2014-01-23 22:40  Face-Recognition-master\TestDatabase\3.jpg
     文件        6525  2014-01-23 22:40  Face-Recognition-master\TestDatabase\4.jpg
     文件        4341  2014-01-23 22:40  Face-Recognition-master\TestDatabase\5.jpg
     文件        5876  2014-01-23 22:40  Face-Recognition-master\TestDatabase\6.jpg
     文件        4352  2014-01-23 22:40  Face-Recognition-master\TestDatabase\7.jpg
     文件        6725  2014-01-23 22:40  Face-Recognition-master\TestDatabase\8.jpg
     文件        5570  2014-01-23 22:40  Face-Recognition-master\TestDatabase\9.jpg
     目录           0  2014-01-23 22:40  Face-Recognition-master\Train2\
     文件       79071  2014-01-23 22:40  Face-Recognition-master\Train2\1.jpg
     文件       83336  2014-01-23 22:40  Face-Recognition-master\Train2\2.jpg
     文件       81973  2014-01-23 22:40  Face-Recognition-master\Train2\3.jpg
     文件       80704  2014-01-23 22:40  Face-Recognition-master\Train2\4.jpg
     文件       87354  2014-01-23 22:40  Face-Recognition-master\Train2\5.jpg
     文件       89958  2014-01-23 22:40  Face-Recognition-master\Train2\6.jpg
     目录           0  2014-01-23 22:40  Face-Recognition-master\TrainDatabase\
............此处省略21个文件信息

评论

共有 条评论