Eigenfaces

Using SVD on a few thousand face photographs to rebuild each face from its first 100 eigenfaces.

2022 · CSCI 2033 Elementary Computational Linear Algebra, University of Minnesota · created with Nayan, Daniel and Cameron

George W. Bush, shown as the original, the reconstruction from 100 eigenfaces, and the difference between them.
George W. Bush, shown as the original, the reconstruction from 100 eigenfaces, and the difference between them.

A linear algebra course project that uses principal component analysis to represent faces. Every face in the dataset is flattened into a column vector. The eigenvectors of the sample covariance of the centered matrix are the eigenfaces, the principal components of "face". Each face then becomes a short linear combination of them. The work is in NumPy, in a Colab notebook. Reconstructing every face in the dataset from just its first 100 eigenfaces accounted for 99.4% of it on average, a mean-squared error of 0.6% against the original.

Media

Eigenfaces 0 through 1849. The leading components are recognisably faces. By the thousandth the image is indistinguishable from noise.
Eigenfaces 0 through 1849. The leading components are recognisably faces. By the thousandth the image is indistinguishable from noise.
The first sixteen eigenfaces, labelled in order.
The first sixteen eigenfaces, labelled in order.
The same progression without labels, with structure decaying into noise as the eigenvalue falls.
The same progression without labels, with structure decaying into noise as the eigenvalue falls.
A second grid of leading eigenfaces.
A second grid of leading eigenfaces.
A leading eigenface, carrying the broad lighting and shape of a face.
A leading eigenface, carrying the broad lighting and shape of a face.
Another of the leading components.
Another of the leading components.
A later eigenface, encoding finer detail at a much smaller eigenvalue.
A later eigenface, encoding finer detail at a much smaller eigenvalue.

Documents