Professional Documents
Culture Documents
05 - Histogram Processing
05 - Histogram Processing
05 - Histogram Processing
2
Normalized Histogram (PMF)
• dividing each of histogram at gray level rk by the total
number of pixels in the image, n
pr(rk) = nk / n
• For k = 0,1,…,L-1
• p(rk) gives an estimate of the probability of occurrence
(Probability Mass Function) of gray level rk
• The sum of all components of a normalized histogram
is equal to 1
3
Discrete versus Continuous
Random Variables
Discrete Random Variable Continuous Random Variable
Finite Sample Space Infinite Sample Space
e.g. {0, 1, 2, 3,…,255} e.g. [0,1], [2.1, 5.3]
Probability Mass Function (PMF) Probability Density Function (PDF)
p x i P X x i f x
1. f ( x ) 0 , for all x in R X
1. p (x i ) 0, for all i
2. f ( x)dx 1
2. i 1
p (x i ) 1 RX
3. f ( x ) 0, if x is not in R X
4
Histogram Processing
• Basic for numerous spatial domain processing
techniques
• Used effectively for image enhancement
• Information inherent in histograms also is
useful in image compression and
segmentation
5
h(rk) or p(rk)
Example
rk
Dark image
Components of
histogram are
concentrated on the
low side of the gray
scale.
Bright image
Components of
histogram are
concentrated on the
high side of the gray
scale. 6
Example
Low-contrast image
histogram is narrow
and centered toward
the middle of the
gray scale
High-contrast image
histogram covers broad
range of the gray scale
and the distribution of
pixels is not too far from
uniform, with very few
vertical lines being much
higher than the others 9
Desired Histogram for the Best
Contrast is a UNIFORM
10
Histogram Equalization
• As the low-contrast image’s histogram is narrow and
centered toward the middle of the gray scale, if we
distribute the histogram to a wider range the quality
of the image will be improved.
11
Histogram Matching Problem
• Given an Image I with
– Intensity values r {0, 1, 2,…, 255}
– and PMF, pr(r)
12
Or Simply
Z=T(r)?
z
13
Conditions of T(r)
• Single-valued (one-to-one relationship) guarantees that
the inverse transformation will exist
• Monotonicity condition preserves the increasing order
from black (0) to white (255) in the output image thus it
won’t cause a negative image
• 0 z = T(r) 255 for 0 r 255 guarantees that the
output gray levels will be in the same range as the input
levels.
• The inverse transformation from z back to r is
r = T -1(z) ; 0 z 255
14
Before we Start the Process:
Remember
• If fx(x) is a PMF of a discrete random variable x, we define the
cumulative distribution function (CDF) Fx (x) as:-
x
Fx ( x) f x (r ), where x {0,1, 2, ..., 255}
• Note that: r 0
1. P(X x) = Fx(x)
2. Fx(-) = 0
3. Fx() = 1
4. 0 Fx(x) 1
5. Fx(x1) Fx(x2) if x1 < x2
6. P(x1 < x x2) = Fx(x2) –Fx(x1)
15
Histogram Matching Process
16
Step 1
• Compute the PMF, pr(r) of the input image I.
0.04
0.035
0.03
0.025
pr(r)
0.02
0.015
0.01
0.005
0
0 50 100 150 200 250 300
17
Step 2
• Compute the CDF, Pr(r) of the input image I.
0.04 1
0.9
0.035
0.8
0.03
0.7
0.025
s = Pr(r)
0.6
pr(r)
0.02 0.5
0.4
0.015
0.3
0.01
0.2
0.005
0.1
0 0
0 50 100 150 200 250 300 0 50 100 150 200 250
r r
18
Step 3
• Given a histogram pz(z) , Compute its CDF, Pz(z).
19
Step 4
• Construct the map r-z by solving the equation
Pr(r)=Pz(z).
0.9
0.8
0.7
s = Pr(r)
0.6
0.5
0.4
0.3
0.2
0.1
0
0 50 100 150 200 250
20
Step 4 (Continue)
r pr(r) s = Pr(r) z = Pz-1(s)
255
21
Simple Proof
Pz(z)=P(Z≤z)
Pr(r)=P(R≤r)
• Pz(z)=(z+1)/L.
• s= Pr(r)=(z+1)/L
• z=L* s-1
24
Example
The quality is
not improved
much because
the original
image already
has a broaden
gray-level scale
25
Example
No. of pixels
6
2 3 3 2 5
4 2 4 3 4
3
3 2 3 5
2
2 4 2 4
1
Gray level
4x4 image
0 1 2 3 4 5 6 7 8 9
Gray scale = [0,9]
histogram
26
Gray
0 1 2 3 4 5 6 7 8 9
Level(r)
No. of
0 0 6 5 4 1 0 0 0 0
pixels
k
n
j 0
j 0 0 6 11 15 16 16 16 16 16
k nj 6 11 15 16 16 16 16 16
s 0 0 / / / / / / / /
j 0 n
16 16 16 16 16 16 16 16
z =round( 10*s-1) 0 0 3 6 8 9 9 9 9 9
8 3 8 6 4
3
6 3 6 9
2
3 8 3 8
1
Output image
0 1 2 3 4 5 6 7 8 9
Gray scale = [0,9] Gray level
Histogram equalization 28
Equalization of a CT Image
29
Equalization of a Natural Image
30
Another Important Example: Adjust the sneakers-image
such that its new histogram matches that given in the
second row.
31
Results
Initial CDF Desired CDF
1 1
0.8 0.8
0.6 0.6
0.4 0.4
0.2 0.2
0 0
0 50 100 150 200 250 0 50 100 150 200 250
32
r-z MAP
260
240
220
200
180
160
z
140
120
100
80
60
0 20 40 60 80 100 120
r
33
Example (Continuous Case)
pr(r) 2r 2 ;0 r 1
pr ( r )
2 0 ; elsewhere
1 r
p ( w )dw 1
0
r
0 1 2 r 34
Example
p ( w )dw 1
0
z
z
0 1 2 35
Step 1:
0 r r 2 2r
1
36
Step 2:
z
2 z
Pz (z) (2 w)dw z z 2
0
0
37
Step 3:
Pz ( z ) Pr (r )
2 2
z r 2r
2
z 2r r
We can guarantee that 0 z 1 when 0 r 1
38