Digital Image Processing: Introduction

Download Report

Transcript Digital Image Processing: Introduction

Digital Image Processing
Intensity Transformations
(Histogram Processing)
Christophoros Nikou
[email protected]
University of Ioannina - Department of Computer Science
Contents
2
Over the next few lectures we will look at
image enhancement techniques working in
the spatial domain:
– Histogram processing
– Spatial filtering
– Neighbourhood operations
C. Nikou – Digital Image Processing (E12)
Image Histograms
3
Frequencies
The histogram of an image shows us the
distribution of grey levels in the image
Massively useful in image processing,
especially in segmentation
Grey Levels
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
4
Histogram Examples
C. Nikou – Digital Image Processing (E12)
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
5
C. Nikou – Digital Image Processing (E12)
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
6
C. Nikou – Digital Image Processing (E12)
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
7
C. Nikou – Digital Image Processing (E12)
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
8
C. Nikou – Digital Image Processing (E12)
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
9
C. Nikou – Digital Image Processing (E12)
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
10
C. Nikou – Digital Image Processing (E12)
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
11
C. Nikou – Digital Image Processing (E12)
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
12
C. Nikou – Digital Image Processing (E12)
Histogram Examples (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
13
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
14
Histogram Examples (cont…)
• 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
C. Nikou – Digital Image Processing (E12)
15
Contrast Stretching
• We can fix images that have poor contrast
by applying a pretty simple contrast
specification
• The interesting part is how do we decide
on this transformation function?
C. Nikou – Digital Image Processing (E12)
16
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
C. Nikou – Digital Image Processing (E12)
17
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).
• If T(r) is strictly monotonically increasing then
the mapping from s back to r will be 1-1.
• 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.
C. Nikou – Digital Image Processing (E12)
18
Histogram Equalisation (cont...)
a) We cannot perform inverse mapping (from s to r).
b) Inverse mapping is possible.
C. Nikou – Digital Image Processing (E12)
19
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
C. Nikou – Digital Image Processing (E12)
20
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
0
C. Nikou – Digital Image Processing (E12)
21
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
C. Nikou – Digital Image Processing (E12)
Histogram Equalisation (cont...)
22
Substituting this result:
ds
 ( L  1) pr ( r )
dr
to
dr
ps ( s)  pr (r )
ds
Uniform pdf
yields
1
1
ps ( s)  pr (r )

, 0  s  L 1
( L  1) pr (r )
L 1
C. Nikou – Digital Image Processing (E12)
23
Histogram Equalisation (cont...)
The formula for histogram equalisation in the
discrete case is given
( L  1) k
sk  T (rk )  ( L  1) pr (rj ) 
nj

MN j 0
j 0
k
where
• rk: input intensity
• sk: processed intensity
• nj: the frequency of intensity j
• MN: the number of image pixels.
C. Nikou – Digital Image Processing (E12)
24
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
j 0
C. Nikou – Digital Image Processing (E12)
25
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
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
26
Histogram Equalization (cont…)
Example
Notice that due to discretization, the resulting
histogram will rarely be perfectly flat. However, it
will be extended.
C. Nikou – Digital Image Processing (E12)
Equalisation Transformation Function
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
27
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
28
Equalisation Examples
1
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
29
Equalisation Transformation Functions
The functions used to equalise the images in
the previous example
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
30
Equalisation Examples
2
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
31
Equalisation Transformation Functions
The functions used to equalise the images in
the previous example
C. Nikou – Digital Image Processing (E12)
Equalisation Examples (cont…)
3
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
32
4
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
33
Equalisation Transformation Functions
The functions used to equalise the images in
the previous examples
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
34
Histogram Specification
• 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
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
35
Histogram Specification (cont...)
Histogram equalization
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
36
Histogram specification (cont.)
• In these 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.
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
37
Histogram specification (cont…)
•Equalize the initial histogram of the image:
r
s  T (r )  ( L  1) pr (w) dw
0
G( z )  T (r )
•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.
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
38
Histogram specification (cont…)
The discrete case:
•Equalize the initial histogram of the image:
( L  1) k
sk  T (rk )  ( L  1) pr (rj ) 
nj

MN j 0
j 0
k
•Equalize the target histogram:
G( z )  T (r )
q
sk  G( zq )  ( L  1) pz (ri )
i 0
1
1
z

G
(
s
)

G
(T (rk ))
•Obtain the inverse transform: q
k
C. Nikou – Digital Image Processing (E12)
Histogram Specification (cont...)
Example
39
Consider again the 3-bit 64x64 image:
It is desired to transform this histogram to:
pz ( z0 )  0.00
pz ( z4 )  0.20
pz ( z1 )  0.00
pz ( z5 )  0.30
pz ( z2 )  0.00
pz ( z6 )  0.20
pz ( z3 )  0.15
pz ( z7 )  0.15
with z0  0, z1  1, z2  2, z3  3, z4  4, z5  5, z6  6, z7  7.
C. Nikou – Digital Image Processing (E12)
40
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.
C. Nikou – Digital Image Processing (E12)
Histogram Specification (cont...)
Example
41
Perform inverse mapping: find the smallest value
of zq that is closest to sk:
sk  T (ri )
G ( zq )
sk  zq
s0  1
s1  3
G ( z0 )  0
G ( z1 )  0
1 3
s2  5
G ( z2 )  0
s3  6
s4  6
G ( z3 )  1
G ( z4 )  2
s5  7
G ( z5 )  5
s6  7
s7  7
G ( z6 )  6
G ( z7 )  7
34
55
66
77
e.g. every pixel with value s0=1 in the histogramequalized image would have a value of 3 (z3) in
the histogram-specified image.
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
42
Histogram Specification (cont...)
Example
Notice that due to discretization, the resulting
histogram will rarely be exactly the same as the
desired histogram.
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
43
Histogram Specification (cont...)
Original image
Histogram equalization
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
44
Histogram Specification (cont...)
Histogram equalization
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
45
Histogram Specification (cont...)
Specified histogram
Transformation function
and its inverse
Resulting histogram
C. Nikou – Digital Image Processing (E12)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
46
Local Histogram Processing
• Image in (a) is slightly noisy but the noise is imperceptible.
• HE enhances the noise in smooth regions (b).
• Local HE reveals structures having values close to the values of the
squares and small sizes to influence HE (c).
C. Nikou – Digital Image Processing (E12)
Summary
47
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
C. Nikou – Digital Image Processing (E12)