Eigenfaces was introduced in the paper in 1991, as a face recognition method based on PCA.
I suggest reading about PCA first if you are not familiar with the idea. 😉 A good practice is to implement your version of PCA first, see my attempt here.
This is an implementation of Eigenfaces in Matlab. I will show the reconstruction of some faces with eigenvectors.
- Download the FaceScrub dataset and convert them into grayscale if they are not already
- Reshape the [m x n] images matrix into [(m x n) x 1] images vector. Here, I choose the dimension to be 100 * 100 just so my laptop doesn't burn itself
- Calculate the mean face, which is the most average face produced from all the face data we feed the program
- Get eigenvectors and eigenvalues with the
svdfunction in Matlab - Display the first 10 eigenvectors, which are some of the most prominent features
- The fun part - reconstruct face with the covariance matrix! Here I used eigenvectors with an interval of 20 to slowly build the mean face up to the original image
Reconstructing face of a cat 🐱

You can see with more eigenvectors, the reconstruction seems increasingly closer to reality. However, just by the first row (top 100 eigenvectors), we already have a good estimation of what does this cat look like, which is kinda awesome because we just reduced the dimension from 100 * 100 to 100 vectors space without losing much information.
Also, see the transformation from the mean face to 🐈 in gif

If you are interested in seeing more results, there's reconstructing faces of Scarlett Johansson and myself 🦄 in results/, or just try it out!
- FaceScrub Dataset
- Downloaded the data set with this Python script
- A good blog explaning Eigenfaces face recognition

