Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

Chapter 3 : Image

Enhancement in the Spatial


Domain

CCU, Taiwan
Wen-Nung Lie
Backgrounds
„ Spatial domain methods are procedures that operate
directly on pixels
g ( x, y ) = T [ f ( x, y )]
„ Neighborhood about a point (x,y)
„ Neighborhood = 1×1Æ point processing or contrast stretching
„ Larger neighborhood Æ mask processing

CCU, Taiwan
Wen-Nung Lie 3-1
Some basic point
transformations
„ Implemented by look-up
tables
„ Functions
„ Linear (negative and
identity)
„ Logarithmic (log and
inverse log)
s = c log(1 + r )
„ Power-law (nth power and
nth root)
s = cr γ or s = c( r + ε ) γ
CCU, Taiwan
Wen-Nung Lie 3-2
„ Log transform
„ Expand the dynamic range of low gray-levels values
„ Compress the dynamic range of images with large variations in
pixel values
„ Power-law transformation
„ Curves generated with γ > 1 have exactly the opposite effect as
those generated with γ < 1

CCU, Taiwan
Wen-Nung Lie 3-3
Gamma correction
„ A variety of devices used for image capture,
printing, and display respond according to a power
law
„ The process used to correct the power-law
response phenomena is called gamma correction
„ CRT has an intensity-to-voltage response of γ = 1.8 ~ 2.5
Æ produce images that are darker1 than intended
Æ preprocess the images with γ 2.5 = γ 0.4 before
inputting it into the monitor
„ Current image standards do not contain the value
of gamma with which an image was created
CCU, Taiwan
Wen-Nung Lie 3-4
CCU, Taiwan
Wen-Nung Lie 3-5
Power-law transformation for
contrast manipulation

CCU, Taiwan
Wen-Nung Lie 3-6
Piecewise-linear
transformation
„ The form of piecewise functions can be arbitrarily complex
„ Contrast stretching – increase the dynamic range of images
being processed

CCU, Taiwan
Wen-Nung Lie 3-7
Graylevel slicing & bit-plan
slicing

CCU, Taiwan
Wen-Nung Lie 3-8
Bit-plane decomposition

1. The MSB plane contains the majority of information

CCU, Taiwan 2. The LSB plane are likely random


Wen-Nung Lie 3-9
Histogram processing
„ Histogram
„ A discrete function h(rk ) = nk , where rk is the kth
graylevel and nk is the number of pixels in the image
having graylevel rk
„ A normalized histogram is given by
p (rk ) = nk / n
where n is the total number of image pixels
„ An image with low contrast has a narrow histogram
„ A high contrast image tends to occupy the entire range
of graylevels and be distributed uniformly

CCU, Taiwan
Wen-Nung Lie 3-10
Histogram equalization
„ Point transformation
„ s = T (r ), 0 ≤ r ≤1
„ Single-valued
„ Monotonically increasing

„ Modify the image histogram, via point


transformation r Æ s, such that its shape is
approximately flat
„ Cdf (cumulative distribution function)
transformation
CCU, Taiwan
Wen-Nung Lie 3-11
Histogram equalization (cont.)
r
s = T (r ) = ∫ pr ( w)dw
0

dr
p s ( s ) = pr ( r )
ds
ps ( s ) = 1, 0 ≤ s ≤1 Uniform distribution

„ Discrete implementation
k n k
s = T (r ) = ∑ p (r ) = ∑ , k = 0,1,..., L − 1
j
k k r j
j =0 n j =0

„ Each pixel with graylevel rk is mapped into sk


in the output image
CCU, Taiwan
Wen-Nung Lie 3-12
Histogram equalization (cont.)

Histogram equalization is a nonlinear


(non-uniform) stretching technique, it
stretches the histogram as flat as
possible (approximating a linear cdf
function)

CCU, Taiwan
Wen-Nung Lie 3-13
Histogram matching
(specification)
„ Transform the image such that it has an
approximately desired histogram shape
„ Given pr (rk ) and p z ( z j ) (input and desired output),
compute
k h
sk = ∑ pr ( r j ) vh = ∑ p z ( z j )
j =0 j =0

for a value of k, find a smallest h such that vh ≥ sk .


Then transform k into h (0≤h,k≤255).
Histogram specification is a trial-and-error process, there
CCU, Taiwan are no rules for specifying histograms
Wen-Nung Lie 3-14
Specified histogram

result

CCU, Taiwan original 3-15


Wen-Nung Lie
Spatial filtering
„ Filtering in the spatial domain by convolution
directly on the pixels
„ Need a filter mask (or the impulse response) for
operation
„ Calculate the response at each point (x, y) (i.e., slide the
filter mask from point to point)
„ The mask is often of odd size (2a+1)×(2b+1), e.g. 3×3
„ Filtering by FFT and manipulation in the
frequency domain

CCU, Taiwan
Wen-Nung Lie 3-23
Linear spatial filtering

a b
g ( x, y ) = ∑ ∑ w( s , t ) f ( x + s , y + t )
s = − at = − b

Nonlinear spatial filtering :


operations that can not be
represented by sum-of-products

How to manage the boundary problem ?

CCU, Taiwan
Wen-Nung Lie 3-24
Smoothing spatial filter
„ Used for blurring and noise reduction
„ Also called averaging filter or lowpass filter
„ Two 3×3 examples
„ The division scale factor is equal to sum of the coefficients
(avoiding overflow) and had better be a power of 2
„ weighted average
„ the weight decreases as the distance to the center pixel increases
Discrete Gaussian averaging with variance σ
2
„

a b
1 1 1 1 2 1
∑ ∑ w( s , t ) f ( x + s , y + t )
1/9 1 1 1 1/16 2 4 2 g ( x, y ) = s = − at = − b
a b
1 1 1 1 2 1 ∑ ∑ w( s , t )
s = − at = − b

CCU, Taiwan
Wen-Nung Lie 3-25
„ More larger the window, more blurring effect it has
„ More flat the coefficients are, more blurring they result in

CCU, Taiwan
Wen-Nung Lie 3-26
Order-statistics (Median) filter
„ Nonlinear spatial filter whose response is based on
ordering (ranking) the pixels contained in the window
„ effective to eliminate impulse noise or salt-and-pepper noise,
with considerably less blurring than linear smoothing filter
„ eliminate noise less than half of the window size
„ 1-D or 2-D window size

Original noisy Low-pass filter Median filter


CCU, Taiwan
Wen-Nung Lie 3-27
Sharpening spatial filter
„ To highlight fine detail in an image
„ Image differentiation (1st and 2nd-order
derivatives) enhances edges and other
discontinuities
„ digital 1st-order derivative of 1-D signal
∂f ∂2 f
= f ( x + 1) − f ( x ) = f ( x + 1) + f ( x − 1) − 2 f ( x )
∂x ∂x 2
„ we can expect a 2nd order derivative to enhance fine
detail much more than a 1st-order derivative

CCU, Taiwan
Wen-Nung Lie 3-28
2nd-order derivative --
Laplacian operator
„ Isotropic filter -- whose response is independent of the
direction of the discontinuities in the image, or rotation-
invariant
„ The Laplacian is the simplest isotropic derivative operator
∂2 f ∂2 f
∇ f = 2 + 2
2
0 -1 0 -1 -1 -1
∂x ∂y
-1 4 -1 -1 8 -1
∂2 f
= f ( x + 1, y ) + f ( x − 1, y ) − 2 f ( x, y )
∂x 2
0 -1 0 -1 -1 -1

∂2 f
= f ( x, y + 1) + f ( x, y − 1) − 2 f ( x, y ) Digital Laplacian
∂y 2

∇ 2 f = [ f ( x + 1, y ) + f ( x − 1, y ) + f ( x, y + 1) + f ( x, y − 1)] − 4 f ( x, y )
CCU, Taiwan
Wen-Nung Lie 3-29
Use of Laplacian for
sharpening enhancement
„ Sharpening enhancement -- add the Laplacian response to
the original image
g ( x, y ) = f ( x, y ) ± ∇ 2 f ( x, y )

g ( x, y ) = f ( x, y ) + ∇ 2 f ( x, y )
0 -1 0 = 5 f ( x, y ) − [ f ( x + 1, y ) + f ( x − 1, y )
-1 5 -1 + f ( x, y + 1) + f ( x, y − 1)]
0 -1 0

-1 -1 -1

-1 9 -1

-1 -1 -1 Sharpening -- Enhance the high


frequency component
CCU, Taiwan
Wen-Nung Lie 3-30
Unsharp masking & high-
boost filtering
„ Unsharp masking – in publishing industry
f s ( x, y ) = f ( x, y ) − f ( x, y ) Sharpening – reduce the low
frequency component
„ High-boost filtering
f hb ( x, y ) = Af ( x, y ) − f ( x, y ) A ≥1
= ( A − 1) f ( x, y ) + f s ( x, y )
If we select
= Af ( x, y ) ± ∇ f ( x, y )
2
f s ( x, y ) = f ( x, y ) ± ∇ 2 f ( x, y )

0 -1 0 -1 -1 -1 The sharpening
-1 A+4 -1 -1 A+8 -1
effect decreases as
A increases
0 -1 0 -1 -1 -1
CCU, Taiwan
Wen-Nung Lie 3-31
Application of high-boost
filtering
„ Sharpen the image and simultaneously
brighten it

CCU, Taiwan
Wen-Nung Lie A=1 A=1.7 3-32
Use of 1st-order derivative
„ Gradient vector ⎡ ∂f ⎤
⎡Gx ⎤ ⎢ ∂x ⎥
∇f = ⎢ ⎥ = ⎢ ∂f ⎥
⎣G y ⎦ ⎢ ⎥
⎢⎣ ∂y ⎥⎦
„ Gradient magnitude
1
∇f = mag (∇f ) = [G + G ]2
x
2 2
y

∂f 2 ∂f 2 12
= [( ) + ( ) ]
„ Approximation ∂x ∂y

∇f ≈ G x + G y
CCU, Taiwan
Wen-Nung Lie 3-33
Popular gradient operators
-1 0 0 -1
„ Roberts cross-gradient operators
0 1 1 0
„ Sobel gradient operator
-1 -2 -1 -1 0 1 The coefficients sum to zero, to
0 0 0 -2 0 2
yield zero on flat areas

1 2 1 -1 0 1

CCU, Taiwan
Wen-Nung Lie Laplacian operator Sobel operator 3-34
Combining spatial
enhancement methods
„ Use Laplacian to highlight fine detail
„ also produce noiser results than the gradient
„ Use gradient to enhance prominent edges
„ The gradient has a stronger response in ramps and steps areas than
does the Laplacian
„ The response of the gradient to noise is lower than Laplacian
„ The response to noise can be lowered by smoothing the gradient
with an averaging filter
„ Combining Laplacian and gradient operators
„ smooth the gradient and multiply it by the Laplacian image
(preserve details in the strong areas while reducing noise in the flat
areas)
„ The above result is added to the original image
CCU, Taiwan
Wen-Nung Lie 3-35
Smoothed gradient Product of Laplacian
original Laplacian by 5x5 window and smoothed gradient

sharpening Sobel gradient final sharpening increase DR


CCU, Taiwan
with γ=0.5 3-36
Wen-Nung Lie

You might also like