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.
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).
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×29, each a gray level from 0 to 255, which is 28 values: 8 bits (p. 2). So the image is a vector (pp. 2–3)
An image as a vector
x∈Rn,n=5122
In words
x is in capital R to the power n, n equals 512 squared
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 basisvectors (pp. 4–5):
the vector of all ones, which alone carries a solid image;
the checkerboard(1,−1,1,−1,…), 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 (the Joint Photographic Experts Group standard) uses, in Strang's words, the Fourier basis, starting with the all-ones vector (the DCvector, 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×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)
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 basisvectorwi (p. 7):
Reconstruction
x^=kept i∑c^iwi
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).
The competition for Fourier is wavelets (p. 9). The simplest set in R8 (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
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) along a row, find c1,…,c8 with (pp. 10–12)
Transform step
P=c1w1+⋯+c8w8=Wc,c=W−1P
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
What makes a basis good (pp. 12–14). First, it must be fast: multiplying by W and by W−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 product4−4=0 (p. 13). Divided by their lengths (8, 4, 2), they are orthonormal and W−1=WT (pp. 13–14). Second, it must compress well: a few basisvectors 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,…,c8 in the waveletbasis 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).
Now take a linear transformation T of eight-dimensional space, a rotation say (p. 16). In a first basisv1,…,v8 it has matrixA; in a second basisw1,…,w8 it has matrixB. 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−1AM
In words
B equals capital M to the power minus 1 capital A capital M
with M the change-of-basis matrix, the W 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). T is known once T(v1),…,T(v8) are known, because every x is c1v1+⋯+c8v8 and T(x)=c1T(v1)+⋯+c8T(v8) (pp. 18–19). Write each output in the basis; the coefficients fill the columns of A, 64 numbers in all (p. 19):
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 "a11 down to a18" for the first column and "a21 down to a28" for the next; the first column runs from a11 to a81, the second from a12 to a82.)
The best basis (pp. 19–20). If the basisvectors are eigenvectors, T(vi)=λivi: the first output is already λ1 times the first basisvector, so the first column is λ1 and zeros, and so on (p. 20):
Eigenvector basis
T(vi)=λivi⇒A=Λ
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 waveletsw1=(1,1,1,1), w2=(1,1,−1,−1), w3=(1,−1,0,0), w4=(0,0,1,−1) to transform the pixel row P=(7,5,2,2), then keep only the two largest coefficients. (b) The projection onto the 45° line has matrixA=(1000) in the basis(1,1)/2, (1,−1)/2 (here the eigenvectorbasis 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/wiTwi: c1=16/4=4, c2=(12−4)/4=2, c3=(7−5)/2=1, c4=(2−2)/2=0. Check: 4w1+2w2+w3=(4+2+1,4+2−1,4−2,4−2)=(7,5,2,2).
(a) Compression
Keep c1=4 and c2=2: P^=4w1+2w2=(6,6,2,2). Two numbers instead of four (and c4 was zero anyway); the error(1,−1,0,0) is exactly c3w3, the one wavelet dropped.
(b) Change of basis
Put the new basis in M=21(111−1), orthogonal and symmetric, so M−1=M. The standard-basis matrix is MAM−1=21(111−1)(1000)(111−1)=21(1111), the familiar projection matrix of the last lecture: similar to A, as promised.
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.
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.
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.
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.
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.
Unchanged by some swap, reflection or turn; for an expression in two quantities, unchanged when they are exchanged. Explained in Introduction to Fourier series.
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).