File Exchange

image thumbnail

PCA based face recognition

This code is PCA base face recognition programme.



View License

This code is PCA base face recognition programme. It reads nots(here 5) faces from ORL database and the rest (noc-nots) are used as test. PCA_Performance shows the recognition performance.

In order to be able to run this programme for ORL face database you need to download the face database. You can google it and it is for free.

This code has been written in Spring 2006 by me, Gholamreza Anbarjafari (Shahab). You can use this code for any research and academic purposes and you may refer to us in your acknowledgement!

Feel free to contact us for any further information:
{hasan.demirel, shahab.jafari}
(c) Demirel and Anbarjafari -2013

Comments and Ratings (26)


Xinhua (view profile)

it doesnt work


john (view profile)

the frame is helpful though the algorithm is a little uncomfortable.The accurary is 74% using the ORL database,which is low in some situation.How can we improve the accurary?

Amit Kumar

How to employ 2D PCA for face recognition? suggest some text to refer this problem


Hau (view profile)

Error using imread (line 350)
File "face4.bmp" does not exist.

Error in PCA_Face_Recognition (line 35)
Help me!


When i run this code, i am getting the following error????

??? Error using ==> iptcheckmap at 34
Function IND2GRAY expected its second input argument, MAP, to be a valid colormap.
Valid colormaps must be nonempty, double, 2-D matrices with 3 columns.

Error in ==> ind2gray>parse_inputs at 79
iptcheckmap(varargin{2}, mfilename, 'MAP', 2);

Error in ==> ind2gray at 23
[a,cm] = parse_inputs(varargin{:});

Error in ==> PCA_Face_Recognition at 17

No you do not need to have equal number of images in both test and training set. Then you should also do slight modification on the code. If you notice the first loop is for training and the second is for the testing.


1.Is it necessary to have equal no.of images both in testing and training dataset.

2.Where do we give the test image to recognize?


yu sam

yu sam (view profile)


Nikola (view profile)

Very helpful

Xu Wings


Good work

This is a great work too

Robin Torres

Xing Yu

alain boyer

V. Poor


Ziba (view profile)

Thank you


Ali (view profile)

Hal 9000

poorly written


Kemal (view profile)

Loop-heavy script by a Matlab novice, adding to a mountain of PCA face-recognition code samples already on FEX.

Xu Wings

See the comment for the LDA code, good work.


A link has been removed.

a YouTube link is provided

The link for ORL face database has been removed and now new information about it has been provided.


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

MATLAB Online Live Editor Challenge

Win cash prizes and have your live script featured on our website

Learn more

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

» Watch video