File Exchange

image thumbnail

Face recognition using PCA

version (2.81 KB) by Baba Dash
Principal Component Analysis for Face Recognition


Updated 04 Mar 2014

View License

This program recognizes a face from a database of human faces using PCA. The principal components are projected onto the eigenspace to find the eigenfaces and an unknown face is recognized from the minimum euclidean distance of projection onto all the face classes.

Cite As

Baba Dash (2019). Face recognition using PCA (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (52)

thank you;
but when we will calculate the accuracy recognition of this method what we can do???

saad albawi

Its Ok

jin li

your coding is very helpful to do face recognition, but if someone need to reconstruct the image by eigenface. the formula to calculate weights should be correct. I spend 2 days to read paper, most of them did not use the right formula to calculate the weights. Here is the formula
W=inverse(eigenface Transpose * eigenface)* eigenface Transpose * (image matrix- image mean)
while eigenface=(image matrix- image mean)*eigenvector
if each image is N*N, the number of training images is M , then image matrix is N^2 *M
if we choose first K eigenvectors, so the eigenface will be N^2 *K
the weight (W) is K*K

how will this work?


Nga Wai

I also used this method and I want to know, how I can solve the persons who are not in the database. Please tell me, how to calculate the threshold value for solving unknown face. Thank You!

How to create a databath


when test image is in database then it shows the equivalent image, if the test image is not in database then it shows another person image as Equivalent image
why it is not showing any error (or) return something as "image not found in database"
someone please us.

hello; the databse used in this code its: yalefaces database

udit jain

can i know which database has been used

i am getting error on this -temp = reshape(img',r*c,1); it says to use Permute instead of img' , but after modification it again gives error

@Baba Dash ... Sir, Can you help me about feature extraction using PCA? and what this code can be used in iris feature extraction?

I want to test grayscale image what to do. please help me.

There is an error in line 104 and 121..U have to project all M face images on eigen space(not the first K faces). Hence size(A,2) would be the appropriate.

aya elnahas

where is the dataset to use for this project ?

can anyone help me out in how to execute this code? did it really work?

we need code for face recognition using hog feature

did any one help me out to like how to write a code for group face detection and recognize a face

5ererweer hfuu ffyf uyryfg


kiet tran


android boy

can someone teach me how to run this program? I am confuse specially in the facerecog.m code which indicates Thumbs.db, do i need to create directory?


Thank you very much for your contribution.

would i ask, First i have many template that different size. can i use PCA with various size of templates?. The second question is, my template have smaller size than source image, can i use PCA to detect a small part in my source image? Thank you very much sir.

M. Farez

is there a tutorial for this?

Dear sir. Can you show me how to launch this project in MATLAB, i've used ver 2009. Please give me the video tutorial .
MY skype : vn680260

sir thanks for code and please help me how to set datapath and test image in the pca matlad codes

salman khan

dear sir,
i need some help about your code. i am new in matlab.

Ankit Pal

sir i need some help with your code . will you please help me..
m beginner in matlab.

Ankit Pal

sir thanku for code and plz help me a little with codes m new with matlab.


how to change euclidean into mahalanobis? because i want use mahalanobis, not euclidean

Hello pls help it's giving me an error of inner matrix dimension must agree

Hello pls I need your getting this error of inner matrix dimensions must confused pls help

i think this is a mistak
for i = 1 : size(A,2) insted
for i = 1 : size(eigenfaces,2)
%%%%%%% finding the projection of each image vector on the facespace (where the eigenfaces are the co-ordinates or dimensions) %%%%%

projectimg = [ ]; % projected image vector matrix
for i = 1 : size(eigenfaces,2)
temp = eigenfaces' * A(:,i);
projectimg = [projectimg temp];

%%%%% extractiing PCA features of the test image %%%%%

u should project all face traninig set in egenFaces ur loop stop just into eigenfaces Size not A traning Set face matrix.

Very cool!
At uni we are talking about this program. Is there any particular dataset I can use for it?



thiyo ps

good job

Hafiz Umar


I will be really grateful if you can instruct me how to use your file.

Ganesh Raut


pca nice


you've been great helpful



Nam Nam

MATLAB Release Compatibility
Created with R2008a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: EOF