1:31

An important quantity for an image is it's histogram.

Is defined as h of k equals the number of pixels with value k.

So, if I have an eight bit image, the values range from from 0 to 255.

I can go and count how may pixels have the value zero, how many pixels have the value

100, that would be 8 of 100, how many have the value 255 and so on.

So, given an image such as this one, here is its histogram.

The horizontal axis is k.

2:17

The histogram clearly tells me how the

intensity values of the original image are distributed.

So, for this particular image, there are no small intensity values.

Then there is a peak, a lot of intensity values around, let's say 30.

There's another smaller peak here, let's say at 60.

And there are no intensity values higher than about this point, let's say it's 125.

2:56

So, again, the histogram gives me the distribution of the intensity values of

the image, and as a matter of fact, if I take h of k and divided by

the number of pixels in the image, then each value is less than one.

The sum of all the values or the area under this curve here is equal to 1.

And we can think of, therefore, the histogram

as the probability density function of the intensity values.

3:44

I'm bringing this example, this contrast stretching example back to

put things in context, now that we talked about the histogram.

If you recall, we started with this image on the left and then we realized that

this is a dark image and we defined the transformation

4:24

we apply the liner transformation is given by curve.

And this, again, is the output image.

Now, while operating on the intensities one at time, independently of the

neighborhood, we were also clearly modifying

the histogram of the image indirectly.

So, this is the histogram of the first

image, again, it's a dark image, so most of

the intensities are concentrate around low values, and there

are almost no intensities here of high intensity values.

4:59

And with this transformation, clearly we expand the range

of intensity values, so there are more bright values here.

So with the, we'd expect that the resulting

histogram of the processed image is spread out somehow.

And indeed, if we look at it, it looks like this.

5:35

So, with the point wise operations that we covered so

far, one has some evaluation of the image, like again, this

one is dark and then defines the transformation to be applied

on the image, independently of the specific values of the image.

With histogram processing, we are looking at the histogram of the

input image and then we are placing an objective on the histogram itself.

We are saying, for example, that they want to transform the histogram

of the input image to another type of histogram, or, as we'll see,

what is most commonly done, I want to equalize the histogram.

I want to turn the histogram of the input image into a flat histogram.

And then this objective will determine the

transformation here that I should be applying

on the input image to obtain the output image.

6:48

So again, now that transformation is defined, indirect in some

sense, by processing the image through the evaluation of his, of its histogram.

And it's not set kind of a priori by [UNKNOWN] okay,

I want this straight line to be applied to the input image.

7:09

So, this is a major difference between histogram

processing and intensity point-wise transformation.

At the end, with histogram processing, I'm also going to apply

a point wise transformation to the input image, but for example,

let's say this transformation is the resulting one that I need

to apply to the input image to get, the output one.

So, with that in mind, let's proceed with some examples of, histogram processing.

7:46

Of the histogram processing approaches, histogram

equalization is the most commonly encountered one.

The objective, in this, in this case, is to obtain an image with a flat histogram.

8:14

One is that we expect that an image with an

equalized histogram it will look better, it will be more pleasing.

All intensities, again, will be equally represented so there'll be

low intensities, and middle intensities, and high intensities in the image.

8:32

Another reason is that when I want to compare

two images, it makes sense to first equalize them.

Equalize the histogram so that then the, the comparison will

become, will be on an equal footing, will be, become meaningful.

Here are, we are going through steps we have to take towards this objective.

The first step is to normalize the histogram, by doing

so, as already mentioned, the values of the histogram become probabilities.

I change the notation slightly here, so p of x of

i is the probability that the intensity x is equal to i.

And this is equal to the number of pixels that have intensity i,

divided by the total number of pixels in the image, M times N.

9:19

So, this number is clearly less than 1.

And more than that, if I add up all these probabilities, their sum is equal to 1.

I sum up over the range of intensities here.

These intensities range from 0 to L minus 1.

So, this is the probability density function.

9:41

Then, the algorithmic steps I have to take are, the first one is, I

have to form this capital P of x sub i function, which is the

sum of the probabilities from intensity 0 to i.

So the value of P of x at i is this sum from 0 to i.

This is actually a cumulative distribution function.

And this is the function I will use now to perform

this point wise transformation of the intensity values of the image.

10:14

So, the transformation is shown here.

x of n is the input image, so this is one intensity value.

The intensity of the input image at location n.

n1 and n2, this is a vector.

10:32

again, cumulative distribution function transformation, I will

obtain the value of the output image y tilde at the same pixel location n.

[BLANK_AUDIO]

And since this mapping will give me values between 0 and 1, there is one more step,

according to which I take the y tilde here, there is an extra parenthesis.

And multiply by L minus 1, so that again y of n now, the

image with equalized histogram, will range from 0 to L minus 1.

11:14

Let's try to get some intuition of why this transformation will work out.

So, let's take the first case when the histogram of the

image is indeed flat, so here are the intensity values ranging

from 0 to L minus 1 and this is the probability of

each intensity value i, so all intensities are equally probable.

So, if form the cumulative distribution function for

this P df is going to be a straight line.

11:56

And this is zero, this is L minus one.

And this is zero and this in one.

Right?

And after I multiply the values here, y tilde by L minus 1, then the

values, again, of y of n are going to range from 0 to L minus 1.

And therefore, the overall transformation will be the identity transformation.

12:23

So, as expected, if the histogram of the image is already equalized,

I should not change anything, and

therefore, I should perform a identity transformation.

Now, let's look at an image that has a histogram that looks like this.

12:47

So, this means that this is a dark image.

It has high concentration of low intensity values and no high intensity values.

This is the maximum value.

And if I form the cumulative distribution of this.

[BLANK_AUDIO]

It's going to roughly look like this.

13:11

This is one.

This is L minus 1 up here.

So, since there is, there are a lot

of values here, it's going to rise pretty fast

and is going to approach one and stay

there because there are no values of high intensity.

So, clearly, a transformation like this will take small intensity values

and spread them out over all possible intensity values.

So, if I apply this transformation to the input

image, then the resulting image, based on this transformation, is

going to be obviously, an equalized image and it's

going to be brighter in terms of where I started.

14:03

This is going to be a bright image, it has a

lot of high intensity values and very few low intensity values and in

this case the transformation, the cumulative distribution function will

look, so let's say, L minus 1 is here, roughly speaking, it will look like this.

So, it's zero down here and then rises to the value of one.

So, according to this transformation, high intensity

values here are mapped to low intensity values.

So, if I apply this transformation again to

the input image I'll get, then, equalized image.

[BLANK_AUDIO]

Since I deal with discreet values, I am not guaranteed

that the resulting histogram is going to be perfectly flat.

15:00

This is the result, however, that if we were to use continuous intensity values,

we can prove then, in a rather straightforward way, that indeed, using

the cumulative distribution function as the point-wise transformation,

one ends up with an image that has an equalized histogram.

[BLANK_AUDIO]

Now that we covered histogram equalization, let's

revisit again contrast stretching and histogram equalization.

So, we started with this image here.

We realized it's dark, we arbitrarily, in a meaningful way

decide that a transformation like this is going to help enhance this image.

So, in, out, 255 here, x min, x max of these images.

16:11

Now, while this is happening at the intensity domain, the

story at the histogram, let's say, domain is that this is the histogram of the image

you started with, and the histogram of the processed image is this one.

16:30

With histogram equalization, we start, again, with this dark image.

We first look at its histogram.

And then we place an objective that the

processed image should have a histogram that is flat.

So, we say that the processed image should have a histogram that looks like this.

17:20

This is a transformation defined by us in an

intuitive way, and this is a transformation that is

defined by the data, the actual data of the

image through this requirement that the histogram is equalized.

And there's where the dimensions, since we

deal with discrete data, we cannot guarantee

that the histogram is going to be

perfectly flat but it's a close approximation flat.

17:51

As another example of the application of histogram

equalization, let's consider the following

images shown here, they could be characterized as

dark, light, low contrast and high contrast.

18:20

Here are their corresponding histograms which agree

with the characterization I gave to these images.

So, for the dark image, we see most

intensity values are low, are concentrated at low values.

18:52

After histogram equalization, that's how the images look like.

They're almost identical.

They have, ideally their histogram should be perfectly

flat, as we mentioned they're not perfectly flat,

actually they're shown here and they just spread

the values all over the range of values.

But again, since we deal with discrete intensities, discrete

signals, we cannot guarantee perfectly flat, perfectly flat histograms.

19:26

We see that for the last image, the one

we characterized as high contrast, the histogram was almost flat.

And therefore, very little change occurred to the histogram.

And very little change occurred for the intensities themselves.

These two images look very, very similar.

19:46

So, if we look now at the

cumulative distribution function, or the transformation that

was applied in going from these images

to these images, then here are the transformations.

So, they're numbered.

One corresponds to this image.

Two, three and four.

20:19

This is 0 to 255 here and 0 to 255, so it's the complete transformation, right?

The histogram, the histogram was almost flat.

Therefore, very little change took place.

20:46

With the light image is what I

described earlier as well the histogram is concentrated

in, at high intensity values, so is

this transformation as [UNKNOWN] as the second image.

And the low contrast is pretty much an example

we had done earlier that goes through this transformation.

It increases the dynamic range.

It maps this range of values over here to

the full range of the output value 0 to 255.

So, these transformations do not look that

different from what we were applying before,

however again, the main difference here is

that before we would define this transformations directly.

We would provide some arguments that I need one to expand

or to stretch the values, or to compress them, but now this

transformation resulted from the objective

of equalizing the, the histogram and therefore they're image dependent.

They cannot, they are not defined

independently of the intensities of the image

but are function, in essence, of distribution

of the intensity values of the image.

There are instances in which is desired that we enhance

the details of an image over a small neighborhood and

in that case we can adopt the global histogram equalization

that we described previously to a local version of it.

So, as an example, here's the original image.

22:49

If however now, we, we equalize the

histogram locally, we obtain an image like this.

So, local histogram equalization entails the

23:01

processing of three by three neighborhood.

So, we take a three by three neighborhood.

We find the mapping that will equalize the histogram in that neighborhood, but

we only process the pixel in the center of this three by three neighborhood.

Then we move this three by three window

to the next pixel, and we repeat this process.

So, we see, for this particular case, there's quite a lot of information that

is revealed, that is not visible in

the original, or the globally histogram equalized image.

So, under each of these kind of

square rectangular patches, you see that there are

specific structures that are now revealed when

I do this histogram, this logic histogram equalization.

23:50

So, this is something to keep in mind, this is a

straight forward extension of the

histogram equalization we just talked about.

It is, again, adapted to the local characteristics of the image.