BetaFree coursewareRewritten from MIT OpenCourseWareCC BY-NC-SA 4.0
Open CosmologyPhysics & cosmology, from high school to a graduate year

Change of basis and image compression

Image compression is a change of basis. A 512 × 512 gray-scale image is a vector x in Rⁿ with n = 512², each pixel a value from 0 to 255 (8 bits). The standard basis, one pixel at a time, ignores that neighbouring pixels are nearly equal; a better basis contains the all-ones vector, which alone carries a blank board, and vectors like (1, −1, 1, −1, …) or half ones and half minus ones. JPEG cuts the image into 8 × 8 blocks of 64 pixels and changes each block to the Fourier basis: a lossless step x → c. The lossy step throws away coefficients below a threshold, keeping ĉ with many zeros, perhaps 3 of 64, a compression of about 21 to 1. Video also uses the correlation between successive frames (prediction and correction). Wavelets compete with Fourier: the 8 Haar wavelets are the all-ones vector, four ones and four minus ones, two-by-two blocks and pairs (1, −1); the checkerboard vector is the sum of the last four. Changing basis means solving P = Wc, so c = W⁻¹P. A good basis must be fast (FFT; wavelet columns orthogonal, so W⁻¹ is Wᵀ after normalising) and must compress well (a few basis vectors close to the signal). The same transformation has matrix A in one basis and B in another, and they are similar, B = M⁻¹AM, with M the change-of-basis matrix. Column j of A holds the coefficients of T(vⱼ); in an eigenvector basis T(vⱼ) = λⱼvⱼ and A = Λ, the perfect but too expensive basis.

You need this first

Full reading path (32 pages)
  1. Vectors (8.01)
  2. Vectors and the dot product (18.02)
  3. Determinants and the cross product (18.02)
  4. Planes through three points, and matrices (18.02)
  5. Equations of planes and square systems (18.02)
  6. The geometry of linear equations (18.06)
  7. Elimination with matrices (18.06)
  8. Matrix multiplication and inverse matrices (18.06)
  9. Factorization into A = LU (18.06)
  10. Transposes, permutations and vector spaces (18.06)
  11. Properties of determinants (18.06)
  12. Determinant formulas and cofactors (18.06)
  13. Cramer's rule, the inverse matrix and volume (18.06)
  14. Column space and nullspace (18.06)
  15. Eigenvalues and eigenvectors (18.06)
  16. Diagonalisation and powers of A (18.06)
  17. Solving Ax = 0: pivot variables and special solutions (18.06)
  18. Solving Ax = b: the complete solution (18.06)
  19. Independence, basis and dimension (18.06)
  20. The four fundamental subspaces (18.06)
  21. Orthogonal vectors and subspaces (18.06)
  22. Projections onto subspaces (18.06)
  23. Projection matrices and least squares (18.06)
  24. Symmetric matrices and positive definiteness (18.06)
  25. Singular value decomposition (18.06)
  26. Linear transformations and their matrices (18.06)
  27. Differential equations and exp(At) (18.06)
  28. Orthogonal matrices and Gram–Schmidt (18.06)
  29. Markov matrices and Fourier series (18.06)
  30. Complex matrices and the fast Fourier transform (18.06)
  31. Positive definite matrices and minima (18.06)
  32. Similar matrices and the Jordan form (18.06)
On this page · 6 sections
  1. An image is a long vector
  2. A better basis than the pixels
  3. JPEG: Fourier basis, then thresholding
  4. Wavelets
  5. Same transformation, different bases
  6. Summary

Near the end of the course, this lecture mixes the linear algebra of a change of basis with an application where changing basis is exactly what is done: compressing signals and images (transcript, p. 1). Then it returns to the chapter's theme, the link between a linear transformation and its matrix in given coordinates (p. 1). Strang notes that these very lectures reach viewers compressed, and that his motion looks jerky because moving needs many bits while the board does not (pp. 1–2).

An image is a long vector#

Satellites, climate and combustion computations and sensors of every kind produce overwhelming amounts of data (p. 2). Some compression is lossless, using redundancy; the subject here is lossy compression (p. 2). A gray-scale image is made of pixels, perhaps 512×512=29×29512 \times 512 = 2^9 \times 2^9, each a gray level from 0 to 255, which is 282^8 values: 8 bits (p. 2). So the image is a vector (pp. 2–3)

An image as a vector
x∈Rn,n=5122x \in \mathbf{R}^n, \qquad n = 512^2
In words

x is in capital R to the power n, n equals 512 squared

three times as long for colour. It cannot be sent without compression (p. 3).

A better basis than the pixels#

The current basis is the standard basis: one pixel at a time (p. 3). Neighbouring pixels have nearly equal values, the blue of a shirt, the board, and these strong correlations make compression possible (p. 3). For a blank board, listing every pixel makes no sense: the standard basis is "lousy" there (p. 4). Better basis vectors (pp. 4–5):

  • the vector of all ones, which alone carries a solid image;
  • the checkerboard (1,−1,1,−1,… )(1, -1, 1, -1, \dots), which alone carries a checkerboard image;
  • half ones and half minus ones, for an image darker on one side.

We are free to choose the basis, and which one is "a billion-dollar decision" (p. 5).

JPEG: Fourier basis, then thresholding#

JPEG (the Joint Photographic Experts Group standard) uses, in Strang's words, the Fourier basis, starting with the all-ones vector (the DC vector, to electrical engineers); he points back to the Fourier matrix without going into details (pp. 3, 5). (Strictly, JPEG uses the discrete cosine transform, a real basis of cosines from the Fourier family.) It cuts the image into 8×88 \times 8 blocks and changes basis in each block, in 64-dimensional space (pp. 5–6). Two steps (pp. 6–7):

Compression in two steps
x  →  c  →  c^(first change of basis, lossless; then thresholding, lossy)x \;\to\; c \;\to\; \hat c \qquad (\text{first change of basis, lossless; then thresholding, lossy})
In words

x goes to c goes to c hat ( first change of basis, lossless; then thresholding, lossy )

The first step is lossless: 64 pixels in, 64 coefficients out (p. 6). The second, thresholding, sets to zero every coefficient below a threshold chosen so the eye can hardly see the difference (p. 7). The coefficient of the all-ones vector is usually large and kept; the high-frequency checkerboard is barely present in a smooth image (p. 7). The image is rebuilt from the few remaining terms, each coefficient times its basis vector wiw_i (p. 7):

Reconstruction
x^=∑kept ic^i wi\hat x = \sum_{\text{kept } i} \hat c_i\,w_i
In words

x hat equals the sum over kept i of c sub i hat w sub i

With 3 of 64 terms left, the compression is about 21 to 1 (p. 7). Strang adds two stories, as of 1999. The FBI digitised its fingerprint files and compresses them, so that a match takes minutes instead of a week (p. 8). And video is a sequence of highly correlated images: one predicts the next frame from the last and codes only the small correction (pp. 8–9).

Wavelets#

The competition for Fourier is wavelets (p. 9). The simplest set in R8\mathbf{R}^8 (pp. 9–10):

Haar wavelet basis of R⁸
(1,1,1,1,1,1,1,1),(1,1,1,1,−1,−1,−1,−1),(1,1,−1,−1,0,0,0,0),(0,0,0,0,1,1,−1,−1),(1,−1,0,0,0,0,0,0) and the same pair (1,−1) moved to positions 3–4, 5–6, 7–8\begin{aligned} &(1, 1, 1, 1, 1, 1, 1, 1), \quad (1, 1, 1, 1, -1, -1, -1, -1), \\ &(1, 1, -1, -1, 0, 0, 0, 0), \quad (0, 0, 0, 0, 1, 1, -1, -1), \\ &(1, -1, 0, 0, 0, 0, 0, 0) \text{ and the same pair } (1, -1) \text{ moved to positions } 3\text{–}4,\ 5\text{–}6,\ 7\text{–}8 \end{aligned}
In words

(1, 1, 1, 1, 1, 1, 1, 1), (1, 1, 1, 1, minus 1, minus 1, minus 1, minus 1); (1, 1, minus 1, minus 1, 0, 0, 0, 0), (0, 0, 0, 0, 1, 1, minus 1, minus 1); (1, minus 1, 0, 0, 0, 0, 0, 0) and the same pair (1, minus 1) moved to positions 3 to 4, 5 to 6, 7 to 8

The fast checkerboard vector of the Fourier basis is the sum of the last four wavelets (p. 10). The linear algebra is the transform step: given pixel values P=(P1,…,P8)P = (P_1, \dots, P_8) along a row, find c1,…,c8c_1, \dots, c_8 with (pp. 10–12)

Transform step
P=c1w1+⋯+c8w8=Wc,c=W−1PP = c_1w_1 + \cdots + c_8w_8 = Wc, \qquad c = W^{-1}P
In words

capital P equals c one w one plus and so on plus c eight w eight equals capital W c, c equals capital W to the power minus 1 capital P

where the columns of the wavelet matrix WW are the basis vectors (p. 11).

What makes a basis good (pp. 12–14). First, it must be fast: multiplying by WW and by W−1W^{-1} quickly. The Fourier basis has the FFT, and wavelets have a fast wavelet transform (p. 12). The Haar wavelets use only ones, minus ones and zeros, and they are orthogonal: for example, the first two have dot product 4−4=04 - 4 = 0 (p. 13). Divided by their lengths (8\sqrt8, 4\sqrt4, 2\sqrt2), they are orthonormal and W−1=WTW^{-1} = W^T (pp. 13–14). Second, it must compress well: a few basis vectors must come close to the signal. The fastest choice, no change at all, fails this: dropping 90% of the pixel values leaves a dark picture, while dropping c5,…,c8c_5, \dots, c_8 in the wavelet basis removes only small blips (p. 14). In this lecture, recorded in 1999 (the 18.06 videos on OCW date from then), Strang says that JPEG 2000, then the coming standard, would include wavelets, and that the FBI uses smoother wavelets than these jumpy ones (p. 15).

Same transformation, different bases#

With the new basis vectors in the columns of WW, a vector with old coordinates xx has new coordinates cc (p. 15):

Change of coordinates
x=Wcx = Wc
In words

x equals capital W c

Now take a linear transformation TT of eight-dimensional space, a rotation say (p. 16). In a first basis v1,…,v8v_1, \dots, v_8 it has matrix AA; in a second basis w1,…,w8w_1, \dots, w_8 it has matrix BB. The answer, which Strang admits this compressed part of the lecture jumps to, is that they are similar (p. 17):

Matrices in two bases
B=M−1AMB = M^{-1}AM
In words

B equals capital M to the power minus 1 capital A capital M

with MM the change-of-basis matrix, the WW above (pp. 17–18). Changing the basis gives every vector new coordinates and every transformation a new matrix (pp. 17–18).

Recap of the matrix (pp. 18–19). TT is known once T(v1),…,T(v8)T(v_1), \dots, T(v_8) are known, because every xx is c1v1+⋯+c8v8c_1v_1 + \cdots + c_8v_8 and T(x)=c1T(v1)+⋯+c8T(v8)T(x) = c_1T(v_1) + \cdots + c_8T(v_8) (pp. 18–19). Write each output in the basis; the coefficients fill the columns of AA, 64 numbers in all (p. 19):

Columns of A
T(v1)=a11v1+a21v2+⋯+a81v8,T(v2)=a12v1+a22v2+⋯+a82v8T(v_1) = a_{11}v_1 + a_{21}v_2 + \cdots + a_{81}v_8, \qquad T(v_2) = a_{12}v_1 + a_{22}v_2 + \cdots + a_{82}v_8
In words

capital T ( v one ) equals a one one v one plus a two one v two plus and so on plus a eight one v eight, capital T ( v two ) equals a one two v one plus a two two v two plus and so on plus a eight two v eight

(Strang says "a11a_{11} down to a18a_{18}" for the first column and "a21a_{21} down to a28a_{28}" for the next; the first column runs from a11a_{11} to a81a_{81}, the second from a12a_{12} to a82a_{82}.)

The best basis (pp. 19–20). If the basis vectors are eigenvectors, T(vi)=λiviT(v_i) = \lambda_iv_i: the first output is already λ1\lambda_1 times the first basis vector, so the first column is λ1\lambda_1 and zeros, and so on (p. 20):

Eigenvector basis
T(vi)=λivi⇒A=ΛT(v_i) = \lambda_iv_i \quad\Rightarrow\quad A = \Lambda
In words

capital T ( v sub i ) equals lambda i v sub i which gives capital A equals capital lambda

That would be the perfect basis for image processing too, but finding the eigenvectors of the pixel data would be too expensive, so a cheaper good basis, wavelets or Fourier, is used instead (p. 20).

Worked example

Four pixels in a wavelet basis

(a) Use the four Haar wavelets w1=(1,1,1,1)w_1 = (1, 1, 1, 1), w2=(1,1,−1,−1)w_2 = (1, 1, -1, -1), w3=(1,−1,0,0)w_3 = (1, -1, 0, 0), w4=(0,0,1,−1)w_4 = (0, 0, 1, -1) to transform the pixel row P=(7,5,2,2)P = (7, 5, 2, 2), then keep only the two largest coefficients. (b) The projection onto the 45°45° line has matrix A=(1000)A = \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix} in the basis (1,1)/2(1, 1)/\sqrt2, (1,−1)/2(1, -1)/\sqrt2 (here the eigenvector basis plays the role of the first basis). Find its matrix in the standard basis by a change of basis.

(a) Coefficients

The wavelets are orthogonal, so ci=wiTP/wiTwic_i = w_i^TP/w_i^Tw_i: c1=16/4=4c_1 = 16/4 = 4, c2=(12−4)/4=2c_2 = (12 - 4)/4 = 2, c3=(7−5)/2=1c_3 = (7 - 5)/2 = 1, c4=(2−2)/2=0c_4 = (2 - 2)/2 = 0. Check: 4w1+2w2+w3=(4+2+1, 4+2−1, 4−2, 4−2)=(7,5,2,2)4w_1 + 2w_2 + w_3 = (4 + 2 + 1,\ 4 + 2 - 1,\ 4 - 2,\ 4 - 2) = (7, 5, 2, 2).

(a) Compression

Keep c1=4c_1 = 4 and c2=2c_2 = 2: P^=4w1+2w2=(6,6,2,2)\hat P = 4w_1 + 2w_2 = (6, 6, 2, 2). Two numbers instead of four (and c4c_4 was zero anyway); the error (1,−1,0,0)(1, -1, 0, 0) is exactly c3w3c_3w_3, the one wavelet dropped.

(b) Change of basis

Put the new basis in M=12(111−1)M = \frac{1}{\sqrt2}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}, orthogonal and symmetric, so M−1=MM^{-1} = M. The standard-basis matrix is MAM−1=12(111−1)(1000)(111−1)=12(1111)MAM^{-1} = \frac12\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}\begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} = \frac12\begin{pmatrix} 1 & 1 \\ 1 & 1 \end{pmatrix}, the familiar projection matrix of the last lecture: similar to AA, as promised.

Summary#

Symbols on this page

Show the 46 symbols used here
λ\lambda lambda.
An eigenvalue of A. Say it: “lambda”.
Λ\Lambda capital lambda.
The diagonal matrix of the eigenvalues. Say it: “capital lambda”.
∈\in element of.
Is an element of (belongs to) a set. Say it: “is in”.
→\to arrow.
Goes to (tends to), or becomes. Say it: “goes to”.
⇒\Rightarrow implies.
Implies: what follows is a consequence of what came before. Say it: “which gives”.
×\times times.
Times (multiplication). Between two vectors: the cross product. Say it: “times”.
∑\sum sum.
Sum: add up the terms over the range written below and above. Say it: “the sum of”.
ı^\hat\imath hat.
A unit vector: a vector of length 1 that only gives a direction (î, r̂). Say it: “hat”.
cc c.
The vector of coefficients of the signal in the new basis. Say it: “c”.
TT T.
A linear transformation of eight-dimensional space. Say it: “capital T”.
xx x.
An image (or a block of it) as a vector of pixel values, in the standard basis. Say it: “x”.
nn n.
The number of pixels, the length of x (512² for a 512 × 512 image). Say it: “n”.
PP P.
A row of pixel values (P₁, …, P₈), the signal to transform. Say it: “capital P”.
AA A.
The matrix of the transformation T in the first basis; in the worked example, the projection in its eigenvector basis. Say it: “capital A”.
BB B.
The matrix of the same transformation in the second basis. Say it: “B”.
MM M.
The change-of-basis matrix in B = M⁻¹AM. Say it: “capital M”.
viv_{i} initial velocity.
The i-th vector of the first basis (an eigenvector, in the best case). Say it: “v sub i”.
WW W.
The wavelet matrix: the basis vectors in its columns; more generally the change-of-basis matrix. Say it: “capital W”.
v1v_{1} v one.
The first vector of the first basis. Say it: “v one”.
v2v_{2} v two.
The second vector of the first basis. Say it: “v two”.
c1c_{1} c one.
The coefficient of the first basis vector (all ones). Say it: “c one”.
c2c_{2} c two.
The coefficient of the second basis vector. Say it: “c two”.
cic_{i} c i.
The coefficient of the i-th new basis vector. Say it: “c sub i”.
c3c_{3} c 3.
The coefficient of the third basis vector. Say it: “c three”.
P1P_{1} P 1.
The first pixel value. Say it: “capital P one”.
λ1\lambda_{1} lambda one.
The first eigenvalue. Say it: “lambda one”.
λi\lambda_{i} lambda i.
Any one of the eigenvalues. Say it: “lambda i”.
a11a_{11} a one one.
The entry in row 1, column 1 of A: the coefficient of v₁ in T(v₁). Say it: “a one one”.
a22a_{22} a two two.
The entry in row 2, column 2 of A. Say it: “a two two”.
a12a_{12} a one two.
The entry in row 1, column 2 of A: the coefficient of v₁ in T(v₂). Say it: “a one two”.
a21a_{21} a two one.
The entry in row 2, column 1 of A: the coefficient of v₂ in T(v₁). Say it: “a two one”.
w1w_{1} w one.
The first wavelet: all ones. Say it: “w one”.
w2w_{2} w two.
The second wavelet: half ones, half minus ones. Say it: “w two”.
P8P_{8} P eight.
The eighth pixel value. Say it: “capital P eight”.
wiw_{i} w i.
The i-th basis vector (Fourier or wavelet). Say it: “w sub i”.
w3w_{3} w three.
The third wavelet. Say it: “w three”.
w4w_{4} w four.
The fourth wavelet. Say it: “w four”.
w8w_{8} w eight.
The eighth wavelet. Say it: “w eight”.
c4c_{4} c four.
The coefficient of the fourth basis vector. Say it: “c four”.
c5c_{5} c five.
The coefficient of the fifth basis vector. Say it: “c five”.
c8c_{8} c eight.
The coefficient of the eighth basis vector. Say it: “c eight”.
v8v_{8} v eight.
The eighth vector of the first basis. Say it: “v eight”.
a81a_{81} a 8 1.
The entry in row 8, column 1 of A: the coefficient of v₈ in T(v₁). Say it: “a eight one”.
a82a_{82} a 8 2.
The entry in row 8, column 2 of A. Say it: “a eight two”.
a18a_{18} a 1 8.
Strang's slip for a₈₁ (row 1, column 8 is in the last column). Say it: “a one eight”.
a28a_{28} a 2 8.
Strang's slip for a₈₂, the last entry of the second column. Say it: “a two eight”.

Tap or click a symbol in a formula to see the same explanation. All symbols: symbols and notation.

Words on this page

Show the 28 words used here

New here

change of basis.
Describing the same vectors, or the same transformation, with a different set of basis vectors.
lossless.
Of compression: making data smaller in a way that can be undone exactly, with nothing lost.
lossy.
Of compression: making data much smaller by throwing away details the eye or ear hardly notices, so the original cannot be recovered exactly.
standard basis.
The basis made of the columns of the identity matrix: vectors with a single 1 and zeros elsewhere.
thresholding.
Setting all coefficients smaller than a chosen size to zero, so only the important ones are kept.
wavelet.
One of a set of short, localised wave shapes used as a basis for signals and images, made by shifting and squeezing one basic shape.

Also used

linear.
Of a map, operator or equation: respecting sums and multiples, so that L(au + bv) = aL(u) + bL(v). Explained in The geometry of linear equations.
basis.
A set of independent vectors from which every vector in a space can be built, in exactly one way, as a combination. Explained in Independence, basis and dimension.
p..
Page, in a reference to a source; pp. means pages, as in pp. 3–5.
matrix.
A rectangular table of numbers, which acts on vectors to give new ones and so describes a linear change of coordinates. Explained in Planes through three points, and matrices.
vector.
A list of numbers written as a column, or more generally anything that can be added and multiplied by numbers. Explained in Orthogonal vectors and subspaces.
correlation.
How strongly two quantities tend to vary together; for random quantities, the average of their product minus the product of their averages. Explained in Random variables: independence, the binomial distribution and the central limit theorem.
DC.
Short for direct current; in signal work, the constant part of a signal that does not oscillate, as in the all-ones DC vector.
Fourier matrix.
The square matrix whose entries are powers of a complex root of one, used to change a signal into its frequencies and back. Explained in Complex matrices and the fast Fourier transform.
FFT.
Short for fast Fourier transform, a quick method for computing a discrete Fourier transform.
orthogonal.
At right angles; more generally, of two vectors or functions, having a dot product, or an integral of their product, of zero. Explained in Introduction to Fourier series.
dot product.
A way of multiplying two vectors that gives a number: multiply matching components and add, or lengths times the cosine of the angle between them. Explained in Vectors and the dot product.
orthonormal.
Of a set of vectors: each has length one and each is at right angles to all the others. Explained in Projection matrices and least squares.
OCW.
OpenCourseWare: MIT's free website of course materials, the source of every MIT lesson on this site.
similar.
Of two square matrices: describing the same transformation in two different bases. Explained in Similar matrices and the Jordan form.
eigenvector.
A non-zero vector that a matrix only stretches or shrinks without turning: multiplying it by the matrix gives a number times the same vector. Explained in Linear systems with constant coefficients: eigenvalues and eigenvectors.
projection.
The shadow of a vector on a line or plane: the nearest point to it there, found by dropping a perpendicular. Explained in Projections onto subspaces.
symmetric.
Unchanged by some swap, reflection or turn; for an expression in two quantities, unchanged when they are exchanged. Explained in Introduction to Fourier series.
projection matrix.
A matrix that sends every vector to its projection onto a fixed line, plane or subspace. Explained in Projection matrices and least squares.

Academic

transcript.
A written record of exactly what was said in a recorded lecture, word for word.
redundant.
Not needed, because the same information is already given elsewhere.
recap.
A short summary of what has already been covered.
error.
The difference between a measured or computed value and the true one; often how large that difference may be.

Tap or click a word, here or in the text, for its meaning in this lesson. All words: the glossary. How many words are marked in the text: Reading options (the “Aa” button).

Where this leads

In cosmology

Check your understanding

  1. Why is the standard pixel basis poor for compression?
  2. Which step of JPEG loses information?
  3. In the 8-point Haar wavelet basis, how is the checkerboard vector (1,−1,1,−1,1,−1,1,−1)(1, -1, 1, -1, 1, -1, 1, -1) written?
  4. A transformation has matrix AA in one basis and BB in another. How are they related?
0 of 4 answered

Flashcards

1 / 4