Digital Image Processing

Download Report

Transcript Digital Image Processing

Digital Image Processing
Image Enhancement
7/16/2015
Duong Anh Duc - Digital Image Processing
1
Image Enhancement
 To process an image so that output is “visually better”
than the input, for a specific application.
 Enhancement is therefore, very much dependent on
the particular problem/image at hand.
 Enhancement can be done in either:
– Spatial domain: operate on the original image
g(m,n) = T[f(m,n)]
– Frequency domain: operate on the DFT of the original image
G(u,v) = T[F(u,v)],
where
F(u,v) = F[f(m,n)], and G(u,v) = F [g(m,n)],
7/16/2015
Duong Anh Duc - Digital Image Processing
2
Image Enhancement Techniques
Point Operations
•
•
•
•
•
•
•
Image Negative
Contrast
Stretching
Compression of
dynamic range
Graylevel slicing
Image
Subtraction
Image Averaging
Histogram
operations
7/16/2015
Mask Operations
•
•
•
•
•
Smoothing
operations
Median Filtering
Sharpening
operations
Derivative
operations
Histogram
operations
Transform Operations
Coloring Operations
•
•
•
•
•
•
•
Low pass
Filtering
Hi pass Filtering
Band pass
Filtering
Homomorphic
Filtering
Histogram
operations
Duong Anh Duc - Digital Image Processing
False Coloring
Full color
Processing
3
Point Operations
 Output pixel value g(m, n) at pixel (m, n) depends only on the input pixel
value at f(m, n) at (m, n) (and not on the neighboring pixel values).
 We normally write s = T(r), where s is the output pixel value and r is the
input pixel value.
 T is any increasing function that maps [0,1] into [0,1].
7/16/2015
Duong Anh Duc - Digital Image Processing
4
Image Negative
T(r) = s = L-1-r, L: max grayvalue
7/16/2015
Duong Anh Duc - Digital Image Processing
5
Negative Image
7/16/2015
Duong Anh Duc - Digital Image Processing
6
Contrast Stretching


Increase the dynamic range of grayvalues in the input image.
Suppose you are interested in stretching the input intensity values in the
interval [r1, r2]:

Note that (r1- r2) < (s1- s2). The grayvalues in the range [r1, r2] is stretched into
the range [s1, s2].
7/16/2015
Duong Anh Duc - Digital Image Processing
7
Contrast Stretching
 Special cases:
– Thresholding or
binarization
r1 = r2 , s1 = 0 and s2 = 1
– Useful when we are
only interested in the
shape of the objects
and on on their actual
grayvalues.
7/16/2015
Duong Anh Duc - Digital Image Processing
8
Contrast Stretching
7/16/2015
Duong Anh Duc - Digital Image Processing
9
Contrast Stretching
 Special cases (cont.):
– Gamma correction:
S1 = 0, S2 = 1 and
0, r  r1

g

 r  r1 
 , r1  r  r2
T r   
 r2  r1 
1, r  r2

7/16/2015
Duong Anh Duc - Digital Image Processing
10
Contrast Stretching
Gamma correction
7/16/2015
Duong Anh Duc - Digital Image Processing
11
Compression of Dynamic
Range
 When the dynamic range of the input
grayvalues is large compared to that of
the display, we need to “compress” the
grayvalue range --- example: Fourier
transform magnitude.
 Typically we use a log scale.
s = T(r) = c log(1+r)
7/16/2015
Duong Anh Duc - Digital Image Processing
12
Compression of Dynamic
Range
Saturn Image
Mag. Spectrum
Mag. Spectrum
in log scale
7/16/2015
Duong Anh Duc - Digital Image Processing
13
Compression of Dynamic
Range
 Graylevel Slicing: Highlight a specific
range of grayvalues.
7/16/2015
Duong Anh Duc - Digital Image Processing
14
Compression of Dynamic
Range
 Example:
Highlighted Image (no background)
Original Image
Highlighted Image (with background)
7/16/2015
Duong Anh Duc - Digital Image Processing
15
Compression of Dynamic
Range
 Bitplane Slicing: Display the different
bits as individual binary images.
7/16/2015
Duong Anh Duc - Digital Image Processing
16
Compression of Dynamic
Range
7/16/2015
Duong Anh Duc - Digital Image Processing
17
Image Subtraction
 In this case, the difference between two
“similar” images is computed to highlight
or enhance the differences between
them:
g(m,n) = f1(m,n)-f2(m,n)
 It has applications in image segmentation
and enhancement
7/16/2015
Duong Anh Duc - Digital Image Processing
18
Example: Mask mode radiography
f1(m, n): Image before dye injection
f2(m, n): Image after dye injection
7/16/2015
g(m, n): Image after dye injection,
followed by subtraction
Duong Anh Duc - Digital Image Processing
19
Image Averaging for noise
reduction
 Noise is any random (unpredictable)
phenomenon that contaminates an image.
 Noise is inherent in most practical systems:
– Image acquisition
– Image transmission
– Image recording
 Noise is typically modeled as an additive process:
g(m,n) = f(m,n) + (m,n)
Noisy
Image
7/16/2015
Noise-free
Image
Duong Anh Duc - Digital Image Processing
Noise
20
Image Averaging for noise
reduction
 The noise h (m, n) at each pixel (m, n) is modeled
as a random variable.
 Usually, h (m, n) has zero-mean and the noise values
at different pixels are uncorrelated.
 Suppose we have M observations {gi(m, n)}, i=1, 2, …,
M, we can (partially) mitigate the effect of noise by
“averaging”
1
g m, n  
M
7/16/2015
M
 g m, n
i 1
i
Duong Anh Duc - Digital Image Processing
21
Image Averaging for noise
reduction
 In this case, we can show that:
E g m, n   f m, n 
1
Var g m, n  
Var  m, n 
M
 Therefore, as the number of observations
increases (M  ), the effect of noise
tends to zero.
7/16/2015
Duong Anh Duc - Digital Image Processing
22
Image Averaging Example
Noise-free Image
7/16/2015
Noisy Image
Noise Variance = 0.05
Duong Anh Duc - Digital Image Processing
23
Image Averaging Example
M =2
7/16/2015
M =5
Duong Anh Duc - Digital Image Processing
24
Image Averaging Example
M =10
7/16/2015
Duong Anh Duc - Digital Image Processing
M =25
25
Image Averaging Example
M =50
7/16/2015
Duong Anh Duc - Digital Image Processing
M =100
26
Some Averaging Filters
7/16/2015
Duong Anh Duc - Digital Image Processing
27
Histograms
 The histogram of a digital image with
grayvalues r0, r1, …, rL-1 is the discrete function
 nk
nk
prk   , where 
n
n
# pixels with value rk
total# pixelsin image
 The function p(rk) represents the fraction of
the total number of pixels with grayvalue rk.
 Histogram provides a global description of the
appearance of the image.
7/16/2015
Duong Anh Duc - Digital Image Processing
28
Histograms
 If we consider the grayvalues in the image
as realizations of a random variable R, with
some probability density, histogram provides
an approximation to this probability density.
In other words,
Pr[R=rk]  p(rk)
7/16/2015
Duong Anh Duc - Digital Image Processing
29
Some Typical Histograms
 The shape of a histogram provides useful
information for contrast enhancement.
7/16/2015
Duong Anh Duc - Digital Image Processing
30
Some Typical Histograms (cont.)
 The shape of a histogram provides useful
information for contrast enhancement.
7/16/2015
Duong Anh Duc - Digital Image Processing
31
Example: Histogram Stretching
The original image displayed
The histogram of the original image
10000
5000
0
0
The stretched image
0.5
1
The stretched histogram
10000
5000
0
0
7/16/2015
0.5
Duong Anh Duc - Digital Image Processing
1
32
Histogram Equalization
 Idea: find a non-linear transformation
g = T(f )
to be applied to each pixel of the input
image f(x,y), such that a uniform distribution
of gray levels in the entire range results for
the output image g(x,y).
7/16/2015
Duong Anh Duc - Digital Image Processing
33
Histogram Equalization
 Let us assume for the moment that the input
image to be enhanced has continuous
grayvalues, with r = 0 representing black and r = 1
representing white.
 We need to design a grayvalue transformation s =
T(r), based on the histogram of the input image,
which will enhance the image.
 As before, we assume that:
– T(r) is a monotonically increasing function for 0r1
(preserves order from black to white)
– T(r) maps [0,1] into [0,1] (preserves the range of
allowed grayvalues).
7/16/2015
Duong Anh Duc - Digital Image Processing
34
Histogram Equalization
7/16/2015
Duong Anh Duc - Digital Image Processing
35
Histogram Equalization
 Let us denote the inverse transformation by r =
T-1(s). We assume that the inverse transformation
also satisfies the above two conditions.
 We consider the grayvalues in the input image
and output image as random variables in the
interval [0, 1].
 Let pin(r) and pout(s) denote the probability density
of the grayvalues in the input and output images.
7/16/2015
Duong Anh Duc - Digital Image Processing
36
Histogram Equalization
 If pin(r) and T(r) are known, and T-1(s) satisfies
condition 1, we can write (result from probability
theory):
dr 

pout s    pin r  
ds  r T 1 s 

 One way to enhance the image is to design a
transformation T(.) such that the grayvalues in
the output is uniformly distributed in [0, 1], i.e.
pout(s)=1, 0 s1
7/16/2015
Duong Anh Duc - Digital Image Processing
37
Histogram Equalization
 In terms of histograms, the output image
will have all grayvalues in “equal
proportion.”
 This technique is called histogram
equalization.
 Consider the transformation
r
s  T r    pin wdw,
0  r 1
o
7/16/2015
Duong Anh Duc - Digital Image Processing
38
Histogram Equalization
 Note that this is the cumulative distribution
function (CDF) of pin(r) and satisfies the
previous two conditions.
 From the previous equation and using
the fundamental theorem of calculus,
ds
 pin r 
dr
7/16/2015
Duong Anh Duc - Digital Image Processing
39
Histogram Equalization
 Therefore, the output histogram is given by

1 
pout s    pin r 



p
r
in

 r T 1  s 
 1r T 1 s   1, for 0  s  1
 The output probability density function is
uniform, regardless of the input.
7/16/2015
Duong Anh Duc - Digital Image Processing
40
Histogram Equalization
 Thus, using a transformation function
equal to the CDF of input grayvalues r,
we can obtain an image with uniform
grayvalues.
 This usually results in an enhanced image,
with an increase in the dynamic range of
pixel values.
7/16/2015
Duong Anh Duc - Digital Image Processing
41
Example: Histogram Equalization
Original image Pout
7/16/2015
after histogram equalization
Duong Anh Duc - Digital Image Processing
42
Example: Histogram Equalization
7/16/2015
Duong Anh Duc - Digital Image Processing
43
Histogram Equalization
 For images with discrete grayvalues, we
have
nk
pin rk   , for 0  r  1, and 0  k  L  1
n
– L: Total number of graylevels
– nk: Number of pixels with grayvalue rk
– n: Total number of pixels in the image
7/16/2015
Duong Anh Duc - Digital Image Processing
44
Histogram Equalization
 The discrete version of the previous
transformation based on CDF is given by:
k
k
ni
sk  T rk      pin ri , for 0  k  L  1
i 0 n
i 0
7/16/2015
Duong Anh Duc - Digital Image Processing
45
Example
 Consider an 8-level
64 x 64 image with
grayvalues (0, 1, …,
7). The normalized
grayvalues are
(0, 1/7, 2/7, …, 1).
The normalized
histogram is given
in the table:
7/16/2015
k
rk
nk
0
1
0
1/7
790
1023
2
3
4
5
6
7
2/7
3/7
4/7
5/7
6/7
1
850
656
329
245
122
81
Duong Anh Duc - Digital Image Processing
p(rk)=
nk/n
0.19
0.25
0.21
0.16
0.08
0.06
0.03
0.02
46
Example(cont.)
7/16/2015
Duong Anh Duc - Digital Image Processing
47
Example(cont.)
 Applying the previous
transformation, we
have (after rounding off
to nearest graylevel):
0
s0  T r0    pin ri   pin r0   0.19  1
i 0
7
1
s1  T r1    pin ri   pin r0   pin r1   0.44  3
i 0
7
2
s2  T r2    pin ri   pin r0   pin r1   pin r2   0.65  5
i 0
7
3
s3  T r3    pin ri   pin r0   pin r1     pin r3   0.81  6
i 0
 Notice that there are
only five distinct
graylevels --- (1/7, 3/7,
5/7, 6/7, 1) in the output
image. We will relabel
them as (s0, s1, …, s4).
7/16/2015
7
4
s4  T r4    pin ri   pin r0   pin r1     pin r4   0.89  6
i 0
5
s5  T r5    pin ri   pin r0   pin r1     pin r5   0.95  1
i 0
6
s6  T r6    pin ri   pin r0   pin r1     pin r6   0.98  1
i 0
7
s7  T r7    pin ri   pin r0   pin r1     pin r7   1.00  1
i 0
Duong Anh Duc - Digital Image Processing
48
7
Example(cont.)
 With this transformation, the output image
will have histogram
7/16/2015
k
sk
nk
p(sk)=
nk/n
0
1
2
1/7
3/7
5/7
790
1023
850
0.19
0.25
0.21
3
4
6/7
1
985
448
0.24
0.11
Duong Anh Duc - Digital Image Processing
49
Example(cont.)
 Note that the histogram of output image is only
approximately, and not exactly, uniform. This should not be
surprising, since there is no result that claims uniformity in
the discrete case.
7/16/2015
Duong Anh Duc - Digital Image Processing
50
Example(cont.)
Original image
7/16/2015
Equalized image
Duong Anh Duc - Digital Image Processing
51
Example(cont.)
Histogram of original image
7/16/2015
Histogram of equalized image
Duong Anh Duc - Digital Image Processing
52
Example(cont.)
Original image
7/16/2015
Equalized image
Duong Anh Duc - Digital Image Processing
53
Example(cont.)
Histogram of original image
7/16/2015
Histogram of equalized image
Duong Anh Duc - Digital Image Processing
54
Example(cont.)
Original image
7/16/2015
Equalized image
Duong Anh Duc - Digital Image Processing
55
Example(cont.)
Histogram of original image
7/16/2015
Histogram of equalized image
Duong Anh Duc - Digital Image Processing
56
Example(cont.)
Original image
7/16/2015
Equalized image
Duong Anh Duc - Digital Image Processing
57
Example(cont.)-Histograms
Histogram of original image
7/16/2015
Histogram of equalized image
Duong Anh Duc - Digital Image Processing
58
Histogram Equalization
 Histogram equalization may not always produce
desirable results, particularly if the given histogram
is very narrow. It can produce false edges and
regions. It can also increase image “graininess”
and “patchiness.”
7/16/2015
Duong Anh Duc - Digital Image Processing
59
Histogram Specification
 Histogram equalization yields an image whose
pixels are (in theory) uniformly distributed among
all graylevels.
 Sometimes, this may not be desirable. Instead, we
may want a transformation that yields an output
image with a prespecified histogram. This
technique is called histogram specification.
 Again, we will assume, for the moment,
continuous grayvalues.
7/16/2015
Duong Anh Duc - Digital Image Processing
60
Histogram Specification
 Suppose, the input image has probability density pin(r). We
want to find a transformation z = H(r), such that the
probability density of the new image obtained by this
transformation is pout(z), which is not necessarily uniform.
 First apply the transformation
r
s  T r    pin wdw,
0  r 1
*
o
This gives an image with a uniform probability density.
7/16/2015
Duong Anh Duc - Digital Image Processing
61
Histogram Specification
 If the desired output image were available,
then the following transformation would
generate an image with uniform density:
z
  Gz    pout wdw,
0  z  1 * *
o
 From the grayvalues  we can obtain the
grayvalues z by using the inverse
transformation, z = G-1().
7/16/2015
Duong Anh Duc - Digital Image Processing
62
Histogram Specification
 If instead of using the grayvalues  obtained from (**), we
use the grayvalues s obtained from (*) above (both are
uniformly distributed!), then the point transformation
z = H(r) = G-1[T(r)]
will generate an image with the specified density pout(z),
from an input image with density pin(r)
 For discrete graylevels, we have
k
ni
sk  T rk    , for 0  k  L  1 and
i 0 n
k
 k  Gzk    pout zi , for 0  k  L  1
i 0
7/16/2015
Duong Anh Duc - Digital Image Processing
63
Histogram Specification
 If the transformation zk  G(zk) is one-toone, the inverse transformation sk  G-1(sk),
can be easily determined, since we are
dealing with a small set of discrete
grayvalues.
 In practice, this is not usually the case (i.e.,
zk  G(zk) is not one-to-one) and we assign
grayvalues to match the given histogram, as
closely as possible.
7/16/2015
Duong Anh Duc - Digital Image Processing
64
Ex.: Histogram Specification
 Consider the previous 8-graylevel 64 x 64 image
histogram:
k
r
n
p(r )=n /n
k
7/16/2015
k
k
k
0
0
790
0.19
1
1/7
1023
0.25
2
2/7
850
0.21
3
3/7
656
0.16
4
4/7
329
0.08
5
5/7
245
0.06
6
6/7
122
0.03
7
1
81
0.02
Duong Anh Duc - Digital Image Processing
65
Ex.: Histogram Specification
 It is desired to transform this image into a new image,
using a transformation z=H(r)= G-1[T(r)], with histogram as
specified below:
k
z
p (z )
k
7/16/2015
out
k
0
0
0.00
1
1/7
0.00
2
2/7
0.00
3
3/7
0.15
4
4/7
0.20
5
5/7
0.30
6
6/7
0.20
7
1
0.15
Duong Anh Duc - Digital Image Processing
66
Ex.: Histogram Specification
 The transformation T(r) was obtained earlier
(reproduced below):
7/16/2015
r i sk
nk
p(sk)
r0  s0 = 1/7
790
0.19
r1  s1 = 3/7
1023
0.25
r2  s2 = 5/7
850
0.21
r3,r4  s3 = 6/7
985
0.24
r5, r6,r7  s4=1
448
0.11
Duong Anh Duc - Digital Image Processing
67
Ex.: Histogram Specification
 Next we compute
the transformation
G as before
0
 0  G z0    pout zi   pout z0   0.00  0
i 0
1
 1  G z1    pout zi   pout z0   pout z1   0.00  0
i 0
2
 2  G z 2    pout zi   pout z0   pout z1   pout z2   0.00  0
i 0
3
 3  G z3    pout zi   pout z0   pout z1     pout z3   0.15  1 7
i 0
4
 4  G z 4    pout zi   pout z0   pout z1     pout z 4   0.35  2 7
i 0
5
 5  G z5    pout zi   pout z0   pout z1     pout z5   0.65  5 7
i 0
6
 6  G z6    pout zi   pout z0   pout z1     pout z6   0.85  6 7
i 0
7
 7  G z7    pout zi   pout z0   pout z1     pout z7   1.00  1
i 0
7/16/2015
Duong Anh Duc - Digital Image Processing
68
Ex.: Histogram Specification
 Notice that G is not invertible. But we will do the
best possible by setting
G-1(0) = ?
G-1(1/7) = 3/7
G-1(2/7) = 4/7
G-1(3/7) = 4/7
G-1(4/7) = ?
G-1(5/7) = 5/7
G-1(6/7) = 6/7
G-1(1) = 1
7/16/2015
(This does not matter since s0)
(This does not matter since s2/7)
(This is not defined, but we use a close match)
(This does not matter since s4/7)
Duong Anh Duc - Digital Image Processing
69
Ex.: Histogram Specification
 Combining the two transformation T and G-1, we get our
required transformation H
7/16/2015
rT(r)=s
sG-1(s)=z
rG-1 [T(r)]=H(r)=z
r0 = 0  1/7
0?
r0 = 0  z3= 3/7
r1 = 1/7  3/7
1/7  3/7
r1 = 1/7  z4= 4/7
r2 = 2/7  5/7
2/7  4/7
r2 = 2/7  z5= 5/7
r3 = 3/7  6/7
3/7  4/7
r3 = 3/7  z6= 6/7
r4 = 4/7  6/7
4/7  ?
r4 = 4/7  z6= 6/7
r5 = 5/7  1
5/7  5/7
r5 = 5/7  z7= 1
r6 = 6/7  1
6/7  6/7
r6 = 6/7  z7= 1
r7 = 1  1
1 1
r 7 = 1  z 7= 1
Duong Anh Duc - Digital Image Processing
70
Ex.: Histogram Specification
 Applying the transformation H to the original image yields
an image with histogram as below:
7/16/2015
k
zk
nk
nk/n
(actual hist.)
pout(zk)
(spec. hist.)
0
1
2
3
4
5
6
7
0
1/7
2/7
3/7
4/7
5/7
6/7
1
0
0
0
790
1023
850
985
448
0.00
0.00
0.00
0.19
0.25
0.21
0.24
0.11
0.00
0.00
0.00
0.15
0.20
0.30
0.20
0.15
Duong Anh Duc - Digital Image Processing
71
Ex.: Histogram Specification
7/16/2015
Duong Anh Duc - Digital Image Processing
72
Ex.: Histogram Specification
 Again, the actual histogram of the output
image does not exactly but only
approximately matches with the specified
histogram. This is because we are dealing
with discrete histograms.
7/16/2015
Duong Anh Duc - Digital Image Processing
73
Example
Original image and its histogram
7/16/2015
Duong Anh Duc - Digital Image Processing
74
Example
Histogram equalized image
7/16/2015
Actual histogram of output
Duong Anh Duc - Digital Image Processing
75
Example
Histogram specified image, Actual Histogram, and Specified Histogram
7/16/2015
Duong Anh Duc - Digital Image Processing
76
Enhancement Using
Local Histogram
 Used to enhance details over small portions of the image.
 Define a square or rectangular neighborhood, whose
center moves from pixel to pixel.
 Compute local histogram based on the chosen
neighborhood for each point and apply a histogram
equalization or histogram specification transformation to
the center pixel.
 Non-overlapping neighborhoods can also be used to
reduce computations. But this usually results in some
artifacts (checkerboard like pattern).
7/16/2015
Duong Anh Duc - Digital Image Processing
77
Enhancement Using
Local Histogram
 Another use of histogram information in image
enhancement is the statistical moments associated
with the histogram (recall that the histogram can
be thought of as a probability density function).
 For example, we can use the local mean and
variance to determine the local
brightness/contrast of a pixel. This information
can then be used to determine what, if any
transformation to apply to that pixel.
 Note that local histogram based operations are
non-uniform in the sense that a different
transformation is applied to each pixel.
7/16/2015
Duong Anh Duc - Digital Image Processing
78