Part II — Linear Algebra & Matrix Decompositions · Chapter 10

Image compression & latent extraction via SVD/PCA

Hook

An image is just a matrix of numbers. Everything this part has built — eigenvalues, PSD-ness, low-rank truncation — was leading here: compress a real image by keeping only its matrix's biggest singular values, and watch the picture reappear almost perfectly from a fraction of the numbers.

Intuition
3.03.01.01.03.03.01.01.01.01.03.03.01.01.03.03.0
original image
0.00.00.00.00.00.00.00.00.00.00.00.00.00.00.00.0
rank-0 reconstruction

reconstruction error = 8.944 (energy retained: 0%)

A 4x4 toy "image," reconstructed from 0, 1, or 2 of its singular components. Rank 0 is blank; rank 1 is already a recognizable (if blurred) sketch; rank 2 is the original back exactly.

Formalize

Every image matrix II (real or toy) has a singular value decomposition, and its best rank-kk reconstruction is the same truncated-SVD formula from the previous chapter:

Ik=i=1kσiuiviI_k = \sum_{i=1}^{k} \sigma_i u_i v_i^\top
  • II — the image, treated as a plain matrix of pixel intensities.
  • σi,ui,vi\sigma_i, u_i, v_i — the ii-th singular value and left/right singular vectors of II.
  • IkI_k — the rank-kk compressed reconstruction of the image.
  1. What compression actually means here

    Storing IkI_k only requires kk singular values plus kk vectors of each length — for a large image, kk singular components can cost far fewer numbers than the raw pixel grid.

  2. Where 'eigenfaces' comes from

    Applied to a collection of face images stacked into one matrix, the same uiu_i patterns become eigenfaces: reusable visual building blocks that any face in the set can be approximated from.

  3. The tradeoff is exact, not fuzzy

    Exactly as in the previous chapter, IIkF=i>kσi2\|I - I_k\|_F = \sqrt{\sum_{i>k}\sigma_i^2} — you can compute precisely how much reconstruction error a given compression ratio costs, before storing anything.

Play

Pattern 1 (uniform across every row) alone captures 80% of the image's total energy — a single rank-1 term already does most of the work.

Worked example

The toy image is built from two clean row-patterns: u1=(0.5,0.5,0.5,0.5)u_1=(0.5,0.5,0.5,0.5) with σ1=8\sigma_1=8, and u2=(0.5,0.5,0.5,0.5)u_2=(0.5,0.5,-0.5,-0.5) with σ2=4\sigma_2=4 (each pattern used as both its own left and right singular vector, since the image is symmetric):

  1. Rank-1 reconstruction

    I1=8u1u1I_1 = 8 \cdot u_1u_1^\top: every entry of u1u1u_1u_1^\top is 0.5×0.5=0.250.5\times0.5=0.25, so I1I_1 is a flat image with every pixel equal to 8×0.25=28\times0.25=2.

  2. The error, by direct subtraction

    Reconstruct II itself, since it was never written down: I=σ1u1u1+σ2u2u2I = \sigma_1u_1u_1^\top+\sigma_2u_2u_2^\top.

    1. The second term has entries 4×(±0.5)(±0.5)=±14\times(\pm0.5)(\pm0.5)=\pm1 — positive where u2u_2's two entries share a sign, negative where they don't:

      σ2u2u2=4(0.250.250.250.250.250.250.250.250.250.250.250.250.250.250.250.25)=(1111111111111111)\sigma_2u_2u_2^\top = 4\begin{pmatrix}0.25&0.25&-0.25&-0.25\\0.25&0.25&-0.25&-0.25\\-0.25&-0.25&0.25&0.25\\-0.25&-0.25&0.25&0.25\end{pmatrix} = \begin{pmatrix}1&1&-1&-1\\1&1&-1&-1\\-1&-1&1&1\\-1&-1&1&1\end{pmatrix}
    2. Adding that to I1I_1's flat 22s gives II — a matrix of 11s and 33s, each exactly 11 away from I1I_1's 22:

      I=(3311331111331133)I = \begin{pmatrix}3&3&1&1\\3&3&1&1\\1&1&3&3\\1&1&3&3\end{pmatrix}

    So II1I - I_1 is exactly the ±1\pm1 matrix from step 1, in all 16 cells, and II1F=16×12=4\|I-I_1\|_F=\sqrt{16\times1^2}=4.

  3. Confirm it matches Eckart-Young

    The formula predicts II1F=σ22=σ2=4\|I-I_1\|_F=\sqrt{\sigma_2^2}=\sigma_2=4 — exactly what direct subtraction gave. Energy retained: 82/(82+42)=64/80=80%8^2/(8^2+4^2)=64/80=80\%.

Checkpoint

Click the smallest rank whose reconstruction error drops below 4.5 (compute each rank's error by hand from the singular values 8 and 4).

Pick a rank to try it
Summary
Ik=i=1kσiuiviIIkF=i>kσi2I_k = \sum_{i=1}^{k} \sigma_i u_i v_i^\top \qquad \|I-I_k\|_F = \sqrt{\sum_{i>k}\sigma_i^2}

Image compression, latent feature extraction, and eigenfaces are the same operation wearing different names: truncate a matrix's SVD and keep only the directions carrying the most energy. This closes out Part II — every idea here (projections, determinants, eigenvalues, PSD-ness, low-rank truncation) was building toward this single, reusable move, which reappears throughout the rest of this course wherever a large matrix needs to be summarized by a small one.