File Exchange

image thumbnail

PCA-based Face Recognition System

version 1.0 (180 KB) by

This package implements 'Eigenface', a PCA-based face recognition system.



View License

This package implements a well-known PCA-based face recognition method, which is called 'Eigenface'.
All functions are easy to use, as they are heavy commented. Furthermore, a sample script and two small training and test databases are included to show their usage.

Comments and Ratings (63)

Sujay Patole

@kishore when you use your own database ,your images should be of same resolution. use reshape command to make them of same resolution

Worked in a go! Thank You.

mani sharma

Thanx a lot ,, its really helpful

Amir Sir,Is there any limitations for the input.?When am giving my own database few errors r encountered
Error using horzcat
Dimensions of matrices being concatenated are not consistent.

Error in CreateDatabase (line 47)
T = [T temp]; % 'T' grows after each turn

Error in example (line 26)
T = CreateDatabase(TrainDatabasePath);
Please reply.
Thanks in advance

great work ..thank you

Ban gocrieng


your work is great.thanks a lot Amir

jeba shanthi

vu hung


noo no

noo no (view profile)

how calculate accuracy for this code


Carine (view profile)

Hello, this code does not give right results if the training database contains the image that we choose for testing. If the image chosen for testing is a face that already exists in training database but a different image of the face, it's not giving the correct results, anyone having same problem?

Shubhankar De

i want to use hsv in pca...i extracted HSV feature from my data base..but want to then use pca ..any one know the procedure..if anyone have idea with this mail me..

@nadeer ataya ...even after chnaging am getting the same error

Hello, can u suggest how can I change dimension of all my 320x240 images to 200x180 images? It is urgent for me.

nadeer ataya

@poongothai rajan
changed images to .jpj


i also got the same error..the solution is this will work for same dimension images..i changed all my images in the data base with same dimension eg(200*180);
then i got the output..try it best wises


Jackie (view profile)


suman (view profile)

this code is not working for my own database i am getting error as
Error using ==> horzcat
CAT arguments dimensions are not consistent.

Error in ==> CreateDatabase at 47
T = [T temp]; % 'T' grows after each turn

Error in ==> example at 26
T = CreateDatabase(TrainDatabasePath); how to clear this errors... any one help me to clear this error


Pooja (view profile)

The code is good but it doesnt work if d same person has his/her face tilted.I eanted a code for that. But good job though!!

pakarat dung

thank youuuu

Jack Claudiu

Vipin Kamble

Great Work .. !!!!

Nehal Patel

great your code it is not show eigenvalue is just recognize face with train image.can you tell me how to show eigenvalue?


Can the anyone tell me why the Eigenfaces is 36000*19 instead of 36000*20?

Jai Gupta

@shruti, were u able to connect webcam and compare pictures taken by it with your database. i want to do the same, if anyone else can also help?


Shruti (view profile)

great work!! i have created my own traindatabase , but if i eliminate test database and try to take the test image via webcam and store it directly into a matlab variable and then run the program , it is not recognising my image but rather match some other face in the traindatabase.. i have resized test image appropriately and no errors are found when i run the code.. just face recognition fails... please suggest if i need to make any changes in the code or any other measures need to be taken into account while image capture through webcam like lighting. or any specific background needed.. please reply and help me ..

Thanks for the nice work. Try to add 2D PCA implementation.

Caelyn Low


debasish (view profile)


debasish (view profile)

great work indeed!!very neatly computed!...I will be very happy if you can suggest how we can reject non-face images by calculating the Euclidean distance of the mean/centered test image from the face space??(Re:"Pentland and Turk:Eigenfaces for Recognition)

Shamir Alavi

I've run the code several times using my own face database and it seems its trying to recognize on the basis of same file names in both training and test folders !!! I changed the file names several times to check this theory and as suspected, the recognition came out to be wrong. Only once it truly recognized the same face having different file names. Most of the times, it was just matching both 1.jpg files regardless of whose picture i put there.


I noticed that you don't sort the eigenvectors at all. All you did was keeping the eigenvalues that are greater than 1 and their associated eigenvectors.
Can you tell me why please.

Kyle Lee

Can the author or anyone tell me why the Eigenfaces is 36000*19 instead of 36000*20? Why the D[1 1] would be negative value that causes the dimemsion to be 19?

Partha Bera


kumar reddy




nice work.... very thanks.. when i am trying to import another photos but it shows
??? Error using ==> horzcat
CAT arguments dimensions are not consistent.

Error in ==> CreateDatabase at 47
T = [T temp]; % 'T' grows after each turn

Error in ==> example at 26
T = CreateDatabase(TrainDatabasePath); how to clear this errors... any one help me to clear this error..........

Liam Mescall

Impressive - thanks for the help

its really a great job...


A really excellent piece of work. Thank You.
How to make this program reject unknon faces(those faces which are not in train database)?

dwi arliani

how to get the original eigenvalue (without eliminating eigenvalue under threshold)?because it cause error when i run Recognition.m.
it says "minus
Matrix dimensions must agree." because i realize that eigenfaces result is 19x20.. but the testing image is 20x20..
thx for your help :)

Like all the other comments well done. Simple and to the point

Muhamad nasri

good, but I found a little problem, when running EigenfaceCore.m, says "??? Input Argument 'T' is undefined", how to solved this problem ?? please to help me

This is a really great work sir... But can I know how we can train this system to identify new faces.

Ganesh AS

Hello, taking 19 of 20 eigen values is no feature extraction :D


raja (view profile)

great work sir...i can understand it easily as it is commented well..thanks


Alex (view profile)

Code is well commented and it works well, however, the images used for training are the same that are used for testing. No wonder it works!

manzoor lone

i am very very very happy with with the pca based face recognition

daba Dabarera

Thank you very much!

Nick Yeow

i am trying to use eigenface method in my project (face recognition via web cam).
but when i try import other picture into training & test image then run it. But error message pop-up
:"All matrices on a row in the bracketed expression must have the
same number of rows"
Any ideals to solve it?
thanks..very appreciate


Hanaa (view profile)


How do you detect facial features using template matching?

I'll be very grateful for your help. Thanks! :)


sara (view profile)

good job ,thank you

very very thankful..but i need a program that detect a fece so i can interface it with the face recognition program..God bless

hba osman

Abdullah Janazerah

you r great man

lili chen

lili chen

Very good

maggie King


abc xyz

simple, nicely implemented, commented extremely well

Qureshi i

Good job done

karl karlos


MATLAB Release
MATLAB 7.2 (R2006a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video