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

Your Photo Is a Vector: Why JPEG Throws Away the Pixel Grid

IKey Formulas

Formula Name Description
Image=c1v1+c2v2+β‹―+cNvN\text{Image} = c_1\mathbf{v}_1 + c_2\mathbf{v}_2 + \dots + c_N\mathbf{v}_N Basis expansion Any image is a weighted sum of basis vectors
ci=vi⊀xc_i = \mathbf{v}_i^\top \mathbf{x} Coefficient (orthonormal basis) Projection of image x\mathbf{x} onto basis vector vi\mathbf{v}_i
x∈RHβ‹…W\mathbf{x} \in \mathbb{R}^{H \cdot W} Image as vector HΓ—WH \times W grayscale image flattened into a single column
x^=βˆ‘i∈Scivi\hat{\mathbf{x}} = \sum_{i \in S} c_i \mathbf{v}_i Lossy reconstruction Keep only large coefficients SS, discard the rest

IIVisualization 1 β€” An Image Is a Vector

Unroll a grayscale grid row by row and the picture becomes one point β€” a vector in R16\mathbb{R}^{16}.

πŸ’‘ The same idea scales: a 512Γ—512512 \times 512 photo is a single point in R262,144\mathbb{R}^{262{,}144}.

IIIVisualization 2 β€” Basis Vectors Can Be Pictures

Each basis vector is itself an 8Γ—88 \times 8 image β€” from a single spike to a uniform field to a fast oscillation.

πŸ’‘ JPEG's basis is cosine waves at rising frequencies (the Discrete Cosine Transform); modern codecs use wavelets β€” choosing the basis is the whole game.

IVVisualization 3 β€” Compression by Discarding Coefficients

Keep only the largest few of 64 frequency coefficients and the reconstruction barely changes.

πŸ’‘ It works because real images are mostly smooth: they project heavily onto the low-frequency basis vectors and barely onto the high-frequency ones.

VQuiz Questions

Question 1

A grayscale photograph has resolution 512Γ—512512 \times 512. As a single vector, in which space does it live?

βœ… Correct! Every pixel contributes one coordinate.

❌ Not quite. The dimension equals the total number of pixels, not the width or height alone.

Show solution

Solution:

To turn an image into a vector, we stack all the pixel values into one long column. For a 512Γ—512512 \times 512 grayscale image, that's 512Γ—512=262,144512 \times 512 = 262{,}144 pixel values, so the image is a single point in R262,144\mathbb{R}^{262{,}144}.

(A color image would triple this, since each pixel has R, G, and B channels.)

Question 2

You photograph a perfectly uniform dark gray blackboard. Compare two bases:

  • Pixel basis {e1,…,eN}\{\mathbf{e}_1, \dots, \mathbf{e}_N\}
  • Structured basis that includes the all-ones vector 1=(1,1,…,1)\mathbf{1} = (1,1,\dots,1)

In which basis does the image have a shorter description (fewer non-zero coefficients)?

βœ… Correct! A uniform image is a scalar multiple of the all-ones vector, so almost every coefficient is zero.

❌ Not quite. Having every coefficient equal is not the same as having most coefficients zero. We want shortness, not uniformity.

Show solution

Solution:

In the pixel basis, every coefficient is the gray value gg. That's 262,144 equal, non-zero numbers β€” no short description.

In a structured basis that contains the all-ones vector 1\mathbf{1}, the uniform image is simply blackboard=gβ‹…1+0β‹…v2+0β‹…v3+…\text{blackboard} = g \cdot \mathbf{1} + 0 \cdot \mathbf{v}_2 + 0 \cdot \mathbf{v}_3 + \dots Almost all coefficients are zero. The whole image is captured by a single number gg.

Same vector, same information β€” just a much shorter description.

Question 3

True or False: When JPEG performs lossy compression, it removes information at random to make the file smaller.

βœ… Correct! Lossy compression is a precise, structured discard of high-frequency coefficients β€” not random damage.

❌ Not quite. The whole point of compression-by-change-of-basis is that the discard is targeted.

Show solution

Solution: False.

JPEG does not discard information randomly. It changes basis (using the Discrete Cosine Transform) so that the image is expressed as a sum of low- to high-frequency components. The coefficients on high-frequency basis vectors are then aggressively quantized or zeroed out.

This is principled, not random:

  • Real photographs are mostly smooth, so high-frequency coefficients are already small.
  • The human visual system is much less sensitive to high-frequency detail than to large-scale structure.

So JPEG selectively discards the parts our eyes barely notice β€” that's why a 10Γ— compressed photo can still look fine.

Question 4

Modern video codecs encode the difference between consecutive frames, rather than each frame on its own. What does this strategy have in common with JPEG?

βœ… Correct! That's the deep idea: compression is choosing coordinates.

❌ Not quite. JPEG is lossy, and the DCT is spatial, not temporal. Look for the general principle the two share.

Show solution

Solution:

The unifying principle is: change coordinates until most numbers are zero.

  • JPEG changes the spatial basis (pixels β†’ cosine waves). Smooth images become sparse in the new basis.
  • Video codecs change the temporal basis (current frame β†’ current frame minus predicted frame). Since consecutive frames are highly correlated, the difference image is mostly black β€” a nearly-zero vector that's cheap to store.

Different axis, same philosophy: the right basis turns hard problems into trivial ones.

Solved: 0 / 4