Facial Recognition
Eigenfaces: Turning Face Recognition into Projection onto a Low-Dimensional Basis
Recognising a face looks like a problem about images. The eigenface method turns it into a problem about vectors in a high-dimensional space, and once that translation is made, the entire solution is linear algebra you already know: subtract a mean, find an orthonormal basis that captures most of the variation, project, and compare.
Step 1: images become vectors
Read a grayscale image row by row and stack the pixel values into a single column. An image with h rows and w columns becomes a vector in Rd with d=hw. A modest 100×100 image already gives d=10,000. Two images are close in this space when their pixel values agree closely, position by position.
Collect M training images as the columns of a d×M matrix. Because d is enormous and M is usually small by comparison, the data occupy a very thin sliver of Rd: almost no vector in that space looks anything like a face.
Step 2: subtract the mean face
Compute the average vector ψ=M1∑ixi, the mean face, and form the mean-centred vectors φi=xi−ψ.
This step is not cosmetic. Every face image shares an enormous common component, a bright oval on a darker background, eyes roughly here, mouth roughly there.
If you skip the centring, the analysis measures second moments about the origin rather than variation about the average, and its largest direction can be dominated by that common offset.
For registered face images, where the shared component carries most of the energy, this is the usual outcome, and such a direction tells you little about which face you are looking at.
It is not guaranteed for every data set, since strong enough variation in another direction could come first. Covariance is defined about the mean precisely so that the analysed directions describe variation between faces, whatever the data.
The centred vectors also carry a built-in linear dependence: by construction
so they always sum to the zero vector, whatever the images were. Any one of them is therefore determined by the others.
Step 3: principal components, computed the practical way
Let A be the d×M matrix whose columns are the φi. The covariance matrix is C=M1AAT, of size d×d. For d=10,000 that is 108 entries, which is impractical to diagonalise directly.
The standard trick uses the much smaller M×M matrix ATA. If ATAv=λv with λ>0, then Av=0 and AAT(Av)=λ(Av), so the non-zero eigensystem maps to image space. Zero-eigenvalue vectors for which Av=0 do not produce eigenvectors and are discarded.
Solve the small problem, map the eigenvectors across, normalise them, and you have the principal components without ever forming C. Note the rank bound this rests on: rank(A)≤min(d,M), so when M≪d only a small number of directions can carry any variance at all.
The resulting orthonormal vectors u1,u2,…, ordered by decreasing eigenvalue, are the eigenfaces. Each is a vector in Rd, so each can be folded back into an h×w array and displayed; they look like ghostly face-shaped patterns because they are directions of variation, not faces.
Step 4: project
Keep the top k eigenfaces and represent any face by its coordinates in that basis:
A face that lived in R10,000 is now a short list of k numbers. Because the uj are orthonormal, the reconstruction is x^=ψ+∑jωjuj, and Pythagoras gives the squared reconstruction error directly as ∥x−ψ∥2−∑jωj2.
Worked example
Take three images in a four-pixel space: x1=(9,7,3,1), x2=(3,1,9,7), x3=(6,4,6,4). The mean face is
Centring gives φ1=(3,3,−3,−3), φ2=(−3,−3,3,3) and φ3=(0,0,0,0), which do indeed sum to zero. All three lie along a single direction, so take the unit vector u=21(1,1,−1,−1) and project:
Reconstructing the first image: ψ+6u=(6,4,6,4)+(3,3,−3,−3)=(9,7,3,1)=x1 exactly. Here a single number per image replaces four, with no loss at all, because the centred data happen to occupy a one-dimensional subspace. Real face data are not one-dimensional, but they are far lower-dimensional than the pixel count, and that gap is what the method exploits.
Step 5: match
Store a weight vector for each enrolled person. To identify a probe image, centre it, project it, and find the nearest stored weight vector in Euclidean distance. Two checks add information beyond that ranking.
- Distance in weight space. How far is the probe from the nearest enrolled person? If it exceeds a calibrated threshold, the system may reject it as a poor match to the enrolled gallery; this does not establish that the probe is a face.
- Distance from face space. How large is the reconstruction residual ∥(x−ψ)−∑jωjuj∥? A photograph of a chair projects to some weight vector, which may land close to an enrolled person by accident. A large residual indicates that the input is poorly represented by the retained face space; it may be a non-face or a face affected by pose, lighting, or other variation. A residual threshold calibrated on suitable data may support rejection, but a residual neither proves that the input is a non-face nor catches every non-face: a non-face can lie in the retained subspace.
Omitting the second check removes a useful measure of fit to the retained face space. Neither the nearest-person distance nor the residual alone establishes identity or whether the image depicts a face.
What the method does not solve
Because the representation works on raw pixel values, it is sensitive to anything that changes those values globally. Illumination, head pose, scale and alignment all shift a face substantially in Rd, often by more than the difference between two different people under matched conditions.
Registration and photometric normalisation are commonly used to reduce sensitivity to alignment and illumination, depending on capture conditions. A small Euclidean distance between weight vectors is evidence about image similarity rather than proof of identity.
Before computing principal components, the eigenface pipeline subtracts the mean face ψ=M1∑ixi from every training image.
Why is this step necessary?
A training set contains M=200 grayscale face images, each 60×50 pixels. The images are vectorised, the mean face is subtracted, and the covariance matrix C=M1AAT of the mean-centred data is formed, where A is the d×M matrix of centred vectors.
At most how many non-zero eigenvalues can C have?