0% found this document useful (0 votes)
2 views

03

Uploaded by

mh861590
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

03

Uploaded by

mh861590
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 68

Prepared By:

DIGITAL IMAGE PROCESSING Dr. Marwa


Mamdouh
Image Enhancement Measures

• 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

T[f (x, y)]


Operation T
Spatial Spatial
f (x, y) g (x, y) 5
IMAGE OPERATIONS: IMAGE ENHANCEMENT
Contrast:
Contrast can be simply explained as the difference between maximum
and minimum pixel intensity in an image.
Histogram
Histogram is a graph that shows frequency of occurrence of data.
Histograms has many use in image processing, out of which we are going to discuss one use here
which is called histogram sliding.
Histogram sliding
In histogram sliding, we just simply shift a complete histogram rightwards or leftwards. Due to
shifting or sliding of histogram towards right or left, a clear change can be seen in the image.
We will use histogram sliding for manipulating brightness.
Sliding Histograms
Increasing brightness using histogram sliding

Histogram of this image has been shown below.


On the y axis of this histogram are the frequency
or count. And on the x axis, we have gray level values.
As you can see from the above histogram, that those gray level intensities
whose count is more then 700, lies in the first half portion,
means towards blacker portion.
That's why we got an image that is a bit darker.
In order to bright it, we will slide its histogram towards right,
or towards whiter portion.
In order to do we need to add at least a value of 50 to this image.
Because we can see from the histogram above, that this image also has 0
pixel intensities, that are pure black.
So if we add 0 to 50, we will shift all the values lies at 0 intensity to 50
intensity and all the rest of the values will be shifted accordingly.
Here what we got after adding 50 to each pixel intensity.
The image has been shown below.

And its histogram has been shown below.


Conclusion

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

The histogram of this image is shown below.


CONTRAST STRETCHING AND THRESHOLDING
HISTOGRAM EQUALIZATION
Image Histogram
• A way of viewing the distribution of
color/intensities in an image.
h(x) = the number of pixels in I with intensity value x
• A plot of pixels values against pixel counts.

Frequenci
es

4/2/2019 Grey Levels 38


Image Histogram – (cont.)
Color Image
● I has 3 histograms:
hR(x) = number of pixels in I(:,:,1) with intensity value x
hG(x) = number of pixels in I(:,:,2) with intensity value x
hB(x) = number of pixels in I(:,:,3) with intensity value x

4/2/2019 43
Image Histogram – (cont.)
Color Image
Luminosity

There is one histogram


per color band
R, G, & B. Luminosity
histogram is from 1
band ~ (R+G+B)/3

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 Level CDF CDF * (Levels-1)


Value
0 0.11 0
1 0.22 1
2 0.55 3
3 0.66 4
4 0.77 5
5 0.88 6
6 0.99 6
7 1 7
Now we have is the last step, in which we have to map the new gray level values into number of
pixels.
Lets assume our old gray levels values has these number of pixels.
 Now if we map our new values to

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:

Original gray level i 0 1 2 3 4 5 6 7 8 9 10 11 12 1 1 15


3 4
Final gray level i 1 1 1 1 1 1 1 1 1 4 8 10 13 1 1 15
5 5

You might also like