UNIT-II: Image Enhancement in Spatial Domain
Presented by:
Shahnawaz Uddin
DIGITAL IMAGE
PROCESSING (WLE-306)
Spatial domain process
where is the input image, is the processed image, and T is an operator on f,
defined over some neighborhood of
)]
, ( [ )
,
( x y T f x y
g
) , ( x y
f
g(x, y)) , (x y
Intensity Transformations and Spatial Filtering
• Intensity transformations operate on single pixel of an image, principally for the purpose of contrast manipulation
& image thresholding
• Spatial Filtering deals with performing operations, such as image sharpening by working in a neighborhood of every pixel in an image
Neighborhood about a point
Intensity Transformations and
Spatial Filtering
Gray-level transformation function
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)
)
(r
T
s
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
Enhance white or gray details
r L
s 1
Log transformations:
where, c is a constant, and r≥0
This transformation maps a narrow range of low intensity values into a wider range of output levels and opposite is true of higher values of input levels, (i.e., to expand the values of dark pixels while
compressing the higher values in an image)
Compress the dynamic range of images with large variations in pixel values
The inverse logarithm transformation does the inverse of the log transformation
) 1
log( r c
s
From the range 0- to the range 0 to 6.2
10
65 .
1
Power-law transformations:
or
maps a narrow range of dark input values into a wider range of output values, while maps a
narrow range of bright input values into a wider range of output values
: gamma, gamma correction
cr
s s c ( r )
1
1
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
where rk is the kth gray level and nk is the number of pixels in the image having gray level rk
Normalized histogram
k
k
n
r
h ( )
n n
r
p (
k)
k/
Histogram Equalization
1 0
),
(
T r r L s
1 0
),
1(
T s s L r
• Here, we focus our attention on transformations of the from
that produce an output intensity level s for every pixel in the input image having intensity r. We assume that:
(a)T(r) is monotonically increasing function in 0<= r <= L-1 and (b) 0<= T(r) <= L-1 for 0<= r <= L-1
In some formulations, we use the inverse
in which case, we change condition (a) to (a’)
(a’) T(r) is strictly monotonically
increasing function in 0<= r <= L-1
Probability density functions (PDF)
ds r dr p
s
p
s( )
r( )
T r L
rp
rw dw s ( ) ( 1 )
0( )
) ( )
1 (
) ( )
1 ) (
(
0
p w dw L p r
dr L d
dr r dT dr
ds
r r
r
1 ) 1
(
s L
p
s1 ,...,
2 , 1 , 0
, )
1 (
) ( )
1 (
) (
0 0
L n k
L n r
p L
r T s
k
j k j
j
j r k
k
• For the discrete form of transformation, the histogram equalization transformation is given by:
• Inverse Transformation from s back to r is denoted by
The method used to generate a processed image that has a specified histogram is called histogram matching/specification.
T r L
rp
rw dw s ( ) ( 1 )
0( )
L
zp
zt dt s z
G ( ) ( 1 )
0( )
)]
( [ )
(
11
s G T r
G
z
) ( z
p
z is the desired PDFHistogram Matching (Specification)
1 ,...,
2 , 1 , 0
, )
1 (
) ( )
1 (
) (
0 0
L n k
L n r
p L
r T s
k
j k j
j
j r k
k
1 ,...,
2 , 1 , 0
, )
( )
1 (
) (
0
L k
s z
p L
z G
v
kk
i
i z k
k
1 ,...,
2 , 1 , 0
)], (
1
[
G
T r k L
z
k k
Histogram matching
Obtain the histogram of the given image, T(r)
Precompute a mapped level for each level
Obtain the transformation function G from the given
Precompute for each value of
Map to its corresponding level ; then map level into the final level
) ( z p
zs
kr
kz
ks
kr
ks
ks
kz
kExample 3.8: A simple example of
histogram matching/specification
Histogram Matching (Specification)
Local enhancement
Histogram using a local neighborhood, for example 7*7 neighborhood
Histogram using a local 3*3 neighborhood
Fundamentals of Spatial Filtering
The Mechanics of Spatial Filtering
Image size:
Mask size:
and
and
N M
n m
aa s
b
b t
t y
s x
f t s w y
x
g ( , ) ( , ) ( , )
2 / ) 1
(
m
a b ( n 1 ) / 2 1
,..., 2
, 1 ,
0
M
x y 0 , 1 , 2 ,..., N 1
Spatial Correlation and Convolution
Vector Representation of Linear Filtering
Generating Spatial Filter Masks
Smoothing Spatial Filters
Smoothing Linear Filters
Noise reduction
Smoothing of false contours
Reduction of irrelevant detail that is smaller than the filter mask
Blurring the edges in an image
91 9
1
16
1 9
1
i
i i
i
and R z
z R
To reduce the blurring effect during smoothing filtering
aa s
b
b t a
a s
b
b t
t s w
t y
s x
f t s w y
x g
) , (
) ,
( ) , ( )
,
(
Order-statistic (Non-linear) spatial filters
median filter: Replace the value of a pixel by the median of the gray levels in the
neighborhood of that pixel
Noise-reduction
Note:
Sharpening Spatial Filters
Foundation
The first-order derivative
The second-order derivative
) ( )
1
( x f x
x f
f
) ( 2 )
1 (
) 1
2
(
2
x f x
f x
x f
f
Use of second derivatives for enhancement-The Laplacian
Development of the method
) , ( 2 )
, 1 (
) , 1
2
(
2
y x f y
x f y
x x f
f
2 2 2
2 2
y f x
f f
) , ( 2 )
1 ,
( )
1 ,
2
(
2
y x f y
x f y
x y f
f
) , ( 4 )]
1 ,
(
) 1 ,
( )
, 1 (
) , 1 (
2
[
y x f y
x f
y x f y
x f y
x f f
positive is
mask Laplacian
the of
t coefficien center
the if
) , ( )
, (
negative is
mask Laplacian
the of
t coefficien center
the if
) , ( )
, ( )
, (
2 2
y x f y
x f
y x f y
x f y
x
g
Note:
Simplifications
)]
1 ,
(
) 1 ,
( )
, 1 (
) , 1 (
[ )
, ( 5
) , ( 4 )]
1 ,
(
) 1 ,
( )
, 1 (
) , 1 (
[ )
, ( )
, (
y x f
y x f y
x f y
x f y
x f
y x f y
x f
y x f y
x f y
x f y
x f y
x
g
Unsharp masking and highboost filtering
Unsharp masking
Substract a blurred version of an image from the image itself
: The image, : The blurred image
) , ( )
, ( )
,
( x y f x y f x y
g
mask
) , ( x y
f f ( x , y ) ) , (
* )
, ( )
,
( x y f x y k g x y
g
mask, k 1
High-boost filtering
) , (
* )
, ( )
,
( x y f x y k g x y
g
mask, k 1
Salt-and-pepper noise in an image