We can now describe the main step that introduces error, meaning quantization.

And it's also the step that I figured out was to compress a lot.

Without quantization, we won't be able to compress too much.

We will be able to compress, but not as much as we see in our digital comments.

So basically, we have the forward transform, which we have seen.

We have these, we have seen earlier, but now we're going to describe the

quantization. So let's talk about it.

And we have actually already seen quantization when we started talking, the

very early weeks of this class, but let's just describe it in detail in the context

of JPEG compression. So, remember, we started from an eight by

eight image, and we have that on transform.

And what I'm going to represent here are the transform coefficients.

So just, in the previous video, we saw that we actually have the transform

coefficients. And we get them as a double sum, with sum

over the X, with sum over the Y, with sum over coordinates of the image.

And we're basically summing the image. This is the image,

and we have, basically, the cosine basis.

So that's how we got to these coefficients that we represent here.

We start from an eight by eight, and we get eight by eight coefficients.

So we have kind of an image in a different domain, in the cosine domain.

So what we have here are different things that we could do to those coefficients.

Now we are working with coefficients. So for example, we could say that we are

only going to take coefficients and we'll ignore all these other coefficients.

We could, that would be very, very simple, sway go to the upper left corner

and only use those coefficients, ignore everybody else.

And I'm going to write in a second what that means.

We could also do these, which says, somehow, I'm going to say which

coefficients to take. Those that are shaded, or says 1 are

going to be coefficients I'm going to send. Those that say 0 or unshaded

coefficients, I'm not going to send or store.

Now we can do something else and we can say you know what,

I don't want to, include or discard coefficients.

I want you to take this coefficient up here and represent it with eight bits.

So I'm going to let you to do quantization to 256 levels.

On the other hand, this coefficient that shows up here, so that would be the

coefficient 07, T-07. I want you to use only one bit.

So you're going to only be able to represent two different levels for that

coefficient. And we are going to talk about this in a

second. Now, what happens when we do

quantization? Remember that F is going to be then

reconstructed, as we saw in the previous, video, as the sum of T.

The transform coefficients. And we can put R because you remember

that the forward and inverse were basically the same.

So this is how we're going to reconstruct our image.

Now if we quantize T we're not going to reconstruct F because we're going to have

an approximation of T. And then we're going to reconstruct an

approximation of F. And remember what's happening is this.

Our F is a linear combination of the coefficients,

either the original coefficients, or the quantized coefficients, a linear

combination multiplying the bases. And these are the bases.

So here I'm just drawing them in a four by four, but we know that we are talking

eight by eight. So this top coefficient basically says

how much of this basis we are going to be using.

And you can say, you know what? Maybe our visual perception is such that

if instead of what I wanted to use, which is 7.7 times these bases.

Maybe if I do 7.5 it's not such a big deal, and my visual system won't perceive

the difference. So that's idea of quantization, to

basically round or say, if I put slightly a different number of this component,

whatever component TUV represents, it might not be such a big deal in the

reconstruction. And we're going to see that.

Now, remember why are we doing quantization?

We are doing quantization because we are going to do Huffman coding after that.

And remember, in Huffman coding, we want a non-uniform distribution.

We want some coefficients to appear a lot,

so we're going to give a short code, and some coefficients to appear not much,

so we can give them a long code. for example, if we quantize a load,

we might find out that 7, 8, 9, 10 all become 0.

And then we're going to be able to basically compress a lot and we're

going to see a bit more examples of that in the next transparencies. Now,

this is the basic idea. As I say, we are going to quantize, we

are going to change the coefficients that hopefully we are not going to notice

that. Now there is something I want to call

your attention, something which is very smartly done in

JPEG. If we just do quantization, we still have

to send an eight by eight matrix of quantized, transformed values, means I

have to send 64 numbers. Now I started, let's say, from an image

that has eight bits per pixel, 256 gray levels.

Then I need to send each one of these, even if I'm going to use only one bit, as

it says here. So I started from eight bits, and I can

use one, then I can only compress eight to one.

I have to basically send you that value. JPEG say something very smart.

As we're going to see in a second, the top region is going to use as its

representation here, more bits. The quantization is going to be more

fine. In the lower corner here, JPEG is

going to say, you know what? I'm going to do very, very drastic

quantizations. So drastic, that a lot of the TUV, the

coefficients would become 0. So JPEG is not going to encode, is not

going to store this, then this, then this, to UV.

It's going to actually go in a zigzag fashion.

It's going to say, okay first, I'm going to just do a convention.

The first coefficient you see is this, which is T00.

The second coefficient you see is this one, which is T01.

The third coefficient you see is this one, which is T10, okay?

So you're going to be, basically be encoding the quantized 0, 0.

Then you're going to be encoding the quantized 0, 1.

Then you're going to be encoding the quantized 1,

0. And then you keep going in this zigzag

fashion. Now, why is that important?

As I say, a lot of these are going to become 0.

Their value is going to be 0, after we do a very strong quantization there.

So when JPEG arrives to a certain coefficient, and sees that everybody else

that comes after becomes 0, it just puts one signal that says end.

And if the nth is here, meaning everybody here is 0, then I save a lot of bits.

It's still sending one bit for each, let's say, to say, 0, 0, 0, we're

basically saying one end, and that means, to the end of my block, to the end of my

eight by eight transform coefficients, everybody became 0.

And that's a very smart thing, and that's what allow us to go beyond eight to one

and to very, very high compression ratios.

And the more you're quantizing this region, the earlier this end symbol will

appear. So that's the basic idea of quantization,

but let's just see how we do it. So, a very simple form of quantization is

what we have here, and that's called uniform quantization, and this is

basically what jpeg is doing. And, it's saying, okay you take your

coefficients. I want to do uniform quantization in the

sense that, let's just pick for example, this interval.