Lecture 31 · Basis transformation and image compression
Simplifying matrices with basis transformations and understanding low-rank approximations in image compression.
On this page
Change of basis; image compression | Gilbert Strang | MIT 18.06 Linear Algebra
Lecture 31 / Total 35 Lectures |Part 3 · Eigenvalues, positive definiteness and linear transformation
Video of this lecture: Bilibili p32 · Basis transformation and image compression ↗(50:14)| MIT OCW official page ↗
Illustration: MIT OCW 18.06SC official lecture summary (CC BY-NC-SA 4.0) and Bilibili classroom video frames (time stamped), about 10 frames per lecture.
Introduction to this lecture
Last lecture linear transformation (Linear transformation) corresponds to a matrix: given a set of basis, an abstract transformation has a concrete matrix. But here is a question - if the basis is replaced, what will the same transformed matrix become? This lecture answers this question and starts with the most practical scenario: image and video compression.
one piece The grayscale image is mathematically a dimensional vector whose standard coordinates are pixel-by-pixel grayscale values. Neighboring pixels tend to have almost the same grayscale, which is where the whole scope of compression comes in. Since the image is a vector, you can use a different set of basis to represent it: rewrite “one coordinate per pixel” as “superposition of a few basis vectors in the direction”. JPEG does exactly that - slices an image into small pieces, in Change the basis once, discard a large number of coefficients, and rebuild again.
This lecture draws two conclusions from this. First, a good basis must satisfy two things at the same time: both the transformation and the inverse transformation are fast, and a few basis vectors are enough to approximate the image. Second, back to the abstract level, the two matrices of the same linear transformation under different bases are similarity matrix (similar matrices), there is only one basis transformation between them. The last section reiterates the previous lecture on “Writing a Matrix from a Base” and explains that if the base is composed of eigenvectors, the matrix is a diagonal matrix - this is the overall goal of changing the base: to make the matrix simple.

MIT OCW Official Lecture Notes Summary Page 1/3 (18.06SC Lecture 31 Summary, CC BY-NC-SA 4.0).
1. An image is a vector
Digital images are extremely cumbersome in their raw form. take one The picture of it has a Pixel (pixel). Record each pixel on the black and white image Arrive The grayscale between level, occupying exactly 8 bits. Arrange all pixels in a column in a fixed order, and the entire image becomes a vector:
If the image is colored, each pixel needs three numbers (red, green, blue) to determine the color, and the vector length becomes . Satellite remote sensing, climate simulation, combustion calculations, and various sensors are all continuously generating data of this magnitude; the original format recorded by the camera is extremely unfriendly to transmission. Transmitting the videos of these courses as they are will directly overwhelm the transmission system, so it must be compressed. There are two types of compression: one type only uses the repetition within the data and can be lossless; the other type is really used for images and videos, which makes part of the information disappear permanently, which is called lossy compression.
In this representation, the The coordinate is the The gray level of pixels, the corresponding basis is of Standard base(standard basis):
The problem with the standard basis is that it completely ignores the correlation between pixels. The grayscale of adjacent pixels on a shirt might be , , , almost the same; the grayscale of the blackboard is completely the same. The most extreme situation is the empty blackboard before class: the gray value of the entire picture is almost the same everywhere, and the amount of information is extremely small. However, it is expressed in standard coordinates and must be given honestly. Almost the same numbers, and I dare not lose any of them. Little information, but a lot of coordinates——This is the reason why the standard basis is not suitable for compression.

Video 00:05:01 | Approximately corresponding to Section 1 “1. The image is a vector”.

Video 00:05:56 | Approximately corresponding to Section 1 “1. The image is a vector”.
2. A solid color only requires one vector
Since the standard basis does not take advantage of correlation, a set of basis should be used that can take advantage of it. There are infinitely many bases, and the choice is ours. The most worthy vector to put into the base is all 1 vector
This vector alone can completely describe a solid color image: take equal to that gray value, It is a uniform picture throughout. Of course, the real image is not a pure color, but the blackboard, the sky, and the entire piece of clothing are all “pure color with a little disturbance”; putting all 1 vectors into the basis, this part of the common information only needs one coefficient, not . In electrical engineering it is called DC vector (DC vector), that is, the DC component, its corresponding frequency is zero.
The other extreme is that adjacent pixels alternate between positive and negative Checkerboard vector
It changes the fastest and represents the highest frequency. If the image is really a huge chessboard, this one vector carries the entire signal; but this component of an ordinary image is extremely small. In between are the slowly changing steps:
Take the first half , take the second half , describing the common overall light and dark transition of “half dark, half bright”.
These three vectors draw a spectrum of shapes of the basis: from a constant at zero frequency, to slowly varying steps, to alternations at the highest frequencies. Which set of basis to choose is the most critical decision in compression, which directly determines whether the coefficients can be discarded in large quantities. Behind this decision are huge industrial interests: the television industry has its own preference for signal scanning methods, and the film industry prefers another. In the end, the debate is still a linear algebra problem.
JPEG has indeed fulfilled its wish to put all 1 vectors into the base. The basis used by JPEG (Joint Photographic Experts Group, Joint Photographic Experts Group) is Fourierky (Fourier basis), the all-1 vector is exactly its first column; in addition, its columns are some complex numbers Each power of , one by one, gives oscillations of increasingly higher frequency. But JPEG does not capture the entire of the diagram, but first cut into of small pieces: each piece pixels, the question starts from down to , using 64 basis vectors to replace the basis in a 64-dimensional space - the shapes of these 64 vectors are predetermined, so the transformation can be completed quickly using a fixed algorithm.
3. There is no loss if you change the basis, but there is loss if you lose the coefficients.
for each Block, the first step of JPEG is to do only one thing: replace the 64 pixel values with 64 new coordinates (coefficients). This step is Lossless (lossless) - the basis has changed, but the vector has not changed. The two sets of coordinates describe the same vector. Completely reversible. Compression really happens in the next step: threshold (thresholding). Set a threshold and set all coefficients whose absolute values are lower than the threshold to zero, and we get . This step is lossy (lossy), the information has really been deleted, but it has been deleted so that the human eye can hardly see the difference - how high the threshold should be set is determined by “whether the eyes can distinguish it”.
Why do thresholds work? Because the coefficient distribution in good base is extremely uneven. Coefficients in the all-1 direction are almost always large and are rarely thrown away; coefficients in high-frequency alternating directions are small enough to be ignored in smooth images. During reconstruction, the retained coefficients are multiplied back to their respective basis vectors and then added:
This sum usually only has two or three terms left, instead of the original 64. 64 items are reduced to 3 items, the compression ratio is about , which is exactly the order of magnitude pursued by actual systems.
The same train of thought explains other applications. Fingerprint files are a large number of still images, with tens of millions of files accumulated in the United States; pixel-by-pixel storage cannot be stored or retrieved. After being compressed and indexed on a unified basis, the time from submission to search has changed from days to minutes. Video is a sequence of highly correlated still frames: two adjacent frames are almost identical. Instead of compressing each frame independently, it is better to only encode and compress “small corrections after prediction”. Regardless of the time direction or the space direction, the essence of compression is to take advantage of the fact that “adjacent values are very close”.
4. Wavelet basis: a set of orthogonal basis that can be quickly inverted
The strongest competitor of Fourier bases is wavelet basis (wavelet basis). In order to see the base-changing action itself, first only take the 8 pixel values of one of the rows, so the problem lies in on; in this 8-dimensional space, the simplest 8 wavelet basis vectors can be written one by one:
The pattern is very clear: the first two describe the light and dark of the entire block (the difference between the overall brightness and the front and rear halves), the next two describe the contrast inside the front and rear halves, and the last four are each taken on only one adjacent pixel pair. . All portions are only , , , multiplication degenerates into addition and subtraction, and calculation is extremely fast. Arranging these eight vectors in columns, we get wavelet matrix(wavelet matrix):
They come in twos orthogonal (orthogonal), the dot product of any two different vectors is zero: ; ; This type is only taken on an adjacent pair The vector of , dot product with any “blocked” vector, there will be only one pair left with Cancel. but they are not orthogonal (orthonormal), the lengths of each column are not the same:
The one above therefore not satisfied , but
Divide each column by its own length to remedy this. after remediation , so The inverse matrix is the transpose:
This point is crucial: the basics of changing bases , that is, calculate ; If the inversion is a transpose, the inversion step disappears, leaving only one matrix multiplication vector.
This set of wavelets really spells it all. Taking the alternating vector with the fastest changing Fourier basis as an example,
The direction that “jumps the most” is cleanly split into four here, which is exactly what a basis means: each vector has a unique set of coefficients. As the next generation image compression standard, JPEG 2000 incorporates wavelet bases; the FBI uses smoother wavelets, not from Jump directly to rough version. Key’s competition is far from over.

MIT OCW Official Lecture Notes Summary Page 2/3 (18.06SC Lecture 31 Summary, CC BY-NC-SA 4.0).

Video 00:26:32 | Approximately corresponding to Section 4 “4. Wavelet basis: a set of orthogonal basis that can quickly invert”.
5. The equation of changing basis and the two criteria of “good basis”
Generalize the above approach. Let the new basis vector Arrange matrix by columns , called basis transformation matrix (change-of-basis matrix). The coordinates of the same vector in the old basis are , the coordinates under the new basis are , the two are related by the following formula:
So the new coordinates are
All the mathematics of changing bases is contained in these two lines: Multiply by the inverse of the basis transformation matrix. The difference between different compression systems lies in How to choose.
Therefore, there are two operable criteria for “good foundation”.
One, fast. Must be able to multiply quickly , can also be quickly multiplied by . Fourier basis Fast Fourier Transform (FFT) to do this; the wavelet base has a corresponding fast wavelet transform; the wavelet matrix in the previous section is orthogonal because of the columns. , two multiplications are equally cheap. If this condition is not met, compression will take an unbearably long time.
Second, it compresses well. Not changing the base at all is of course fastest, but that’s the worst kind of compression: throw away 90% of the 8 pixel values, and the image is just black. A good basis allows a few basis vectors to be enough to reconstruct the image, that is, the vast majority of coefficients can be safely set to zero - in block, replacing 64 with approximately three coefficients.
Both are indispensable. The Fourier basis is the most familiar choice, and the wavelet basis is a later challenger, but the “best basis” has not yet been determined.

Video 00:32:39 | Approximately corresponding to Section 5 “5. The equation of changing basis and the two criteria of “good basis"".
6. The same transformation under different bases: similarity matrix
Back to the abstract level. Set is A linear transformation to itself, which itself has no coordinates, and can be a rotation, projection, or any linear operation. selected basis , There is a matrix ;Change a group of bases , the same There is a matrix . The transformation has not changed, only the coordinates describing it have changed, so with There must be a definite relationship between them.
The conclusion is: with similar(similar),
Among them It is the base transformation matrix, which can be taken as the one in the previous section . The definition of similarity matrix is exactly this form: there is an invertible matrix , so that the difference between the two matrices is once “left multiplied by , multiply right ”.
This relationship can be spelled out by the two rules from the previous section. Between the old coordinates and the new coordinates is . If you put The matrix under the old basis is written as , the matrix under the new basis is recorded as , then for any new coordinate : first Replace with old coordinates , use function, and then change the result back to the new basis, we get
Therefore, changing the basis changes two things at the same time: new coordinates for each vector, and new matrices for each transformation; the latter is the former sandwiched between with obtained between. This also shows that “similar” is an appropriate term - the two matrices describe what the same object looks like in different coordinate systems.

Video 00:40:11 | Approximately corresponding to Section 6 “6. The same transformation under different basis: similarity matrix”.

Video 00:40:49 | Approximately corresponding to Section 6 “6. The same transformation under different basis: similarity matrix”.
7. How the matrix is created; eigenvector basis
The conclusion of Section 6 is based on “how to write a matrix given a given basis”, so we will go through the construction method in the previous lecture again. Let the basis be . By linearity, any are all unique combinations of basis vectors , so
Just know here By outputting the basis vectors, we know the entire . Next, these outputs are expressed using the same basis:
coefficient It’s the matrix of the column; generally, of The elements are in the expansion of coefficient. Time matrix total Number: The output of each of the 8 input directions must be written as a combination of base vectors using 8 coordinates.
The best base is eigenvector (eigenvector) basis, that is, the basis vector satisfies , among which is corresponding eigenvalue (eigenvalue). At this time The expansion of is , the first column only has the first component ;Similarly Column only components . The matrix becomes a diagonal matrix:
Under a diagonal matrix, each basis vector is simply stretched times, all directions do not interfere with each other, and the transformation is extremely simple. Of course, image processing most wants such a basis, but for It is too expensive to find all the eigenvectors of dimensional pixel vectors. In fact, we can only take a step back: choose a cheap and easy-to-use basis, such as wavelet basis or Fourier basis. The main line of the whole lecture ends here——The purpose of changing the basis is to make the matrix simpler, but the price must be paid.

Video 00:45:12 | Approximately corresponding to Section 7 “7. How matrices are created; Eigenvector basis”.

MIT OCW Official Lecture Notes Summary Page 3/3 (18.06SC Lecture 31 Summary, CC BY-NC-SA 4.0).
Summary of this lecture
- one piece The grayscale image is a vector in , ;The vector length of the color image is 3 times longer.
- The possibility of compression comes from correlation: adjacent pixels are close in grayscale, and adjacent frames are almost identical. The standard basis gives coordinates pixel by pixel, which is not used. It is especially bad for images where the “entire grayscale is the same”.
- The full 1 vector (DC vector, zero frequency) can describe the solid color image with one coefficient; the alternating vector is the highest frequency direction; the half vector half The vector describes the slowly changing light and dark steps. Base selection is the most critical and most important decision in compression.
- JPEG Cut the picture into blocks (64 pixels each), in The Fourier basis is used to change the basis; this step of changing the basis is lossless, and then setting the small coefficients to zero (threshold) is lossy.
- Reconstruction is the superposition of a small number of basis vectors; there are usually only two or three coefficients left out of 64, and the compression ratio is about .
- The 8-dimensional wavelet basis consists of all 1 vectors, three block step vectors and four vectors taken only on one adjacent pair. consists of vectors, each pair is orthogonal, and the length is ;After column-by-column standardization .
- The equation for changing the basis is , that is ; A good basis must be fast (FFT, fast wavelet transform, orthogonal inversion or transpose), and it must be compressible (a few basis vectors are enough for reconstruction).
- The matrices of the same transformation under the two families of basis are similar: , among which is the base transformation matrix.
- How to write a matrix from bases: put Expanded into a combination of basis vectors, the coefficient is the column, The elements are coefficient.
- If the basis consists of eigenvectors, , the matrix becomes a diagonal matrix ; This is the best basis, but finding eigenvectors is too expensive, so in practice it is the second best.
keywords
| English | Chinese | One sentence explanation |
|---|---|---|
| change of basis | basis transformation | Change a set of bases to represent the same vector, and the new coordinates are given by given |
| standard basis | Standard base | Only one component is taken , the rest are The basis of , corresponding to the pixel-by-pixel grayscale |
| pixel | Pixel | The smallest unit of the image, the grayscale is Arrive |
| lossless | Lossless | A compression step where the transformation is reversible and information is not really lost |
| lossy | lossy | A compression step in which some coefficients are discarded and information cannot be recovered. |
| thresholding | threshold | Set coefficients whose absolute value is below the threshold to zero |
| DC vector | DC vector | A vector of all 1s, in the zero-frequency direction, describing a solid color image with one coefficient |
| Fourier basis | Fourierky | The basis used by JPEG can be quickly transformed using FFT |
| wavelet basis | wavelet basis | made of lumps with Orthogonal basis composed of, JPEG 2000 adopts |
| orthonormal | orthogonal | Pairs are orthogonal and the length is , at this time |
| basis-change matrix | basis transformation matrix | matrix with new basis vectors as columns , satisfy |
| similar matrices | similarity matrix | The matrix of the same transformation under different bases satisfies |
| eigenvector basis | Eigenvector basis | A basis composed of eigenvectors, where the matrix is a diagonal matrix |
Machine-assisted translation · Read Chinese original
