资源描述:
《PCA人脸识别算法Matlab版》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、PCA人脸识别算法Matlab版2010-11-1819:301.数据准备functionT = CreateDatabase(TrainDatabasePath)% Alignasetoffaceimages(thetrainingsetT1,T2,...,TM)%% Description:Thisfunctionreshapesall2Dimagesofthetrainingdatabase% into1Dcolumnvectors.Then,itputsthese1Dcolumnvectorsinarowto % construct2Dmatrix 'T
2、'.% % % Argument: TrainDatabasePath - Pathofthetrainingdatabase%% Returns: T - A2Dmatrix,containingall1Dimagevectors.% SupposeallPimagesinthetrainingdatabase % havethesam
3、esizeofMxN.Sothelengthof1D % columnvectorsisMNand 'T' willbeaMNxP2Dmatrix.%% Seealso:STRCMP,STRCAT,RESHAPE% OriginalversionbyAmirHosseinOmidvarnia,October 2007% Email:aomidvar@ece.ut.ac.ir %%%%%%%%%%%%%%%%%%%
4、%%%%% FilemanagementTrainFiles = dir(TrainDatabasePath);Train_Number = 0;for i = 1:size(TrainFiles,1) if not(strcmp(TrainFiles(i).name,'.')
5、strcmp(TrainFiles(i).name,'..')
6、strcmp(TrainFiles(i).name,'Thumbs.db')) Train_Number = Train_Number + 1; % Numberofallimagesinthetrain
7、ingdatabase endend%%%%%%%%%%%%%%%%%%%%%%%% Constructionof2Dmatrixfrom1DimagevectorsT = [];for i = 1 :Train_Number % Ihavechosenthenameofeachimageindatabasesasacorresponding % number.However,itisnotmandatory! str = int2str(i); str = strcat('',str,'.jpg'); str =
8、strcat(TrainDatabasePath,str); img = imread(str); img = rgb2gray(img); [irowicol] = size(img); temp = reshape(img',irow*icol,1); %Reshaping2Dimagesinto1Dimagevectors T = [Ttemp]; % 'T' growsaftereachturn end2,样本训练function[m,A,Eigenfaces]
9、 = EigenfaceCore(T)% UsePrincipleComponentAnalysis(PCA)todeterminethemost % discriminatingfeaturesbetweenimagesoffaces.%% Description:Thisfunctiongetsa2Dmatrix,containingalltrainingimagevectors% andreturns 3 outputswhichareextractedfromtrainingdatabase.%% Argument: T
10、 -