03
03
• Enhancement “parameters”:
1. Brightness
2. Contrast.
3. Histogram
4
Domains of Image Enhancement
Output (Better)
Input Image Image
f (x, y) Enhancement
g (x, y)
Spatial Transform
Domain Domain
As we can clearly see from the new histogram that all the pixels values has been shifted towards
right and its effect can be seen in the new image.
Decreasing brightness using histogram sliding
Now if we were to decrease brightness of this new image to such an
extent that the old image look brighter, we got to subtract some value
from all the matrix of the new image.
And this what we got after subtracting 80 from the new image.
One of the other advantage of Histogram is contrast enhancement
There are two methods of enhancing contrast.
The first one is called Histogram stretching that increase contrast.
The second one is called
Histogram equalization that enhance contrast
histogram stretching
Frequenci
es
4/2/2019 43
Image Histogram – (cont.)
Color Image
Luminosity
4/2/2019 44
Image Histogram – (cont.)
Color Image
4/2/2019 45
Image Histogram – (cont.)
Color to gray
• Lightness
Lightness = ½ × (max(R,G,B) + min(R,G,B))
• Luminosity
Luminosity = 0.21 × R + 0.72 × G + 0.07 × B
• Average
Average Brightness = (R + G + B) ÷ 3
4/2/2019 46
Image Histogram – (cont.)
Histogram Definition (normalized)
• An estimate to the probability of occurrence
of intensity level rk in an image.
• Not unique.
Introduction to Probability
What is PMF?
PMF stands for probability mass function. As it name suggest, it gives the probability of each number in
the data set or you can say that it basically gives the count or frequency of each element.
How PMF is calculated
We will calculate PMF from two different ways. First from a matrix, as image is a matrix, second from the
histogram.
Consider this matrix.
1 2 7 5 6
7 2 3 4 5
0 1 5 7 3
1 2 5 6 7
6 1 0 3 4
Now if we were to calculate the PMF of this matrix, here how we are going to do it.
At first, we will take the first value in the matrix , and then we will count, how much time this value
appears in the whole matrix. After count they can either be represented in a histogram, or in a table
like this below.
PMF 0 2 2/25
1 4 4/25
2 3 3/25
3 3 3/25
4 2 2/25
5 4 4/25
6 3 3/25
7 4 4/25
Note that the sum of the count must be equal to total number of values.
Calculating PMF from histogram
The above histogram shows frequency of gray level values for an 8 bits per pixel image.
Now if we have to calculate its PMF, we will simple look at the count of each bar from vertical axis and
then divide it by total count.
So the PMF of the above histogram is this.
Another important thing to note in the above histogram is that it is not monotonically increasing. So in
order to increase it monotonically, we will calculate its CDF.
What is CDF?
CDF stands for cumulative distributive function. It is a function that calculates the cumulative sum of all
the values that are calculated by PMF. It basically sums the previous one.
How it is calculated?
We will calculate CDF using a histogram. Here how it is done. Consider the histogram shown above which
shows PMF.
Since this histogram is not increasing monotonically, so will make it grow monotonically.
We will simply keep the first value as it is, and then in the 2nd value , we will add the first one and so on.
Here is the CDF of the above PMF function.
Now as you can see from the graph above, that the first value of PMF remain as it is. The second value
of PMF is added in the first value and placed over 128. The third value of PMF is added in the second
value of CDF , that gives 110/110 which is equal to 1.
And also now, the function is growing monotonically which is necessary condition for histogram
equalization.
PMF and CDF usage in histogram equalization
Histogram equalization is used for enhancing the contrast of the images.
PMF and CDF are both use in histogram equalization.
In the histogram equalization, the first and the second step are PMF and CDF.
Since in histogram equalization, we have to equalize all the pixel values of an image.
So PMF helps us calculating the probability of each pixel value in an image.
And CDF gives us the cumulative sum of these values.
Further on, this CDF is multiplied by levels, to find the new pixel intensities, which are mapped into old
values, and your histogram is equalized.
Histogram Equalization
Histogram equalization is used to enhance contrast. It is not necessary that contrast will always be
increase in this. There may be some cases were histogram equalization can be worse. In that cases the
contrast is decreased.
Lets start histogram equalization by taking this image below as a simple image.
Image Histogram of this image
Now we will perform histogram equalization to it.
PMF: First we have to calculate the PMF (probability mass function) of all the pixels in this image.
CDF: Our next step involves calculation of CDF (cumulative distributive function).
Calculate CDF according to gray levels
Lets for instance consider this , Gray Level CDF
that the CDF calculated in the second step Value
0 0.11
looks like this.
1 0.22
2 0.55
3 0.66
4 0.77
5 0.88
6 0.99
7 1
Then in this step you will multiply the CDF value with (Gray levels (minus) 1) .
Considering we have an 3 bpp image. Then number of levels we have are 8. And 1 subtracts 8 is 7. So
we multiply CDF by 7. Here what we got after multiplying.
Gray Frequency
Level Gray Level New Gray Level Frequency
Value Value Value
0 2 0 0 2
1 4 1 1 4
2 6 2 3 6
3 8 3 4 8
4 10 4 5 10
5 12 5 6 12
6 14 6 6 14
7 16 7 7 16
Comparing both the histograms and images
Example:
Suppose a 4-bit greyscale image has the histogram shown in figure 5.17. associated with a table of
the numbers ni of grey values:
Gray level
i 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
ni 15 0 0 0 0 0 0 0 0 70 110 45 80 40 0 0
(with n=360) We would expect this image to be uniformly bright, with a few dark dots on it. To equalize
this histogram, we form running totals of the ni
and multiply each by 15/360 = 1/24.
Gray level i ni (1/24) ni Rounded value
ni
0 15 15 0.63 1
1 0 15 0.63 1
2 0 15 0.63 1
3 0 15 0.63 1
4 0 15 0.63 1
5 0 15 0.63 1
6 0 15 0.63 1
7 0 15 0.63 1
8 0 15 0.63 1
9 70 85 3.65 4
10 110 195 8.13 8
11 45 240 10 10
12 80 320 13.33 13
13 40 360 15 15
14 0 360 15 15
15 0 360 15 15
We now have the following transformation of grey values, obtained by reading of the first and last
columns in the above table: