The main idea behind eigenfaces is that we want to learn a low-dimensional space - known as the eigenface subspace - on which we assume the faces intrinsically lie. From there, we can then compare faces within this low-dimensional space in order to perform facial recognition. It’s a relatively simple approach to facial recognition, but indeed one of the most famous and effective ones of the early approaches. It still works well in simple, controlled scenarios.

Assume we have a set of images , where ; ; and is the spatial dimension of the image. The first step to the algorithm is to resize all the images in the set to the same size. Typically, the images are converted to grayscale, since it is assumed that colour is not an important factor. This is clearly debatable, however, for the purposes of this post we will assume that the images are grayscale images.

Each image is then converted to a vector, by appending each row into one long vector. Given an image from the set, we convert it to a vector .

We then calculate the mean face :

We then zero-centre the image vectors by subtracting the mean from each. This results in a set of vectors :

We then perform PCA on the matrix , where is given by:

More concretely, we compute the covariance matrix :

We would then typically compute the eigen decomposition of this matrix. However, in the interest of speed, the eigen decomposition is instead computed for . This is mathematically justified since the eigenvalues of (along with their associated eigenvectors) correspond to the largest eigenvalues of (along with their associated eigenvectors).

We then retain the first principal components: the eigenvectors with largest associated absolute eigenvalues. This corresponds to a matrix , where the columns of the matrix are these chosen eigenvectors. We then compute the so-called projection matrix :

Lastly, we can finally find the eigenface subspace :

Now, for the actual facial recognition part! Consider a resized grayscale test image . We reshape this into a vector:

We then mean-normalise:

Finally, we project the test face onto the eigenface subspace (i.e. the linear manifold learned by PCA):

Given this projected face, we can find which face it is closest to in the eigenface subspace, and classify it as that that person’s face:

where is the face in the eigenface subspace. It is clear that this is using Euclidean distance, as this is the metric used in the classical eigenface algorithm. We can, however, instead opt for distance or any other distance metric.