Histogram: Instructor Engr DR Muhammad Jamil Khan

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 55

Instructor

Histogram Engr Dr Muhammad


Jamil Khan
Objectives
❑ Histogram

❑ Histogram Equalization

❑ Histogram Matching
Histogram Processing
Histogram Processing
The histogram of a digital image with gray levels in the range
[0, 𝐿 − 1] is a discrete function
ℎ(𝑟𝑘) = 𝑛𝑘
where 𝑟𝑘 is the 𝑘𝑡ℎ gray level and 𝑛𝑘 is the number of pixels
in the image having gray level 𝑟𝑘. and the subdivisions of the
intensity scale are called histogram bins.
Histogram Processing
Example
Consider the 5x5 Digital Image with 8 gray levels [0 – 7]

7 1 6 2 5
5 6 7 5 3
5 1 6 4 4
5 7 6 7 4
7 6 3 0 6
Histogram Processing
𝒉 𝒓𝟎 = 𝟏 7 1 6 2 5

𝒉 𝒓𝟏 = 𝟐 5 6 7 5 3

𝒉 𝒓𝟐 = 𝟏 5 1 6 4 4

𝒉 𝒓𝟑 = 𝟐 5 7 6 7 6

𝒉 𝒓𝟒 = 𝟐 7 6 3 0 6

𝒉 𝒓𝟓 = 𝟓
𝟕
𝒉 𝒓𝟔 = 𝟕
𝑻𝒐𝒕𝒂𝒍 𝑵𝒖𝒎𝒃𝒆𝒓 𝒐𝒇 𝑷𝒊𝒙𝒆𝒍𝒔 = ෍ 𝒉(𝒓𝒋 ) = 𝟐𝟓
𝒉 𝒓𝟕 = 𝟓 𝒋=𝟎
Histogram Processing

0
𝒉 𝒓𝟎 𝒉 𝒓𝟏 𝒉 𝒓𝟐 𝒉 𝒓𝟑 𝒉 𝒓𝟒 𝒉 𝒓𝟓 𝒉 𝒓𝟔 𝒉 𝒓𝟕
Histogram Processing
Histogram Processing
Histogram Processing
It is common practice to normalize a histogram by dividing
each of its values by the total number of pixels in the image,
denoted by the product 𝑀𝑁. Thus, a normalized histogram
is given by
𝑛𝑘
ℎ(𝑟𝑘) =
𝑀𝑁
The sum of all components of a normalized histogram is
equal to 1.
Histogram Processing
𝟐
𝟏 𝒉 𝒓𝟒 = = 𝟎. 𝟎𝟖
𝒉 𝒓𝟎 = = 𝟎. 𝟎𝟒 𝟐𝟓
𝟐𝟓
𝟓
𝟐 𝒉 𝒓𝟓 = = 𝟎. 𝟐𝟎
𝒉 𝒓𝟏 = = 𝟎. 𝟎𝟖 𝟐𝟓
𝟐𝟓
𝟕
𝟏 𝒉 𝒓𝟔 = = 𝟎. 𝟐𝟖
𝒉 𝒓𝟐 = = 𝟎. 𝟎𝟒 𝟐𝟓
𝟐𝟓
𝟓
𝟐 𝒉 𝒓𝟕 = = 𝟎. 𝟐𝟎
𝒉 𝒓𝟑 = = 𝟎. 𝟎𝟖 𝟐𝟓
𝟐𝟓
Histogram Processing Normalized Histogram
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
𝒉 𝒓𝟎 𝒉 𝒓𝟏 𝒉 𝒓𝟐 𝒉 𝒓𝟑 𝒉 𝒓𝟒 𝒉 𝒓𝟓 𝒉 𝒓𝟔 𝒉 𝒓𝟕
Cumulative Distributive Function (CDF)
Histogram Processing
1 1

0.9 0.9

0.8 0.8

0.7 0.7

0.6 0.6

0.5 0.5

0.4 0.4

0.3 0.3

0.2 0.2

0.1 0.1

0 0
𝒉 𝒓𝟎 𝒉 𝒓𝟏 𝒉 𝒓𝟐 𝒉 𝒓𝟑 𝒉 𝒓𝟒 𝒉 𝒓𝟓 𝒉 𝒓𝟔 𝒉 𝒓𝟕 𝒉 𝒓𝟎 𝒉 𝒓𝟏 𝒉 𝒓𝟐 𝒉 𝒓𝟑 𝒉 𝒓𝟒 𝒉 𝒓𝟓 𝒉 𝒓𝟔 𝒉 𝒓𝟕
Histogram Processing
Consider the 8x8 Digital Image 4 0 3 3 1 5 1 0
with 8 gray levels [0 – 7] 4 1 4 3 2 1 3 3
1 2 2 3 2 5 7 6
Draw the histogram and
1 2 2 2 3 2 6 0
normalized histogram of the 2 1 2 2 1 5 4 3
given image. 2 3 6 5 4 4 1 3
1 7 5 5 7 3 7 2
1 0 6 7 4 2 5 6
Histogram Processing 4 0 3 3 1 5 1 0
𝒉 𝒓𝟎 = 𝟒 4 1 4 3 2 1 3 3
𝒉 𝒓𝟏 = 𝟏𝟐 1 2 2 3 2 5 7 2
1 2 2 2 3 2 6 0
𝒉 𝒓𝟐 = 𝟏𝟔
2 1 2 2 1 5 4 3
𝒉 𝒓𝟑 = 𝟏𝟑 2 3 3 5 4 4 1 3
𝒉 𝒓𝟒 = 𝟕 1 7 5 5 3 3 2 2
𝒉 𝒓𝟓 = 𝟕 1 0 1 7 4 2 5 6
𝟕
𝒉 𝒓𝟔 = 𝟐
𝑻𝒐𝒕𝒂𝒍 𝑵𝒖𝒎𝒃𝒆𝒓 𝒐𝒇 𝑷𝒊𝒙𝒆𝒍𝒔 = ෍ 𝒉(𝒓𝒋 ) = 𝟔𝟒
𝒉 𝒓𝟕 = 𝟑 𝒋=𝟎
Histogram Processing
Histograms are
❑ Simple to calculate
❑ Give information about the kind (global appearance) of
image and its properties.
❑ Used for image enhancement
❑ Used for image compression
❑ Used for image segmentation
❑ Can be used for real time processing
Histogram Equalization
A histogram being a distribution of the number of pixel
according to their intensities. Histogram equalization is a method to
process images in order to adjust the contrast of an image by
modifying the intensity distribution of the histogram. The
objective of this technique is to give a linear trend to the cumulative
probability function associated to the image.
Histogram Equalization
Histogram Equalization
The intensity levels in an image may be viewed as
random variables in the interval [0, L-1].
Let pr (r ) and ps ( s) denote the probability density
function (PDF) of random variables r and s.
Histogram Equalization
Histogram Equalization
How to implement histogram equalization?
Step 1:For images with discrete gray values, compute:
L: Total number of gray levels

nk: Number of pixels with gray value rk

n: Total number of pixels in the image

Step 2: Based on CDF, compute the discrete version of the


previous transformation :
Histogram Processing
Example
Consider the 5x5 Digital Image with 8 gray levels [0 – 7]

7 1 6 2 5
5 6 7 5 3
5 1 6 4 4
5 7 6 7 4
7 6 3 0 6
Histogram Processing Normalized Histogram
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
𝒉 𝒓𝟎 𝒉 𝒓𝟏 𝒉 𝒓𝟐 𝒉 𝒓𝟑 𝒉 𝒓𝟒 𝒉 𝒓𝟓 𝒉 𝒓𝟔 𝒉 𝒓𝟕
Cumulative Distributive Function (CDF)
Histogram Processing
1 1

0.9 0.9

0.8 0.8

0.7 0.7

0.6 0.6

0.5 0.5

0.4 0.4

0.3 0.3

0.2 0.2

0.1 0.1

0 0
𝒉 𝒓𝟎 𝒉 𝒓𝟏 𝒉 𝒓𝟐 𝒉 𝒓𝟑 𝒉 𝒓𝟒 𝒉 𝒓𝟓 𝒉 𝒓𝟔 𝒉 𝒓𝟕 𝒉 𝒓𝟎 𝒉 𝒓𝟏 𝒉 𝒓𝟐 𝒉 𝒓𝟑 𝒉 𝒓𝟒 𝒉 𝒓𝟓 𝒉 𝒓𝟔 𝒉 𝒓𝟕
Histogram Processing
1 1

0.9 0.9

0.8
 CDF for 0.8

0.7 Histogram 0.7

0.6 0.6

0.5 0.5

0.4
0.4
CDF for
0.3 Equalized 0.3

0.2
Histogram → 0.2

0.1 0.1

0 0
𝒉 𝒓𝟎 𝒉 𝒓 𝟏 𝒉 𝒓𝟐 𝒉 𝒓𝟑 𝒉 𝒓𝟒 𝒉 𝒓𝟓 𝒉 𝒓𝟔 𝒉 𝒓𝟕 𝒉 𝒓𝟎 𝒉 𝒓𝟏 𝒉 𝒓𝟐 𝒉 𝒓𝟑 𝒉 𝒓𝟒 𝒉 𝒓𝟓 𝒉 𝒓𝟔 𝒉 𝒓𝟕
Histogram Equalization
How to implement histogram equalization?
Step 1:For images with discrete gray values, compute:
𝑛𝑘
𝑝𝑟 𝑟𝑘 = 𝑤ℎ𝑒𝑟𝑒 𝑘 = 0,1,2, … , 𝐿 − 1
𝑀𝑁
nk: Number of pixels with gray value rk

𝑀𝑁: Total number of pixels in the image

L: Total number of gray levels


Histogram Equalization
How to implement histogram equalization?
Step 2: Based on CDF, compute the discrete version of the previous
transformation :

Thus, a processed (output) image is obtained by using Eq. to


map each pixel in the input image with intensity 𝑟𝑘 into a
corresponding pixel with level 𝑠𝑘 in the output image, This is
called a histogram equalization or histogram linearization
transformation.
Histogram Processing
𝒑𝒓 𝒓𝟎 = 𝟎. 𝟎𝟒 𝟎
෍ 𝒑𝒓 𝒓𝒋 = 𝟎. 𝟎𝟒
𝒋=𝟎
𝒑𝒓 𝒓𝟏 = 𝟎. 𝟎𝟖 𝟏
෍ 𝒑𝒓 𝒓𝒋 = 𝟎. 𝟏𝟐
𝒋=𝟎
𝟐
𝒑𝒓 𝒓𝟐 = 𝟎. 𝟎𝟒 ෍ 𝒑𝒓 𝒓𝒋 = 𝟎. 𝟏𝟔
𝒋=𝟎
𝟑
𝒑𝒓 𝒓𝟑 = 𝟎. 𝟎𝟖 ෍
𝒋=𝟎
𝒑𝒓 𝒓𝒋 = 𝟎. 𝟐𝟒
𝟒
𝒑𝒓 𝒓𝟒 = 𝟎. 𝟎𝟖 ෍
𝒋=𝟎
𝒑𝒓 𝒓𝒋 = 𝟎. 𝟑𝟐
𝟓

𝒑𝒓 𝒓𝟓 = 𝟎. 𝟐𝟎 ෍ 𝒑𝒓 𝒓𝒋 = 𝟎. 𝟓𝟐
𝒋=𝟎
𝟔
෍ 𝒑𝒓 𝒓𝒋 = 𝟎. 𝟖𝟎
𝒑𝒓 𝒓𝟔 = 𝟎. 𝟐𝟖 𝒋=𝟎
𝟕
෍ 𝒑𝒓 𝒓𝒋 = 𝟏
𝒑𝒓 𝒓𝟕 = 𝟎. 𝟐𝟎 𝒋=𝟎
Histogram Processing
𝟎
𝒔𝟎 = 𝟕 ෍ 𝒑𝒓 𝒓𝒋 = 𝟎. 𝟐𝟖 𝒔𝟎 = 𝟎
𝒋=𝟎
𝟏
𝒔𝟏 = 𝟕 ෍ 𝒑𝒓 𝒓𝒋 = 𝟎. 𝟖𝟒 𝒔𝟏 = 𝟏
𝒋=𝟎
𝟐
𝒔𝟐 = 𝟕 ෍ 𝒑𝒓 𝒓𝒋 = 𝟏. 𝟏𝟐 𝒔𝟐 = 𝟏
𝒋=𝟎
𝟑
𝒔𝟑 = 𝟕 ෍ 𝒑𝒓 𝒓𝒋 = 𝟏. 𝟔𝟖 𝒔𝟑 = 𝟐
𝒋=𝟎
𝟒
𝒔𝟒 = 𝟐
𝒔𝟒 = 𝟕 ෍ 𝒑𝒓 𝒓𝒋 = 𝟐. 𝟐𝟒
𝒋=𝟎
𝟓 𝒔𝟓 = 𝟒
𝒔𝟓 = 𝟕 ෍ 𝒑𝒓 𝒓𝒋 = 𝟑. 𝟔𝟒
𝒋=𝟎
𝟔 𝒔𝟔 = 𝟔
𝒔𝟔 = 𝟕 ෍ 𝒑𝒓 𝒓𝒋 = 𝟓. 𝟔𝟎
𝒋=𝟎
𝟕 𝒔𝟕 = 𝟕
𝒔𝟕 = 𝟕 ෍ 𝒑𝒓 𝒓𝒋 = 𝟕. 𝟎𝟎
𝒋=𝟎
Histogram Processing Normalized Histogram
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
𝒉 𝒓𝟎 𝒉 𝒓𝟏 𝒉 𝒓𝟐 𝒉 𝒓𝟑 𝒉 𝒓𝟒 𝒉 𝒓𝟓 𝒉 𝒓𝟔 𝒉 𝒓𝟕
CDF for Equalized Histogram
Histogram Processing
1 1

0.9 0.9

0.8 0.8

0.7 0.7

0.6 0.6

0.5 0.5

0.4 0.4

0.3 0.3

0.2 0.2

0.1 0.1

0 0
𝒉 𝒓𝟎 𝒉 𝒓𝟏 𝒉 𝒓𝟐 𝒉 𝒓𝟑 𝒉 𝒓𝟒 𝒉 𝒓𝟓 𝒉 𝒓𝟔 𝒉 𝒓𝟕 𝒉 𝒓𝟎 𝒉 𝒓𝟏 𝒉 𝒓𝟐 𝒉 𝒓𝟑 𝒉 𝒓𝟒 𝒉 𝒓𝟓 𝒉 𝒓𝟔 𝒉 𝒓𝟕
Histogram Processing
1 1

0.9 0.9

0.8
 CDF for 0.8

0.7 Histogram 0.7

0.6 0.6

0.5 0.5

0.4
0.4
CDF for
0.3 Equalized 0.3

0.2
Histogram → 0.2

0.1 0.1

0 0
𝒉 𝒓𝟎 𝒉 𝒓 𝟏 𝒉 𝒓𝟐 𝒉 𝒓𝟑 𝒉 𝒓𝟒 𝒉 𝒓𝟓 𝒉 𝒓𝟔 𝒉 𝒓𝟕 𝒉 𝒓𝟎 𝒉 𝒓𝟏 𝒉 𝒓𝟐 𝒉 𝒓𝟑 𝒉 𝒓𝟒 𝒉 𝒓𝟓 𝒉 𝒓𝟔 𝒉 𝒓𝟕
Histogram Equalization Example
Suppose that a 3-bit image (L=8) of size 64 × 64 pixels (MN = 4096) has
the intensity distribution shown in following table.
Get the histogram equalization transformation function and give the
ps(sk) for each sk.
Histogram Equalization Example
Suppose that a 3-bit image (L=8) of size 64 × 64 pixels (MN = 4096) has
the intensity distribution shown in following table.
Get the histogram equalization transformation function and give the
ps(sk) for each sk.
Histogram Equalization Example
0
s0 = T (r0 ) = 7 pr (rj ) = 7  0.19 = 1.33 → 1
j =0

1
s1 = T (r1 ) = 7 pr (rj ) = 7  (0.19 + 0.25) = 3.08 → 3
j =0

s2 = 4.55 → 5 s3 = 5.67 → 6
s4 = 6.23 → 6 s5 = 6.65 → 7
s6 = 6.86 → 7 s7 = 7.00 → 7
Histogram Equalization Example
Histogram Matching
Histogram equalization yields an image whose pixels are (in
theory) uniformly distributed among all gray levels.

Sometimes, this may not be desirable. Instead, we may want a


transformation that yields an output image with a pre-
specified histogram. This technique is called histogram
specification.
Histogram Matching
Histogram matching or histogram specification is the
transformation of an image so that its histogram matches
a specified histogram. The well-known histogram
equalization method is a special case in which the
specified histogram is uniformly distributed.
Histogram Matching
Histogram Matching
Histogram Matching
Histogram Matching
Histogram Matching
Histogram Matching
Histogram Matching
Histogram Matching
Histogram Matching
Histogram
Matching
Local Histogram

You might also like