The main purpose behind writing this tutorial was to provide a more detailed set of instructions for someone who is trying to implement an eigenface based face detection or recognition systems. It is assumed that the reader is familiar (at least to some extent) with the eigenface technique as described in the original M. Turk and A. Pentland papers (see “References” for more details).
Introduction
The idea behind eigenfaces is similar (to a certain extent) to the one behind the periodic signal representation as a sum of simple oscillating functions in a Fourier decomposition. The technique described in this tutorial, as well as in the original papers, also aims to represent a face as a linear composition of the base images (called the eigenfaces).
The recognition/detection process consists of initialization, during which the eigenface basis is established and face classification, during which a new image is projected onto the “face space” and the resulting image is categorized by the weight patterns as a known-face, an unknown-face or a non-face image.
Demonstration
To download the software shown in video for 32-bit x86 platform, click here. It was compiled using Microsoft Visual C++ 2008 and uses GSL for Windows.
Establishing the Eigenface Basis
First of all, we have to obtain a training set of
grayscale face images
. They should be:
- face-wise aligned, with eyes in the same level and faces of the same scale,
- normalized so that every pixel has a value between 0 and 255 (i.e. one byte per pixel encoding), and
- of the same
size.
So just capturing everything formally, we want to obtain a set:
, where
and 
Once we have that, we should change the representation of a face image
from a
matrix, to a
point in
-dimensional space. Now here is how we do it: we concatenate all the rows of the matrix
into one big vector of dimension
. Can it get any more simpler than that?
This is how it looks formally:
, where
and 
Since we are much more interested in the characteristic features of those faces, let’s subtract everything what is common between them, i.e. the average face.
The average face of the previous mean-adjusted images can be defined as
, then each face differs from the average by the vector
.
Now we should attempt to find a set of orthonormal vectors which best describe the distribution of our data. The necessary steps in this at a first glance daunting task would seem to be:
- Obtain a covariance matrix
, where
. - Find the eigenvectors
and eigenvalues
of
.
However, note two things here:
is of the size
and hence the matrix
is of the size
. To put things into perspective – if your image size is
, then the size of the matrix
would be
. Determining eigenvectors and eigenvalues for a matrix this size would be an absolutely intractable task!
So how do we go about it? A simple mathematical trick: first let’s calculate the inner product matrix
, of the size
. Then let’s find it’s eigenvectors
of
(of the
-th dimension). Now observe, that if
, then
,and hence
and
are respectively the
eigenvectors (of
-th dimension) and eigenvalues of
. Make sure to normalize
, such that
.
We will call these eigenvectors
the eigenfaces. Scale them to 255 and render on the screen, to see why.
It turns out that quite a few eigenfaces with the smallest eigenvalues can be discarded, so leave only the
ones with the largest eigenvalues (i.e. only the ones making the greatest contribution to the variance of the original image set) and chuck them into the matrix ![U = \left[ u_1 u_2 ... u_R \right]_{N \times R}](http://blog.zabarauskas.com/wp-content/cache/tex_1f1a76aa21ad1b9ba4e2bf48d2879611.png)
After you have done that – congratulations! We won’t need anything else, but the matrix
for the next steps – face detection and classification.
Face Classification Using Eigenfaces
Once the eigenfaces are created, a new face image
can be transformed into it’s eigenface components by a simple operation:
.The weights
describe the contribution of each eigenface in representing the input face image. We can use this vector for face recognition by finding the smallest Euclidean distance
between the input face and training faces weight vectors, i.e. by calculating
. If
, where
is a treshold chosen heuristically, then we can say that the input image is recognized as the image with which it gives the lowest score.
The weights vector can also be used for an unknown face detection, exploiting the fact that the images of faces do not change radically when projected into the face space, while the projection of non-face images appear quite different. To do so, we can calculate the distance
from the mean-adjusted input image
and its projection onto face space
, i.e.
. Again, if
for some treshold
(also obtained heuristically, for example, by observing
for an input set consisting only of face images and a set of non-face images) we can conclude that the input image is a face.
References
1. Face Recognition Using Eigenfaces, Matthew A. Turk and Alex P. Pentland, MIT Vision and Modeling Lab, CVPR ‘91.
2. Eigenfaces for Recognition, Matthew A. Turk and Alex P. Pentland, Journal of Cognitive Neuroscience ‘91.
3. Eigenfaces. Sheng Zhang and Matthew Turk (2008), Scholarpedia, 3(9):4244.

#1 by Alex on January 1st, 2010
Hi,
just thought i’d say that you’ve done a great tutorial (from what i understand of it lol). i was just wondering if i could take a look at your source code or if you have a sample project for me to better understaind eigenfaces as my algebra isn’t too great :p
Thanks,
Alex
#2 by Martyns Papartyns on January 3rd, 2010
Čia tai geras ^^ Čia laisvalaikiu ar su mokslu susiję ?
#3 by Midorj on January 12th, 2010
Great, thank so much. Your tutorial helps me a lot. very much appreciate!!
#4 by Manfredas Zabarauskas on January 12th, 2010
Thanks, Alex!
Apologies, but the source code is not available at the moment… On the other hand – it’s literally following the maths described in this tutorial, so if you’re worried about implementing these algebraic operations – you might want to look at GSL (GNU Scientific Library, you can find a pretty good documentation for it online). Also, to get a better grip on the method behind eigenfaces itself, I suggest you to read a bit about PCA (Principal Component Analysis), there are quite a few tutorials online on the subject.
#5 by Manfredas Zabarauskas on January 12th, 2010
Laisvalaikiu, tėvai… Deja… :-}
#6 by Manfredas Zabarauskas on January 12th, 2010
Thanks, Midorj, glad to hear that!