LINEAR-ALGEBRA Β· Interactive Practice | Unit 30 Β· Video 2

Why Your Photos Are 95% Lies: The Linear Algebra Behind JPEG

IKey Ideas Reference

Concept Expression Meaning
Change of basis x=c1b1+c2b2+β‹―+cnbn\mathbf{x} = c_1 \mathbf{b}_1 + c_2 \mathbf{b}_2 + \cdots + c_n \mathbf{b}_n Rewrite the same vector in a new vocabulary
Coefficient ck=bkβ‹…xc_k = \mathbf{b}_k \cdot \mathbf{x} (orthonormal case) How much of pattern bk\mathbf{b}_k appears in x\mathbf{x}
Thresholding Keep ckc_k if ∣ck∣β‰₯Ο„\lvert c_k \rvert \geq \tau, else set to 00 The lossy step β€” information disappears here
Compression ratio numbersΒ storedΒ originallycoefficientsΒ kept\dfrac{\text{numbers stored originally}}{\text{coefficients kept}} e.g. 64/3β‰ˆ21:164/3 \approx 21{:}1

IIVisualization 1 β€” A Basis Localized in Space

Each Haar basis vector watches a different slice of the signal β€” some the whole thing, some just two neighboring pixels.

πŸ’‘ Unlike a Fourier sine wave, which stretches across the whole signal, most Haar vectors are zero almost everywhere β€” that locality is what lets one coefficient pin down an edge.

IIIVisualization 2 β€” Throwing Coefficients Away

A smooth signal hides in a few large coefficients β€” keep those, zero the rest, and barely notice.

πŸ’‘ Natural image blocks are smooth, so their energy piles into a few low-frequency coefficients β€” that sparsity, not the basis by itself, is what makes JPEG work.

IVVisualization 3 β€” Fourier vs. Wavelets

Smooth signals are sparse in Fourier; sharp edges are sparse in wavelets β€” sparsity depends on the basis.

πŸ’‘ This is why JPEG 2000 and the FBI's fingerprint format (WSQ) use wavelets: a fingerprint is all edges, and edges are sparse in Haar, not Fourier.

VQuiz Questions

Question 1

In the JPEG pipeline, an 8Γ—8 pixel block (64 numbers) is rewritten using the Fourier basis to get 64 coefficients c1,c2,…,c64c_1, c_2, \ldots, c_{64}.

At this step β€” before any thresholding β€” has any information been lost?

βœ… Correct! Change of basis just renames the same vector in a new vocabulary.

❌ Not quite. Don't confuse the change of basis step with the thresholding step. Only thresholding loses information.

Show solution

Solution:

A change of basis just rewrites the same vector using different "vocabulary" β€” it does not throw anything away. If x\mathbf{x} is the original pixel vector and c\mathbf{c} is the Fourier-coefficient vector, then we can always recover

x=c1b1+c2b2+β‹―+c64b64.\mathbf{x} = c_1 \mathbf{b}_1 + c_2 \mathbf{b}_2 + \cdots + c_{64} \mathbf{b}_{64}.

The lossy step in JPEG is thresholding (Act 2), where small coefficients are set to zero. The change-of-basis step itself (Act 1) is perfectly reversible.

Question 2

Suppose an 8Γ—8 block (64 numbers) is compressed by keeping only 4 of its 64 Fourier coefficients. What is the compression ratio?

βœ… Correct! 64/4=1664 / 4 = 16, so the compression ratio is 16:1.

❌ Not quite. Compression ratio = (original numbers) / (stored numbers).

Show solution

Solution:

Compression ratio compares the original number of values to the stored number of values:

ratio=originalkept=644=16.\text{ratio} = \frac{\text{original}}{\text{kept}} = \frac{64}{4} = 16.

So we get 16:1 compression. The reconstruction still produces all 64 pixel values, but we only had to store 4 numbers to get there.

  • ❌ 4:1 β€” that's just the number of coefficients kept, not the ratio.
  • ❌ 60:1 β€” that's the number discarded, not the ratio.
  • ❌ 64:1 β€” that would require keeping only 1 coefficient.

Question 3

You need to compress an image containing sharp fingerprint ridges (lots of edges and fine-scale local features). The FBI famously chose a wavelet-based standard for this task rather than JPEG's Fourier-based one.

Why are wavelets a better fit than Fourier here?

βœ… Correct! Localization in space is the wavelet's superpower for edges.

❌ Not quite. The key word is localization β€” wavelets know where features are, not just how wavy they are.

Show solution

Solution:

Fourier basis vectors stretch across the entire interval. A sharp edge β€” a single sudden jump β€” cannot be captured by any one Fourier vector, so the edge "spreads out" across many high-frequency coefficients. That kills sparsity, and sparsity is what makes compression work.

Haar wavelets, by contrast, are localized in both space and frequency. A jump at position 4 mostly lights up the wavelet that sits at position 4 β€” a few coefficients, not many.

This is exactly why the FBI's fingerprint compression standard (WSQ) shrinks each fingerprint by roughly 15:1 while preserving identifying ridge detail, and why JPEG 2000 also uses wavelets.

  • ❌ "Store more information per coefficient" β€” coefficients are just real numbers in either basis.
  • ❌ "Wavelets are lossless" β€” wavelet compression still thresholds, which is lossy.
  • ❌ "Fourier coefficients don't exist" β€” they exist, there are just too many significant ones for an edge.

Question 4

True or False: The Fourier basis and the Haar wavelet basis in R8\mathbb{R}^8 span different subspaces of R8\mathbb{R}^8 β€” that is, there are vectors expressible in one basis that cannot be expressed in the other.

βœ… Correct! Both are bases of the same space R8\mathbb{R}^8 β€” they just describe vectors using different vocabularies.

❌ Not quite. Recall the video: the Fourier checkerboard equals a sum of four Haar wavelets. Every vector in R8\mathbb{R}^8 can be expressed in either basis.

Show solution

Solution:

False. Any basis of R8\mathbb{R}^8 spans all of R8\mathbb{R}^8 β€” that's literally what "basis" means. The Fourier basis and the Haar wavelet basis describe the same space, just in different vocabularies.

The video made this explicit by writing the Fourier checkerboard vector as a sum of four Haar wavelets:

(1,βˆ’1,1,βˆ’1,1,βˆ’1,1,βˆ’1)=(1,βˆ’1,0,0,0,0,0,0)+(0,0,1,βˆ’1,0,0,0,0)+(0,0,0,0,1,βˆ’1,0,0)+(0,0,0,0,0,0,1,βˆ’1).(1, -1, 1, -1, 1, -1, 1, -1) = (1, -1, 0, 0, 0, 0, 0, 0) + (0, 0, 1, -1, 0, 0, 0, 0) + (0, 0, 0, 0, 1, -1, 0, 0) + (0, 0, 0, 0, 0, 0, 1, -1).

Every vector expressible in one basis is expressible in the other. What differs is which vectors are sparse (have few nonzero coefficients):

  • Smooth signals are sparse in Fourier.
  • Sharp / localized signals are sparse in Haar.

Same space, different strengths.

Solved: 0 / 4