First, let's just take a, basically, an artificial sample, where we have eight

different values here. This is a counting, so we have 790 pixels

that have value zero. And 1,023 pixels that have value one, and

so on, and we just transformed these into a probability, and because we have been

working with probabilities and this is the probability that we are going to get,

we plug that into the formula that I just showed you, and this is what we're going

to get. So, first of all.

This is the original instagram, Pr. This is the distribution that we have.

If you plug that into the formula which I showed, this is going to be the

transform. Note, it's going to be monotonic.

And we know that because we are integrating.

And let me just write that again. The basic operation was to integrate from

zero to r. So, the more I integrate, because what I

have in here is positive, it's clearly an increasing function.

I'm only adding more and more positive numbers so it has to be positive.

So, it's an increasing function, and what it tells me, it tells me that zero goes

to this number. One goes to this number, and so on.

So, it becomes a very, very simple map. And this is going to be the new

histogram. Now, you may wonder, it looks more

uniform and one of the things that happens because we are working with

discrete data, we're working with images in the computer, we're going to have to

round numbers. So, for example, the 4.2 will become

four. So, we end up actually with less peaks

than we have here because this ones here at the end, will merge into the same

integer number. And that's a price we play, we pay for

working with this great images. We cannot represent 6.7 and 6.8, will

both become, although the formula tells us they should go to different numbers,

they will both become, let's say, seven. In a similar fashion, Let me ask the

following question which I'm going to ask you to think for a second and then

respond to me. Let's just look at an histogram that has

the following form. It has only two different pixel values,

these two. It doesn't matter what exactly are the

values here, but this is the original distribution, of pixel values.

There are only two values in the image. This is a binary image with only two

different colors, two different pixel values.

And I'm going to ask you what's the relationship between the map for a pixel

value here and a pixel value here? So, let's just call this A, let's just

call this B, and I'm asking you the relationship between T(a) and T(b).

Are they equal? Are they different?

Is T(a) greater than T(b)? Is T(a) less than T(b)?

So, just think for a second and give me your answer and I'm going to come back

right away and give you the explanation for the correct answer.

So, let's look at what is the correct answer.

Remember, what we are doing in histogram equalization is we are integrating,

okay? So, I ask you, what's the relationship

between these two, are equal, less, or greater?

We know first of all that T(b) should be greater or equal, than T(a) because we

have a monotonically increase in function. But let's just look a bit more

in detail, what happened. This actually is going to integrate the

whole mass up to here. So, basically its going to integrate only

this. Here, is going to integrate everything up

to b. But there is no new mass between a and b.

Since there is no new mass then what happens is that T(a) would equal to T(b).

And as an extra exercise, you can think about what's going to be actually to

transform for this one and what's going to be the transform for this particular

one. And especially, you can relate it to the

average in the image, just do that as an exercise on the side.

But this is very important illustration that the basically, transform that we're

looking for, even before we have to round or quantize because we're working with

these great images. Even before that, it's not strictly

monotonic, there might be more than one values that end up with the same

transform. You can, of course, say, we don't really

care too much about that, because in the original image there were no pixels with

initial gray value a. And that's correct but I want to show

this both to illustrate that the transform does not have to be

monotonically, strictly monotonically increasing.

It has to be monotonically increasing but not strictly.

And also to illustrate once again that all what the histogram equalization is

doing is basically counting the number of pixels after the value that you want to

mark. So, I'm counting the value, the number of

pixels up to a and then the number of pixels up to b.

So, after this exercise, let's just see few additional examples.

We, of course, saw examples with the online demo, but let's just illustrate

one more example, which I think is very useful.

I'm going back to the images that we started.

This was dark. This is what's happening after histogram

equalization and the histogram looks much nicer than before.

So, let's just look at the map. This is the map.

Pixels value form here can map to here, okay?

So, this is my r and this is my s. And look at the map.

The map is basically is very, it has a very, very high slope because it's trying

to very fast map very dark pixels to brighter pixels.

So, it has a very, very sharp slope. Let's look for example at this one.

This one was pretty good to start from. It hasn't changed a lot and actually this

is the map. It's almost unislope, in mapping the

diagonal, there's almost no changes in the pixel values.

And similar interpretations for the other two maps.

This one actually needed, needs to darken the pixels and we see that in the

corresponding map, that basically, look what happens here.

And this one needed to stretch the pixels.

Remember, they were in the middle, it needs to stretch them and we actually

observe that here. It's stretching the pixels from the

middle. They were all around here to start from

and it's going to stretch them and we see that it actually occupies the whole range

from this which was the very big, very narrow band, that it occupies the

original histogram with very low contrast is actually mapping out to the whole

spectrum from zero to 255 and we see that in the map as well.

And, of course, we end up with images that are very similar, regardless of

where we started because these images actually were created from these images,

from an original, let's say, this one, just by changing the

contrast. And then after we equalize them, they look much closer.

And that's a technique that is used very often to make images that we're taking

under different conditions look much more similar.

We equalize the histogram, at the same time, we're making the images look much

more similar and then we can compare between them in a, in a much more

friendly fashion. So, this is basically instagram

equalization. What we are going to do next in the next

video is instagram transform. What happens if I don't want to equalize

an histogram? I want to transform it to an histogram

that I know is going to be very good for my image.

We are going to see that in the next very short video that is also a very, very

simple operation. Thank you.