Image Processing (Unit-2)
Dr. Vijay Kumar Sharma
NIT Kurukshetra
Histogram sliding
• Brightness is changed by shifting
the histogram to left or right.
+50
Histogram sliding
- 30
Histogram stretching
• Contrast can be increased using:
1. Histogram stretching
2. Histogram equalization
• Contrast is the difference between maximum
and minimum pixel intensity. Contrast = 225.
Increasing the
contrast
f(x,y) g(x,y)
Low contrast image High contrast image
Contrast stretching
Before
Contrast = 225
After
Contrast = 255
Contrast stretching
• This formula doesn’t work always. If there
is 1 pixel with intensity 255:
Contrast stretching has
no effect!!!
Introduction to probability
• PMF and CDF are both related to
probability. They will be used in Histogram
Equalization. • PMF – Probability Mass
Function.
• It gives the probability of each number in
the data set (frequency of each
element).
Probability – PMF
Calculating PMF from image
mat
rix
PM
Image matrix
0 2 2/25 1 4 4/25 2 3
1 2 7 5 6 7 2 3 4 5 0 1 3/25 3 3 3/25 4 2 2/25 5
5 7 3 1 2 5 6 7 6 1 0 3 4 4/25 6 3 3/25 7 4 4/25
4
Probability – PMF
Calculating PMF from histogram
Frequency of gray increasing
level values for an 8 function
bits per pixel image.
Not monotonically
Probability – CDF
• CDF – Cumulative Distributed Function •
Cumulative sum of values calculated by
PMF
Probability – CDF
•
CDF will be calculated using the
histogram • CDF makes the PDF grow
monotonically
• Monotonical growth is necessary
for histogram equalization.
Histogram equalization
• Histogram equalization is used for enhancing
the contrast of the images.
• The first two steps are calculating the PDF
and CDF.
• All pixel values of the image will be equalized.
Histogram equalization
• Image with its histogram
Histogram equalization
Small Small
image image
(values) (values)
Histogram
equalization
Image detail
Frequency of pixel values
Histogram
equalization
Histogram equalization
• min = 52
• max = 154
cdfmin is the minimum non-zero value of the cumulative distribution function (in
this case 1), M × N gives the image's number of pixels (for the example above
64, where M is width and N the height) and L is the number of grey levels used
(in most cases, like this one, 256).
Histogram equalization
New min. value = 0, old min. value 52
New max. value = 255, old max. value 154
Original Equalized
Histogram
equalization
An unequalized image and cumulative histogram (black)
Corresponding histogram (red)
The same image after histogram Corresponding histogram (red)
equalization and cumulative histogram (black)
Histogram Matching or
Histogram Specification
• Modify the gray-level distribution of an image so that its
histogram matches a specified (target) histogram.
• Purpose
– To make images taken under different conditions look
similar – To impose a desired contrast or brightness
distribution • Process:
– Compute the histogram of the input image.
– Compute the cumulative distribution function (CDF) of
the input image.
– Define a target histogram and compute its CDF.
– Map gray levels of the input image to new gray levels
so that the input CDF matches the target CDF.
Image and Video Processing
Histogram Matching: Discrete Cases
• Obtain pr(rj) from the input image and then obtain the values of
sk, round
the value to the integer range [0, L-1].
kk
( 1)
( ) ( 1) ( )
L
−
==−=
∑∑
sTrLprn
kkrjj
== MN
jj
00
• Use the specified PDF and obtain the transformation function
G(zq), round the value to the integer range [0, L-1].
q
=− ∑
=
GzLpzs
( ) ( 1) ( )
qzik
i
=
0
• Mapping from skto zq
1
() qk z G s − =
22
Computer Vision & Biometrics Lab, Indian Institute of Information Technology,
Allahabad
Image and Video Processing
Example: Histogram Matching
Suppose that a 3-bit image (L=8) of size 64 × 64 pixels (MN =
4096)
has the intensity distribution shown in the following table (on the
left). Get the histogram transformation function and make the
output
image with the specified histogram, listed in the table on the
right.
23
Computer Vision & Biometrics Lab, Indian Institute of Information Technology, Allahabad
Image and Video Processing
Example: Histogram Matching
Obtain the scaled histogram-equalized values,
sssss
=====
1, 3, 5, 6, 7,
01234
sss
===
7, 7, 7.
567
Compute all the values of the transformation function G,
0
==
∑
Gzpz
( ) 7 ( ) 0.00 zj 0
→0
j
=
0
GzGz
( ) 0.00 ( ) 0.00 ==
→0 →0
12
GzGz
( ) 1.05 ( ) 2.45 ==
→1 → 2
34
GzGz
( ) 4.55 ( ) 5.95 ==
→ 5 →6
56
( ) 7.00
Gz
7
=
→7
24
Computer Vision & Biometrics Lab, Indian Institute of Information Technology, Allahabad
Image and Video Processing
Example: Histogram Matching
25
Computer Vision & Biometrics Lab, Indian Institute of Information Technology, Allahabad
Image and Video Processing
Example: Histogram Matching
Obtain the scaled histogram-equalized values,
sssss
=====
1, 3, 5, 6, 7,
01234
sss
===
7, 7, 7.
567
Compute all the values of the transformation function G,
0
==
∑
Gzpz
( ) 7 ( ) 0.00 zj 0
→0
j
=
0
GzGz
( ) 0.00 ( ) 0.00 ==
→0 →0
12
GzGz
( ) 1.05 ( ) 2.45 ==
→1 → 2
s1
34
s0
GzGz
( ) 4.55 ( ) 5.95 ==
→ 5 →6
s2 s3
56
( ) 7.00
Gz
7
=
→7
s4
s5 s6 s7
26
Computer Vision & Biometrics Lab, Indian Institute of Information Technology, Allahabad
Image and Video Processing
Example: Histogram Matching
sssss
=====
1, 3, 5, 6, 7,
01234
sss
===
7, 7, 7.
567
r
k
0
1
2
3
4
5
6
7
27
Computer Vision & Biometrics Lab, Indian Institute of Information Technology,
Allahabad
Image and Video Processing
Example: Histogram Matching
kq rz →
03
→
14
→
25
→
36
→
47
→
57
→
67
→
77
→
28
Computer Vision & Biometrics Lab, Indian Institute of Information Technology,
Allahabad