13 - Image Compression
You probably have heard of JPEG, probably have JPEG images all around you, okay. JPEG uses something called the Discrete Cosine Transform, or variations there of. Basically a way of thinking about that is they take a little 8x8 region of the image.

So you carve the whole region up in little 8x8 segments. And then it takes, as a basis set, these sinusoids and co-sinusoids, right. So here we have the ones that are vertical, here we have ones that are coming down and here we have the product of them. And you can see the lower frequencies are in the top left hand corner and the higher frequencies are in the bottom right hand corner.
So what you can do is you can say, how much of each of these do I need to make the picture? And you can actually order them, right. You can, you can sort of go through them and order them this way. With the idea being that the top left hand corner might be, in fact go back here. You see how this is a constant? Okay, so that's just, if you, that's just the average of the picture. So the top left hand corner, what sometimes called B(0,0) that's just the DC component, the average and then as you get further and further your getting the higher and higher frequencies. So the top left hand corner represent the lower frequencies. The bottom right hand corner represents the higher frequencies.

Now, what we said before is, we don't have to represent the higher frequencies that well, right? Just sort of the high contrasty components of it. So one way of doing that is saying, what if we encode these coefficients better, more bits, than these coefficients? And that gives you what's called a quantization table. And DCT, discrete cosine transform, does the compression by, so what this 3 means is we keep the coefficient say to the nearest three values, so if you're thinking of this in bits you, you can shift it over by two. The idea is that you round this to the nearest 3. Whereas this is rounded to the nearest 31, okay. So in other words, you're doing more representation of the top left hand corner than you are of the bottom right hand corner, okay. And so what that means is you lose information but you're mostly losing the information down here, okay. And the same way, by the way, that you do the inverse Fourier transform given the spectrum you can reconstruct the signal.

The same is true of the DCT. IDCT, inverse DCT. Given those coefficients, I can reconstruct the image. But now, instead of maintaining all those coefficients exactly, I'm only going to keep more information about the low frequency coefficients than I am about the high frequency coefficients. And that works really well for the human vision system. And so if you take a look at your average JPEG image and here's an example I've stolen from the web somewhere, okay. So they used 89,000 bytes of information to represent this picture. Using just the, the raw intensities and 12,000 bytes here so this is a ratio of what, seven to one. Using DCT coefficients, the JPEG standard, all right. The reason it works, to sum this all up, is that images vary over frequency, that's our base's set. The human vision system is sensitive to different frequencies at different amounts. So by doing similar to a Fourier transform where you take that integral or that sum, that dot product with the wiggly sinusoids, DCT is a variant of that. We can figure out the coefficients for each of the frequencies. Then we can threshold essentially or reduce the level of representation of the high frequency in order to save a bunch of bits in describing the image.