欢迎来到天天文库
浏览记录
ID:10982797
大小:156.50 KB
页数:18页
时间:2018-07-09
《基于pca人脸识算法代码》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、一种基于图象分析的柜员机-人脸识别算法的研究代码1.EigenfaceCode.m:function[m,A,Eigenfaces]=EigenfaceCore(T)%UsePrincipleComponentAnalysis(PCA)todeterminethemost%discriminatingfeaturesbetweenimagesoffaces.%%Description:Thisfunctiongetsa2Dmatrix,containingalltrainingimagevectors%andreturns3
2、outputswhichareextractedfromtrainingdatabase.%%Argument:T-A2Dmatrix,containingall1Dimagevectors.%SupposeallPimagesinthetrainingdatabase%havethesamesizeofMxN.Sothelengthof1D%columnvectorsisM*Nand'T'willbeaMNxP2Dmatrix.%%Returns:m-(M*Nx1)Meanofthetrainingdatabase%Eig
3、enfaces-(M*Nx(P-1))Eigenvectorsofthecovariancematrixofthetrainingdatabase%A-(M*NxP)Matrixofcenteredimagevectors%%Seealso:EIG%OriginalversionbyAmirHosseinOmidvarnia,October2007%Email:aomidvar@ece.ut.ac.ir%%%%%%%%%%%%%%%%%%%%%%%%Calculatingthemeanimagem=mean(T,2);%Co
4、mputingtheaveragefaceimagem=(1/P)*sum(Tj's)(j=1:P)Train_Number=size(T,2);18%%%%%%%%%%%%%%%%%%%%%%%%CalculatingthedeviationofeachimagefrommeanimageA=[];fori=1:Train_Numbertemp=double(T(:,i))-m;%ComputingthedifferenceimageforeachimageinthetrainingsetAi=Ti-mA=[Atemp];
5、%Mergingallcenteredimagesend%%%%%%%%%%%%%%%%%%%%%%%%SnapshotmethodofEigenfacemethos%WeknowfromlinearalgebratheorythatforaPxQmatrix,themaximum%numberofnon-zeroeigenvaluesthatthematrixcanhaveismin(P-1,Q-1).%Sincethenumberoftrainingimages(P)isusuallylessthanthenumber%
6、ofpixels(M*N),themostnon-zeroeigenvaluesthatcanbefoundareequal%toP-1.SowecancalculateeigenvaluesofA'*A(aPxPmatrix)insteadof%A*A'(aM*NxM*Nmatrix).ItisclearthatthedimensionsofA*A'ismuch%largerthatA'*A.Sothedimensionalitywilldecrease.L=A'*A;%Listhesurrogateofcovarianc
7、ematrixC=A*A'.[VD]=eig(L);%DiagonalelementsofDaretheeigenvaluesforbothL=A'*AandC=A*A'.%%%%%%%%%%%%%%%%%%%%%%%%Sortingandeliminatingeigenvalues%AlleigenvaluesofmatrixLaresortedandthosewhoarelessthana%specifiedthreshold,areeliminated.Sothenumberofnon-zero%eigenvector
8、smaybelessthan(P-1).L_eig_vec=[];fori=1:size(V,2)if(D(i,i)>1)L_eig_vec=[L_eig_vecV(:,i)];end18end%%%%%%%%%%%%%%%%%%%%%%%%Calculatingtheeigenvecto
此文档下载收益归作者所有