Image Enhancement: Histogram Processingmanj/ece178-Fall2009/e178-L4.ppt.pdf · Histogram Processing...
Transcript of Image Enhancement: Histogram Processingmanj/ece178-Fall2009/e178-L4.ppt.pdf · Histogram Processing...
Histogram Processing 1
Image Enhancement: Histogram Processing
Reading: Chapter 3 (Spatial domain)
Histogram Processing 2
Histogram Processing
• Histogram Equalization • Histogram Specification/Matching
Histogram Processing 3
Histogram
p(rk)= nk/n
rk
nk : # pixels with gray level rk
n : # pixels in the image
€
rk ∈ {0,1,2,…,L −1}
Histogram Processing 4
Histogram
Histogram Processing 5
Figure 3.15: histograms
Histogram Processing 6
Histogram Modification
r : Input gray level [0, 1] s : Transformed gray level [0, 1]
s = T (r) T : Transformation function
Histogram Processing 7
Histogram Equalization ( i ) T (r) is single valued valued and monotonically increasing in 0 ≤ r ≤ 1 ( ii ) 0 ≤ T (r) ≤ 1 for 0 ≤ r ≤ 1
[0, 1] T→ [0, 1] Inverse transformation : T −1(s)= r 0 ≤ s ≤ 1T −1(s) also satisfies ( i ) and ( ii )The gray levels in the image can be viewed as random variables takingvalues in the range [0,1].Let pr (r) : p.d.f. of input level r and let ps (s) : p.d.f. of s
s = T (r) ; ∴ ps (s) = pr (r) dr ds r=T −1 (s ) (from ECE 140)
Histogram Processing 8
Equalization (contd.)
We are interested in obtaining a transformation function T( ) which transforms an arbitrary p.d.f. to an uniform distribution
pr(r) ps(s)
s
Histogram Processing 9
Consider s = T (r) = pr (w) dw 0 ≤ r ≤ 10
r
∫
(Cumulative distribution function of r)ps (s) = pr (r)dr ds r=T −1 (s )
;
dsdr
=ddr
pr (w)dw0
r
∫
= pr (r)
∴ ps (s) = pr (r)1
pr (r) r=T −1 (s )
≡ 1 0 ≤ s ≤ 1
Histogram Processing 10
Equalization: Example
2
1 r
pr(r)
pr (r) =−2r + 2 0 ≤ r ≤ 10 Else
s = T (r) = (2 − 2w) dw0
r
∫ = (2w − w2 )0
r= 2r − r2
∴r2 − 2r + s = 0
Histogram Processing 11
Equalization (example: contd.)
r =+2 ± 4 − 4s
2= 1± 1− s
r = T −1(s) = 1− 1− s as r ∈[0,1]
ps (s) = pr (r)drds
= (−2r + 2) dds
(1− 1− s)r=1− 1− s
= (−2r + 2) −12
(1− s)−1/2 (−1)
= (−2 + 2 1− s + 2) +12 1− s
= 1 0 ≤ r ≤ 1
Histogram Processing 12
Equalized Histograms
Histogram Processing 13
Fig 3.18: Transformation curves
Histogram Processing 14
Equalization: Discrete Case
0
Number of levels
p r nn
r k L
L
s T r p r nn
r kk
k
k k r jj
j
k
j
k
( ) ; , ,...,
( ) ( )
= ≤ ≤ = −
→
= = ===∑∑
1 0 1 1
00
Histogram Processing 15
Discrete Case: Example
64x64 image; 8 gray levels.
Notice that equalized histogram is not perfectly flat!
k r n nn S n
n p s
ssssssss
k kk
kj
j
k
s k=
→ →
→ →
→ →
→ →
→ →
→ →
→ →
→ →
=∑0
17 0
17
37 1
27
57 2
37
67 3
47
67 3
57 4
67 4
77 4
0 0 790 019 019 0191 1023 0 25 0 0 252 850 0 21 0 65 0 213 656 016 0 81 0 244 329 0 08 0 89 0 245 245 0 06 0 95 1 0116 122 0 03 0 98 1 0117 81 0 02 10 1 011
( )
. . .. .44 .. . .. . .. . .. . .. . .. . .
Histogram Processing 16
Equalization: Image Examples
Original, Equalized (64) Equalized (256)
Histogram Processing 17
..and their histograms
Original, equalized (64 levels) Equalized (256 levels)
Histogram Processing 18
Histogram specification
Suppose s = T (r) = pr (w) dw0
r
∫pr (r)→ Original histogram ; pz (z)→ Desired histogram
Let v = G(z) = pz (w)0
z
∫ dw and z = G−1(v)
But s and v are identical p.d.f.∴ z = G−1(v) = G−1(s) = G−1(T (r))
Histogram Processing 19
Question
• What happens when you apply equalization to an already equalized histogram – In the continuous case? – In the discrete case?
Histogram Processing 20
Fig 3.19: Matching
Histogram Processing 21
Matching: Summary
Steps: (1) Equalize the levels of original image (2) Specify the desired pz(z) and obtain G(z) (3) Apply z=G-1(s) to the levels s obtained in
step 1
Histogram Processing 22
Matching: an example
z p z v G r n p zzzzz sz sz sz sz
k z k k k k z k 0 0 0
0 0 0 0 0 0 0.15 = 790 0.19 0.35 = 1023 0.25 0.65 = 850 0.21 0.85 = 985 0.24
17
37
57
67
( ) ( ) ( )
.
.
.
..
=
=
=
=
= ↔
= ↔
= ↔
= ↔
=
0
11
7
22
7
33
7 0
44
7 1
55
7 2
66
7 3
7
0 000
0 150 20 30 2
1 015 4 1.0 = 1 448 0.11 ↔ s
Histogram Processing 23
Histogram Matching: example
Original image (Jenolan caves, blue mountain, Sydney, Ausralia)
Histogram Processing 24
Color to grayscale
I=imread(‘sydney1.jpg); I1=rgb2gray(I); I1=imresize(I1,0.5); Imhist(I1);
Histogram Processing 25
Desired & modified histograms
I2=histeq(I1,imhist(J)); Imhist(I2);
Imhist(J) J=some image
Histogram Processing 26
Histogram modified image
Histogram Processing 27
Fig 3.20: Another example
Histogram Processing 28
Fig 3.21
Histogram Processing 29
Fig 3.22