Digital Image Processing
Chapter 3: Intensity Transformations
and Spatial Filtering
Background
Spatial domain process
g ( x, y) = T [ f ( x, y)]
⚫ where f ( x, y) is the input image, g ( x, y )
is the processed image, and T is an
operator on f, defined over some
neighborhood of ( x, y )
Neighborhood about a point
Gray-level transformation function
s = T (r )
⚫ where r is the gray level of f ( x, y) and
s is the gray level of g ( x, y ) at any
point ( x, y )
Contrast enhancement
⚫ For example, a thresholding function
Masks (filters, kernels, templates,
windows)
⚫ A small 2-D array in which the values
of the mask coefficients determine the
nature of the process
Some Basic Gray Level
Transformations
Image negatives
s = L −1 − r
⚫ Enhance white or gray details
Log transformations
s = c log(1 + r )
⚫ Compress the dynamic range of images
with large variations in pixel values
⚫ From the range 0-1.5 10 6 to the range
0 to 6.2
Power-law transformations
s = cr or s = c(r + )
⚫ 1 maps a narrow range of dark
input values into a wider range of
output values, while 1 maps a
narrow range of bright input values into
a wider range of output values
⚫ : gamma, gamma correction
Monitor, = 2.5
Piecewise-linear transformation
functions
⚫ The form of piecewise functions can be
arbitrarily complex
⚫ Contrast stretching
⚫ Gray-level slicing
⚫ Bit-plane slicing
Histogram Processing
Histogram
h(rk ) = nk
⚫ where rk is the kth gray level and nkis
the number of pixels in the image
having gray level rk
⚫ Normalized histogram
p(rk ) = nk / n
Histogram equalization
s = T (r ), 0 r 1
r = T −1 ( s), 0 s 1
⚫ Probability density functions (PDF)
dr
p s ( s ) = pr ( r )
ds
r
s = T (r ) = ( L − 1) pr (w)dw
0
ds dT (r ) d r = ( L − 1) p (r )
dr
=
dr
= ( L − 1)
dr
0
pr ( w) dw
r
1
ps ( s ) =
L −1
k k nj
sk = T (rk ) = ( L − 1) pr (rj ) =( L − 1) , k = 0,1,2,..., L − 1
j =0 j =0 n
Histogram matching (specification)
r
s = T (r ) = ( L − 1) pr (w)dw
0
z
G( z ) = ( L − 1) pz (t )dt = s
0
z = G −1 ( s) = G −1[T (r )]
pz (z ) is the desired PDF
k k nj
sk = T (rk ) = ( L − 1) pr (rj ) = ( L − 1) , k = 0,1,2,..., L − 1
j =0 j =0 n
k
vk = G ( zk ) = ( L − 1) p z ( zi ) =sk , k = 0,1,2,..., L − 1
i =0
zk = G −1[T (rk )], k = 0,1,2,..., L − 1
Histogram matching
⚫ Obtain the histogram of the given
image, T(r)
⚫ Precompute a mapped level sk for each
level rk
⚫ Obtain the transformation function G
from the given pz (z )
⚫ Precompute z k for each value of sk
⚫ Map rk to its corresponding level sk ;
then map level sk into the final level z k
Local enhancement
⚫ Histogram using a local neighborhood,
for example 7*7 neighborhood
⚫ Histogram using a local 3*3
neighborhood
Use of histogram statistics for
image enhancement
⚫ r denotes a discrete random variable
⚫ p(ri ) denotes the normalized
histogram component corresponding to
the ith value of r
⚫ Mean L −1
m = ri p (ri )
i =0
⚫ The nth moment
L −1
n (r ) = (ri − m) n p(ri )
i =0
⚫ The second moment
L −1
2 (r ) = (ri − m) 2 p(ri )
i =0
⚫ Global enhancement: The global mean
and variance are measured over an
entire image
⚫ Local enhancement: The local mean
and variance are used as the basis for
making changes
⚫ rs ,t is the gray level at coordinates
(s,t) in the neighborhood
⚫ p(rs ,t ) is the neighborhood normalized
histogram component
⚫ mean:
mS xy = r s ,t
( s ,t )S xy
p(rs ,t )
⚫ local variance
S2 =
xy s,t S xy p(rs,t )
[ r − m
( s ,t )S xy
]2
⚫ E , k0 , k1 , k2 are specified parameters
⚫ M G is the global mean
⚫ DG is the global standard deviation
⚫ Mapping
if mS xy k0 M G
E f ( x, y )
g ( x, y ) = and k1DG S xy k2 DG
f ( x, y ) otherwise
Fundamentals of Spatial Filtering
The Mechanics of Spatial Filtering
R = w(−1,−1) f ( x − 1, y − 1) +
w(−1,0) f ( x − 1, y ) + +
w(0,0) f ( x, y ) + +
w(1,0) f ( x + 1, y ) +
w(1,1) f ( x + 1, y + 1)
⚫ Image size: M N
⚫ Mask size: m n
a b
g ( x, y ) = w(s, t ) f ( x + s, y + t )
s = − at = − b
⚫ a = (m − 1) / 2 and b = (n − 1) / 2
⚫ x = 0,1,2,..., M − 1 and y = 0,1,2,..., N − 1
Spatial Correlation and Convolution
Vector Representation of Linear
Filtering
R = w1 z1 + w2 z 2 + ... + w9 z9
9
= wi zi
i =1
Smoothing Spatial Filters
Smoothing Linear Filters
⚫ Noise reduction
⚫ Smoothing of false contours
⚫ Reduction of irrelevant detail
1 9
R = zi
9 i =1
a b
w(s, t ) f ( x + s, y + t )
g ( x, y ) = s = − at = − b
a b
w(s, t )
s = − at = − b
Order-statistic filters
⚫ median filter: Replace the value of a
pixel by the median of the gray levels
in the neighborhood of that pixel
⚫ Noise-reduction
Sharpening Spatial Filters
Foundation
⚫ The first-order derivative
f
= f ( x + 1) − f ( x)
x
⚫ The second-order derivative
f
2
= f ( x + 1) + f ( x − 1) − 2 f ( x)
x 2
Use of second derivatives for
enhancement-The Laplacian
⚫ Development of the method
f f
2 2
f = 2 + 2
2
x y
f
2
= f ( x + 1, y) + f ( x − 1, y) − 2 f ( x, y)
x 2
2 f
= f ( x, y + 1) + f ( x, y − 1) − 2 f ( x, y)
y 2
2 f = [ f ( x + 1, y ) + f ( x − 1, y ) + f ( x, y + 1) +
f ( x, y − 1)] − 4 f ( x, y )
if the center coefficien t
f ( x, y ) − 2 f ( x, y ) of the Laplacian mask
is negative
g ( x, y ) =
if the center coefficien t
f ( x, y ) + 2 f ( x, y ) of the Laplacian mask
is positive
⚫ Simplifications
g ( x, y ) = f ( x, y ) − [ f ( x + 1, y ) + f ( x − 1, y) + f ( x, y + 1) +
f ( x, y − 1)] + 4 f ( x, y)
= 5 f ( x, y) − [ f ( x + 1, y ) + f ( x − 1, y ) + f ( x, y + 1) +
f ( x, y − 1)]
Unsharp masking and highboost
filtering
⚫ Unsharp masking
Substract a blurred version of an image
from the image itself
g mask ( x, y) = f ( x, y) − f ( x, y)
f ( x, y) : The image, f ( x, y ) : The
blurred image
g ( x, y) = f ( x, y) + k * g mask ( x, y) ,k =1
⚫ High-boost filtering
g ( x, y) = f ( x, y) + k * g mask ( x, y) ,k 1
Using first-order derivatives for
(nonlinear) image sharpening—The
gradient
f
Gx x
f = = f
G y
y
⚫ The magnitude is rotation invariant
(isotropic)
f = mag (f ) = G + G2
x
2
y
1
2
1
f 2 f 2 2
= +
x y
f G x + G y
⚫ Computing using cross differences,
Roberts cross-gradient operators
G x = ( z9 − z5 ) and Gy = ( z8 − z6 )
f = ( z9 − z5 ) + ( z8 − z6 )
2 2
1
2
f z9 − z5 + z8 − z6
⚫ Sobel operators
A weight value of 2 is to achieve some
smoothing by giving more importance to
the center point
f ( z7 + 2 z8 + z9 ) − ( z1 + 2 z2 + z3 )
+ ( z3 + 2 z6 + z9 ) − ( z1 + 2 z4 + z7 )
Combining Spatial Enhancement
Methods
An example
⚫ Laplacian to highlight fine detail
⚫ Gradient to enhance prominent edges
⚫ Smoothed version of the gradient
image used to mask the Laplacian
image
⚫ Increase the dynamic range of the gray
levels by using a gray-level
transformation