0% found this document useful (0 votes)
13 views42 pages

Intensity Transformations (Histogram Processing)

ivp

Uploaded by

Ashu GG
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views42 pages

Intensity Transformations (Histogram Processing)

ivp

Uploaded by

Ashu GG
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

Intensity Transformations

(Histogram Processing)

Dr. Navjot Singh


Image and Video Processing
Acknowledgements
⚫ Gonzalez, Rafael C. Digital image processing. Pearson, 4th
edition, 2018.
⚫ Jain, Anil K. Fundamentals of digital image processing. Prentice-
Hall, Inc., 1989.
⚫ Digital Image Processing course by Brian Mac Namee, Dublin
Institute of Technology
⚫ Digital Image Processing course by Christophoros Nikou,
University of Ioannina

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

⚫A selection of images and their histograms


⚫ Notice the relationships between the images and their histograms

⚫ Note that the high contrast image has the most evenly spaced
histogram
10
Histogram Processing

11
Histogram Equalisation

⚫ Spreading out the frequencies in an image (or equalising the


image) is a simple way to improve dark or washed out images.
⚫ At first, the continuous case will be studied:
⚫ r is the intensity of the image in [0, L-1].
⚫ we focus on transformations s=T(r):
⚫ T(r) is strictly monotonically increasing.
⚫ T(r) must satisfy:

0  T (r )  L − 1, for 0  r  L − 1
12
Histogram Equalisation (cont...)

⚫ The condition for T(r) to be monotonically increasing


guarantees that ordering of the output intensity values will
follow the ordering of the input intensity values (avoids
reversal of intensities).
⚫ The second condition (T(r) in [0,1]) guarantees that the range
of the output will be the same as the range of the input.

13
Histogram Equalisation (cont...)

a) We cannot perform inverse mapping (from s to r).


b) Inverse mapping is possible.
14

Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Histogram Equalisation (cont...)

⚫ We can view intensities r and s as random variables and their


histograms as probability density functions (pdf) pr(r) and ps(s).
⚫ Fundamental result from probability theory:
⚫ If pr(r) and T(r) are known and T(r) is continuous and differentiable,
then

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...)

⚫ It satisfies the first condition as the area under the curve


increases as r increases.
⚫ It satisfies the second condition as for r=L-1 we have s=L-1.
⚫ To find ps(s) we have to compute

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...)

Example: Suppose that the (continuous) intensity values in an


image have the PDF

Prove that the PDF of the intensities in the new image is uniform

19
Histogram Equalisation (cont...)

The formula for histogram equalisation in the discrete case is given


k
( L − 1) k
sk = T (rk ) = ( L − 1) pr (rj ) =  nj
j =0 MN j =0
where
⚫ rk: input intensity
⚫ sk: processed intensity
⚫ nj: the frequency of intensity j
⚫ MN: the number of image pixels.

20
Histogram Equalisation (cont...)
Example
A 3-bit 64x64 image has the following intensities:
k
sk = T (rk ) = ( L − 1) pr (rj )
j =0

Applying histogram equalization:


0
s0 = T (r0 ) = 7 pr (rj ) = 7 pr (r0 ) = 1.33
j =0
1
s1 = T (r1 ) = 7 pr (rj ) = 7 pr (r0 ) + 7 pr (r1 ) = 3.08
21
j =0
Histogram Equalisation (cont...)
Example
Rounding to the nearest integer:
s0 = 1.33 → 1 s1 = 3.08 → 3 s2 = 4.55 → 5 s3 = 5.67 → 6
s4 = 6.23 → 6 s5 = 6.65 → 7 s6 = 6.86 → 7 s7 = 7.00 → 7

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

⚫ Histogram equalization does not always provide the desirable results.

• Image of Phobos (Mars


moon) and its histogram.
• Many values near zero
in the initial histogram
30

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.)

⚫ Inthese cases, it is more useful to specify the final histogram.


⚫ Problem statement:
⚫ Given pr(r) from the image and the target histogram pz(z), estimate the
transformation z=T(r).
⚫ The solution exploits histogram equalization.

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

Find the transformation function that will produce an image whose


intensity PDF is

34
Histogram specification (cont…)
Find the histogram equalization transformation for the input image

Find the histogram equalization transformation for the specified histogram


z z 3t 2 z3
G ( z ) = ( L − 1)  pz (t )dt = ( L − 1)  dt = =s
0 0 ( L − 1) 3
( L − 1) 2

The transformation function

35
Histogram specification (cont…)
The discrete case:

⚫ Equalize the initial histogram of the image:


k
( L − 1) k
sk = T (rk ) = ( L − 1) pr (rj ) =  nj
j =0 MN j =0 G ( z ) = T (r )
⚫ Equalize the target histogram:
q
sk = G ( zq ) = ( L − 1) pz (ri )
i =0

⚫ Obtain the inverse transform: zq = G −1 ( sk ) = G −1 (T (rk ))


36
Histogram Specification (cont...)
Example
Consider again the 3-bit 64x64 image:

It is desired to transform this histogram to:


pz ( z0 ) = 0.00 pz ( z1 ) = 0.00 pz ( z2 ) = 0.00 pz ( z3 ) = 0.15
pz ( z4 ) = 0.20 pz ( z5 ) = 0.30 pz ( z6 ) = 0.20 pz ( z7 ) = 0.15

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

The next step is to equalize the output:

G( z0 ) = 0 G( z1 ) = 0 G( z2 ) = 0 G ( z3 ) = 1
G( z4 ) = 2 G ( z5 ) = 5 G ( z6 ) = 6 G( z7 ) = 7

Notice that G(z) is not strictly monotonic. We must resolve this


ambiguity by choosing, e.g. the smallest value for the inverse
mapping.
38
Histogram Specification (cont...)
Example
Perform inverse mapping: find the smallest value
of zq that is closest to sk:
sk = T (ri ) G ( zq ) sk → z q
s0 = 1 G ( z0 ) = 0 1→ 3
s1 = 3 G ( z1 ) = 0
3→4
s2 = 5 G ( z2 ) = 0
s3 = 6 G ( z3 ) = 1 5→5
s4 = 6 G ( z4 ) = 2 6→6
s5 = 7 G ( z5 ) = 5
7→7
s6 = 7 G ( z6 ) = 6
e.g. every pixel with value s0=1 in the histogram-
s7 = 7 G ( z7 ) = 7 equalized image would have a value of 3 (z3) in
the histogram-specified image. 39
40

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

You might also like