Intensity Transformations (Histogram Processing)
Intensity Transformations (Histogram Processing)
(Histogram Processing)
2
Contents
Over the next few lectures we will look at image enhancement
techniques working in the spatial domain:
⚫ Histogram processing
⚫ Spatial filtering
⚫ Neighbourhood operations
3
Image Histograms
The histogram of an image shows us the distribution of grey
levels in the image
Massively useful in image processing, especially in
segmentation Frequencies
Grey Levels 4
Histogram Examples
5
Histogram Examples (cont…):
Dark Image
6
Histogram Examples (cont…):
Light Image
7
Histogram Examples (cont…):
Low Contrast Image
8
Histogram Examples (cont…):
High Contrast Image
9
Histogram Examples (cont…)
Dark Image Light Image Low Contrast Image High Contrast Image
⚫ Note that the high contrast image has the most evenly spaced
histogram
10
Histogram Processing
11
Histogram Equalisation
0 T (r ) L − 1, for 0 r L − 1
12
Histogram Equalisation (cont...)
13
Histogram Equalisation (cont...)
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Histogram Equalisation (cont...)
1 dr
ps ( s ) = pr (r ) = pr ( r )
ds ds
dr
15
Histogram Equalisation (cont...)
⚫ The pdf of the output is determined by the pdf of the input and
the transformation.
⚫ This means that we can determine the histogram of the output
image.
⚫ A transformation of particular importance in image processing is
the cumulative distribution function (CDF) of a random variable:
r
s = T (r ) = ( L − 1) pr ( w) dw
16
0
Histogram Equalisation (cont...)
r
ds dT (r ) d
= = ( L − 1) pr ( w) dw = ( L − 1) pr (r )
dr dr dr 0
17
Histogram Equalisation (cont...)
Substituting this result:
ds
= ( L − 1) pr (r )
dr
to
dr
ps ( s) = pr (r ) Uniform pdf
ds
yields
1 1
ps ( s) = pr (r ) = , 0 s L −1
( L − 1) pr (r ) L −1 18
Histogram Equalisation (cont...)
Prove that the PDF of the intensities in the new image is uniform
19
Histogram Equalisation (cont...)
20
Histogram Equalisation (cont...)
Example
A 3-bit 64x64 image has the following intensities:
k
sk = T (rk ) = ( L − 1) pr (rj )
j =0
Notice that due to discretization, the resulting histogram will rarely be perfectly flat. However, it will be extended.
22
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Equalisation Transformation Function
23
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Equalisation Examples
1
24
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Equalisation Transformation Functions
The functions used to equalise the images in the previous
example
25
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Equalisation Examples
2
26
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Equalisation Transformation Functions
The functions used to equalise the images in the previous
example
27
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Equalisation Examples (cont…)
3
28
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Equalisation Transformation Functions
The functions used to equalise the images in the previous
examples
29
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Histogram Specification or Matching
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Histogram Specification (cont...)
31
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Histogram specification (cont.)
32
Histogram specification (cont…)
⚫ Equalize the initial histogram of the image:
r
s = T (r ) = ( L − 1) pr ( w) dw
G ( z ) = T (r )
0
⚫ Equalize the target histogram:
r
s = G ( z ) = ( L − 1) pz ( w) dw
0
−1 −1
⚫ Obtain the inverse transform: z = G ( s ) = G (T (r ))
In practice, for every value of r in the image:
⚫ get its equalized transformation s=T(r).
⚫ perform the inverse mapping z=G-1(s), where s=G(z) is the equalized target
histogram. 33
Histogram specification (cont…)
Assuming continuous intensity values, suppose that an image has
the intensity PDF
34
Histogram specification (cont…)
Find the histogram equalization transformation for the input image
35
Histogram specification (cont…)
The discrete case:
with z0 = 0, z1 = 1, z2 = 2, z3 = 3, z4 = 4, z5 = 5, z6 = 6, z7 = 7. 37
Histogram Specification (cont...)
Example
The first step is to equalize the input (as before):
s0 = 1, s1 = 3, s2 = 5, s3 = 6, s4 = 6, s5 = 7, s6 = 7, s7 = 7
G( z0 ) = 0 G( z1 ) = 0 G( z2 ) = 0 G ( z3 ) = 1
G( z4 ) = 2 G ( z5 ) = 5 G ( z6 ) = 6 G( z7 ) = 7
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
41
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Summary
We have looked at:
⚫ Different kinds of image enhancement
⚫ Histograms
⚫ Histogram equalisation
⚫ Histogram specification
Next time we will start to look at spatial filtering and
neighbourhood operations
42