CSC2014 Week3
CSC2014 Week3
CSC2014 Week3
Histogram
CSC2014 Digital Image Processing
Outline
Image Histogram
Histogram Threshold Selection
Adaptive Thresholding
Contrast Stretching
Histogram Equalization
Histogram Matching
Learning Objectives
Understand what an image histogram represents.
Understand the use of histogram manipulation
Image Histogram
Histogram of a digital image with gray-
Count
0
6
4
2
0
Gray
3 Level
Image Histogram
Image Histogram
Histogram
h(rk ) nk
Count
0
rk
P(rk)
r0 = 0
2/16
r1 = 1
5/16
r2 = 2
4/16
r3 = 3
5/16
0.3
75
0.2
5
0.12
5
0
Gray
3 Level
Image Histogram
Example
Suppose that a 3-bit image (L=8) of size 64 64 pixels (MN
Histogram Threshold
Selection
By selecting a threshold value between the
two
peaks,
we
can
separate
the
background/foreground of the image using the
thresholding approach.
s=
10
Histogram Threshold
Selection
background
coins
11
Histogram Threshold
Selection
12
Histogram Threshold
Selection
Is that means we have to always select the
13
Histogram Threshold
Selection
The Otsus method calculates the optimum
14
Otsus Method
15
Adaptive Thresholding
Designed
16
Adaptive Thresholding
Threshold value, t, can be based on several
statistics:
t = mean + C;
t = median + C;
s=
floor((max-min)/2) + C;
10 10 10 10 10
20 20 20 20 20
50 50 50 50 50
20 20 20 20 20
10 10 10 10 10
0
17
Adaptive Thresholding
Illumination may differ over the image.
Roughly uniform in a sufficiently
small,
local
neighbourhood.
Original
Global Thresholding
Adaptive
Thresholding
18
19
Contrast Stretching
Improve contrast of an image by stretching
20
Contrast Stretching
Problem:
New image output depends on choice of maximum and
Contrast Stretching
50
50
50
80
81
50
50
80
81
51
51
80
255
81
51
51
80
81
81
51
51
80
81
81
22
Contrast Stretching
Solution:
Ensure that the maximum and minimum pixel
23
Contrast Stretching
25 Pixels x 5% = 1.25
50
50
50
80
81
50
50
80
81
51
51
80
255
81
51
51
80
81
81
51
51
80
81
81
24
Contrast Stretching
25
Histogram Equalization
An automatic transformation function that seeks
with
uniform
sk T(rk )
rk sk
26
Histogram Equalization
Cumulative Distribution Function (CDF)
27
Count
rk
P(rk)
r0 = 0
2/16
r1 = 1
5/16
r2 = 2
4/16
r3 = 3
5/16
0.3
75
0.2
5
0.12
5
0
Gray
3 Level
Gray
3 Level
CDF(Prk)
1
0.5
0.12
5
28
Count
Count
0.3
75
0.2
5
0.12
5
0.3
75
0.2
5
0.12
5
0
CDF(Prk)
Gray
3
Level
0.5
0.5
3
Gray
Level
Gray
3
Level
3
Gray
Level
CDF(Prk)
CDF(Prk)
1
Cu = 1
x=3
1*3=3
0.5
Cu =
0.375
x=0
0.375 * 3 =
1.125
0
3
Cu = 0.5
x=1
0.5 * 3 = 1.5
Cu =
0.675
x=2
0.675 * 3 =
2.025
Gray
Level
30
Count
Count
0.3
75
0.2
5
0.12
5
0.3
75
0.2
5
0.12
5
0
CDF(Prk)
Gray
3
Level
0.5
0.5
3
Gray
Level
Gray
3
Level
3
Gray
Level
CDF(Prk)
CDF (Prk)
T (r)
rk
sk
790
0.19
1.35
1813
0.44
3.10
2663
0.65
4.55
3319
0.81
5.67
3648
0.89
6.23
3893
0.95
6.65
4015
0.98
6.86
4096
1.00
7.00
32
Ps(sk)
0.00
0.19
0.00
0.25
0.00
0.21
0.24
0.11
33
34
35
Histogram Equalization
36
Histogram Equalization
37
Histogram Equalization
38
Comparison
Original
Histogram
Equalization
Contrast
Stretching
39
Comparison
Original
Histogram
Equalization
Contrast
Stretching
40
that:
Pixel values that occur frequently occupies a bigger
Histogram Matching
Also known as histogram specification.
Enables us to match the grayscale distribution
Original
Target
Output
42
Histogram Matching
CDF
CDF
43
Histogram Matching
01 2 3 4 5 6
7
01 2 3 4 5 6
7
01 2 3 4 5 6
7
01 2 3 4 5 6
7
44
Histogram Matching
01 2 3 4 5 6
7
01 2 3 4 5 6
7
01 2 3 4 5 6
7
01 2 3 4 5 6
7
45
Histogram Matching
Example
Get the histogram transformation function and make
46
Histogram Matching
Example
Find the smallest value of zq, so that G(zq) is
closest to sk
rk
Prk
CDF (Prk)
sk
Zq
Pz(zq)
CDF(Pz(zq))
G(zk)
0.19
0.19
0.00
0.00
0.00
0.25
0.44
0.00
0.00
0.00
0.21
0.65
0.00
0.00
0.00
0.16
0.81
0.15
0.15
1.05
0.08
0.89
0.20
0.35
2.45
0.06
0.95
0.30
0.65
4.55
0.03
0.98
0.20
0.85
5.95
0.02
1.00
0.15
1.00
7.00
47
Histogram Matching
Example
After Equalization:
rk
Prk
CDF (Prk)
sk
rk
New Prk
0.19
0.19
0.00
0.25
0.44
0.19
0.19
0.21
0.65
0.19
0.16
0.81
0.25
0.44
0.08
0.89
0.44
0.06
0.95
0.21
0.65
0.03
0.98
0.24
0.89
0.02
1.00
0.11
1.00
48
rk
0
1
2
3
4
5
6
7
sk
1
3
5
6
6
7
7
7
Zq
0
1
2
3
4
5
6
7
Pz(zq)
0.00
0.00
0.00
0.15
0.20
0.30
0.20
0.15
CDF(Pz(zq))
0.00
0.00
0.00
0.15
0.35
0.65
0.85
1.00
G(zk)
0.00
0.00
0.00
1.05
2.45
4.55
5.95
7.00
New Pz(zq)
0.00
0.15
0.20
0.00
0.00
0.30
0.20
0.15
CDF(New Pz(zq))
0.00
0.15
0.35
0.35
0.35
0.65
0.85
1.00
49
rk
Prk
CDF (Prk)
sk
0.19
0.19
0.25
0.44
0.21
0.65
0.16
0.81
0.08
0.89
0.06
0.95
0.03
0.98
0.02
1.00
7
6
5
4
3
2
1
0
0
7
Zq
Pz(zq)
CDF(Pz(zq))
G(zk)
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.15
0.15
1.05
0.20
0.35
2.45
0.30
0.65
4.55
0.20
0.85
5.95
0.15
1.00
7.00
7
6
5
4
3
2
1
0
0
7
50
1 -> 3
3->4
7
6
5
4
3
2
1
0
0
5 -> 5
6 -> 6
7 -> 7
7
7
6
5
4
3
2
1
0
0
7
51
Histogram Matching
Example
52
Histogram Matching
Example
Match Pr(rk) to Pz(zq):
rk
Pr(rk)
zq
Specified Pz(zq)
r0=0
0.05
z0=0
0.35
r1=1
0.25
z1=1
0.05
r2=2
0.20
z2=2
0.10
r3=3
0.15
z3=3
0.15
r4=4
0.10
z4=4
0.20
r5=5
0.10
z5=5
0.05
r6=6
0.10
z6=6
0.05
r7=7
0.05
z7=7
0.05
53