Digital Image Processing
Digital Image Processing
Digital Image Processing
Lecture 2. Intensity
Transformation and Spatial
Filtering
Spring 2008
New Mexico Tech
domain
domain
01/15/15
g ( x, y ) T [ f ( x, y )])
f ( x, y ) : input image
g ( x, y ) : output image
T : an operator on f defined over
a neighborhood of point ( x, y)
01/15/15
01/15/15
01/15/15
01/15/15
Image Negatives
Image negatives
s L 1 r
01/15/15
Small
lesion
01/15/15
Log Transformations
Log Transformations
s c log(1 r )
01/15/15
01/15/15
10
s cr
01/15/15
11
01/15/15
12
sr
01/15/15
1/2.5
13
01/15/15
14
01/15/15
15
Piecewise-Linear Transformations
Contrast
Stretching
Intensity-level
Slicing
01/15/15
16
01/15/15
17
01/15/15
Measuring the
actual flow of the
contrast medium as
a function of time
in a series of
images
18
Bit-plane Slicing
01/15/15
19
Bit-plane Slicing
01/15/15
20
Bit-plane Slicing
01/15/15
21
Histogram Processing
Histogram Equalization
Histogram Matching
01/15/15
22
Histogram Processing
Histogram h( rk ) nk
rk is the k th intensity value
nk is the number of pixels in the image with intensity rk
nk
Normalized histogram p(rk )
MN
nk : the number of pixels in the image of
size M N with intensity rk
01/15/15
23
01/15/15
24
Histogram Equalization
The intensity levels in an image may be viewed as
random variables in the interval [0, L-1].
Let pr ( r ) and ps ( s) denote the probability density
function (PDF) of random variables r and s.
01/15/15
25
Histogram Equalization
s T (r )
0 r L 1
01/15/15
26
Histogram Equalization
s T (r )
0 r L 1
ps ( s)ds pr (r )dr
01/15/15
27
Histogram Equalization
r
s T (r ) ( L 1) pr ( w)dw
0
ds dT (r )
d
( L 1)
dr
dr
dr
pr ( w)dw
( L 1) pr ( r )
pr (r )dr pr (r )
1
pr (r )
ps ( s )
( L 1) pr (r ) L 1
ds
ds
dr
01/15/15
28
Example
Suppose that the (continuous) intensity values
in an image have the PDF
pr (r )
2r
,
2
( L 1)
0,
for 0 r L-1
otherwise
29
Example
r
s T (r ) ( L 1) pr ( w)dw
0
( L 1)
2w
dw
2
( L 1)
L 1
01/15/15
30
Histogram Equalization
Continuous case:
r
s T (r ) ( L 1) pr ( w)dw
0
Discrete values:
k
sk T (rk ) ( L 1) pr (rj )
j 0
nj
L 1 k
( L 1)
nj
MN j 0
j 0 MN
k
01/15/15
k=0,1,..., L-1
31
01/15/15
32
j 0
1
j 0
01/15/15
s2 4.55 5
s3 5.67 6
s4 6.23 6
s5 6.65 7
s6 6.86 7
s7 7.00 7
33
01/15/15
34
01/15/15
35
01/15/15
36
Question
Is histogram equalization always
good?
No
01/15/15
37
Histogram Matching
Histogram matching (histogram
specification)
Let pr ( r ) and
pz ( z ) denote
the continous
generate
a processed
image
that has aprobability
specified
histogram
density functions of the variables r and z. p ( z ) is the
z
s T ( r ) ( L 1) pr ( w) dw
0
G ( z ) ( L 1) p z (t ) dt s
0
01/15/15
38
Histogram Matching
r
s T (r ) ( L 1) pr ( w)dw
0
G ( z ) ( L 1) pz (t ) dt s
0
z G (s) G
01/15/15
T (r )
39
Obtain pr(r) from the input image and then obtain the
values of s
r
s ( L 1) pr ( w)dw
0
01/15/15
( s)
40
pr (r )
2r
,
2
( L 1)
0,
for 0 r L -1
otherwise
pz ( z )
01/15/15
3z 2
,
3
( L 1)
0,
for 0 z ( L -1)
otherwise
41
s T (r ) ( L 1) pr ( w)dw ( L 1)
r
2w
dw
2
( L 1)
L 1
( L 1)3
r
The transformation
z ( L 1) s function
( L 1)
01/15/15
1/3
( L 1) 2
1/3
( L 1) r
2 1/3
42
Obtain pr(rj) from the input image and then obtain the
values of sk, round the value to the integer range [0, L-1].
( L 1) k
sk T (rk ) ( L 1) pr (rj )
nj
MN j 0
j 0
k
G ( zq ) ( L 1) pz ( zi ) sk
i 0
Mapping from sk to zq zq
01/15/15
G 1 ( sk )
43
01/15/15
44
s0 1, s1 3, s2 5, s3 6, s4 7,
s5 7, s6 7, s7 7.
Compute all the values of the transformation function G,
0
G ( z0 ) 7 pz ( z j ) 0.00
j 0
G ( z1 ) 0.00
G ( z3 ) 1.05
G ( z7 ) 7.00
G ( z5 ) 4.55 5
01/15/15
0
G( z2 ) 0.00 0
G( z4 ) 2.45 2
G( z6 ) 5.95 6
45
01/15/15
46
s0 1, s1 3, s2 5, s3 6, s4 7,
s5 7, s6 7, s7 7.
Compute all the values of the transformation function G,
0
G ( z0 ) 7 pz ( z j ) 0.00
j 0
G ( z1 ) 0.00
G ( z3 ) 1.05
1 s0
G ( z5 ) 4.55 5
G ( z7 ) 7.00
01/15/15
s2
0
G( z2 ) 0.00 0
G( z4 ) 2.45 2 s1
G( z6 ) 5.95 6 s3
s4 s5 s6 s7
47
5
6
7
48
49
01/15/15
50
01/15/15
51
01/15/15
52
53
01/15/15
54
m ri p (ri )
i 0
MN
M 1 N 1
f ( x, y )
x 0 y 0
L 1
un (r ) (ri m) n p(ri )
i 0
Variance
L 1
u2 (r ) (ri
2
i 0
01/15/15
1
2
m) p (ri )
MN
M 1 N 1
x 0 y 0
f ( x, y ) m
55
01/15/15
2
s xy
L 1
i 0
56
g ( x, y )
f ( x, y ),
otherwise
01/15/15
57
Spatial Filtering
A spatial filter consists of (a) a neighborhood, and
(b) a predefined operation
Linear spatial filtering of an image of size MxN with
a filter of size mxn is given by the expression
g ( x, y )
w(s, t ) f ( x s, y t )
s a t b
01/15/15
58
Spatial Filtering
01/15/15
59
Spatial Correlation
The correlation of a filter w( x, y ) of size m n
with an image f ( x, y ), denoted as w( x, y) f ( x, y)
w( x, y )
f ( x, y )
w(s, t ) f ( x s, y t )
s a t b
01/15/15
60
Spatial Convolution
The convolution of a filter w( x, y) of size m n
with an image f ( x, y ), denoted as w( x, y) f ( x, y)
w( x, y )
f ( x, y )
w( s, t ) f ( x s, y t )
s a t b
01/15/15
61
01/15/15
62
01/15/15
63
g ( x, y )
w(s, t ) f ( x s, y t )
s a t b
w(s, t )
s a t b
where m 2a 1,
01/15/15
n 2b 1.
64
01/15/15
65
01/15/15
66
01/15/15
67
01/15/15
68
01/15/15
69
Foundation
Laplacian Operator
01/15/15
70
f
f ( x 1) f ( x)
x
2 f
f ( x 1) f ( x 1) 2 f ( x)
2
x
01/15/15
71
01/15/15
72
f
2
f 2 2
x
y
2 f
f ( x 1, y ) f ( x 1, y ) 2 f ( x, y )
2
x
2 f
f ( x, y 1) f ( x, y 1) 2 f ( x, y )
2
y
2 f f ( x 1, y ) f ( x 1, y ) f ( x, y 1) f ( x, y 1)
- 4 f ( x, y )
01/15/15
73
01/15/15
74
g ( x, y ) f ( x, y ) c 2 f ( x, y )
where,
f ( x, y ) is input image,
g ( x, y ) is sharpenend images,
c -1 if 2 f ( x, y ) corresponding to Fig. 3.37(a) or (b)
and c 1 if either of the other two filters is used.
01/15/15
75
01/15/15
76
Unsharp masking
Sharpen images consists of subtracting an unsharp
(smoothed) version of an image from the original image
e.g., printing and publishing industry
Steps
1. Blur the original image
2. Subtract the blurred image from the original
3. Add the mask to the original
01/15/15
77
01/15/15
78
01/15/15
79
01/15/15
80
f
x
f
y
M ( x, y ) mag(f ) g x 2 g y 2
81
M ( x, y ) | g x | | g y |
z1 z2 z3
z4 z5 z6
M ( x, y ) | z8 z5 | | z6 z5 |
z7 z8 z9
01/15/15
82
z1 z2 z3
Sobel Operators
M ( x, y ) | ( z7 2 z8 z9 ) ( z1 2 z2 z3 ) |
| ( z3 2 z6 z9 ) ( z1 2 z4 z7 ) |
z4 z5 z6
z7 z8 z9
01/15/15
83
01/15/15
84
Example
01/15/15
85
Example:
Combining
Spatial
Enhancement
Methods
Goal:
Enhance the
image by
sharpening it
and by
bringing out
more of the
skeletal detail
01/15/15
86
Example:
Combining
Spatial
Enhancement
Methods
Goal:
Enhance the
image by
sharpening it
and by
bringing out
more of the
skeletal detail
01/15/15
87