Lab 17 Interactive: Image Compression

Explore how a digital image becomes a matrix, how SVD breaks it into ordered layers, and how rank controls the tradeoff between quality, storage, and information loss.

1. The central idea

A grayscale image is a matrix. SVD writes it as a sum of rank-one visual layers:

A = σ₁u₁v₁ᵀ + σ₂u₂v₂ᵀ + ⋯

Compression keeps only the first k layers:

Ak = σ₁u₁v₁ᵀ + ⋯ + σkukvk
The first layers often capture broad structure. Later layers add details, texture, and sometimes noise.

2. Rank-k image compression simulator

This uses a precomputed low-rank-style synthetic construction in the browser. It demonstrates the same rank-layer idea as SVD compression.

Storage ratio:

Approximate energy captured:

Visual lesson:

Reflection: At what value of k does the main structure appear? At what value do smaller details appear?

3. Singular values: fast decay versus slow decay

If singular values decay quickly, a small rank can capture most of the image. If they decay slowly, information is spread across many layers.

Rank needed for 90% energy:

Rank needed for 99% energy:

Smooth images usually have faster decay than random or highly textured images.

4. Compression versus denoising

Small k removes noise but may oversmooth. Large k restores detail but may restore noise too.

5. Storage calculator

Full storage: numbers

SVD storage: numbers

Storage fraction:

Compression worthwhile?

SVD storage = k(m+n+1)

6. Final learning questions

SVDrankenergycompressiondenoising

  1. Why does the first singular layer often look like a broad shadow of the image?
  2. Why can a smaller k denoise an image but also remove fine detail?
  3. Why is a random image hard to compress with low-rank SVD?
  4. How does this chapter prepare for PCA?