Math for CS and ML · 15 min

SVD: a picture as a sum of simple pieces

Rebuild pictures one rank-1 piece at a time, and see why a few pieces carry most of an image but none of the noise.

Builds onEigenvectors

01Why it matters

How few numbers does a picture need?

A 24 × 24 grayscale picture is 576 numbers. But most pictures aren't random: neighbouring rows look alike, and whole regions share the same pattern. The singular value decomposition (SVD) finds that shared structure and lists it from most to least important, so you can keep the important part and throw the rest away.

The same idea compresses images, removes noise, powers recommender systems and is the engine inside PCA.

02Key parts

The pieces you will see

rank-1 piece
A column pattern uu times a row pattern v⊤v^\top: every row of the piece is the same row pattern, scaled. It takes m+nm + n numbers instead of m⋅nm \cdot n.
singular value σ
How strongly a piece counts. The SVD sorts them: σ1≥σ2≥⋯≥0\sigma_1 \ge \sigma_2 \ge \dots \ge 0.
rank
How many pieces have σ>0\sigma > 0: the number of pieces that rebuild the matrix exactly.
energy
The share of ∑σi2\sum \sigma_i^2 that the pieces kept so far account for.

03See it work

Rebuild a face one piece at a time

Each step adds the next piece σ·u·vᵀ. Blue in the piece adds brightness, orange takes it away.

Every matrix AA can be written as

A=σ1u1v1⊤+σ2u2v2⊤+…A = \sigma_1 u_1 v_1^\top + \sigma_2 u_2 v_2^\top + \dots

with the uu's perpendicular to each other, the vv's too, and the σ\sigma's in decreasing order. The first piece alone already has about 80% of the smiley's energy; by the fifth the face is clearly there. Each piece costs 24+24+1=4924 + 24 + 1 = 49 numbers, so five pieces are 245 numbers instead of 576.

Some pictures are simple enough to have only a couple of pieces at all:

A checkerboard is an even gray plus one ± pattern: rank 2, however many squares it has.

There is also a geometric reading, the one the eigenvectors lesson prepares you for. Written as A=UΣV⊤A = U \Sigma V^\top, any matrix acts in three moves: V⊤V^\top rotates (or reflects) the space, Σ\Sigma stretches it along the axes by the singular values, and UU rotates it again. A circle always lands on an ellipse whose half-axes are the σ\sigma's.

04Predict

Your turn: how many pieces does a letter need?

Make 5 predictions: step forward and answer each question before the next step plays.

0 of 5 made

05Try it

Compare pictures

Switch between the pictures and watch the bar chart of singular values:

  • Plus sign and gradient: two pieces and the picture is exact. One σ\sigma is huge and the other tiny.
  • Smiley and letter A: curves and diagonals need more pieces, but the σ\sigma's still fall fast.
  • Random noise: the σ\sigma's fall slowly, so ten pieces still look like mush. Noise has no shared structure to find.

06Check yourself

Check yourself

  1. Question 1 of 5

    How many numbers does one rank-1 piece σ·u·vᵀ of a 24 × 24 picture take to store?

    Your answer comes back in Review in a few days, so it sticks.

  2. Question 2 of 5

    A white picture with one full-width black stripe across it. What is its rank?

  3. Question 3 of 5

    You keep the first k pieces. What is the squared error ‖A − Aₖ‖²?

  4. Question 4 of 5

    Why does random noise compress so badly?

  5. Question 5 of 5

    A 24 × 24 picture is stored as its first 3 SVD pieces. What exactly is stored?

07Explain it back

Say it in your own words

How does the SVD compress a picture, and why does keeping the pieces with the largest singular values work so well?

08Recap

What to remember

  • Any matrix is a sum of rank-1 pieces σiuivi⊤\sigma_i u_i v_i^\top, sorted by singular value.
  • The first kk pieces are the best rank-kk approximation; the error is the dropped σ\sigma's.
  • Fast-falling σ\sigma's mean structure you can compress; flat ones mean noise.
  • Geometrically, every matrix rotates, stretches along axes, and rotates again.
Back to path