Nothing Special   »   [go: up one dir, main page]

Lecture 4-Image - Enhancement in Spatial Filtering

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 25

Advanced Image Processing

Md. Shafiqul Islam


Assistant Professor
Department of CSE, DUET
Basics of Spatial Filtering
• In spatial filtering (vs. frequency domain filtering), the output image is
computed directly by simple calculations on the pixels of the input image.
• Spatial filtering can be either linear or non-linear.
• For each output pixel, some neighborhood of input pixels is used in the
computation.
• In general, linear filtering of an image f of size MXN with a filter mask of
size mxn is given by
a b
g ( x, y )    w( s, t ) f ( x  s, y  t )
s   at   b

where a=(m-1)/2 and b=(n-1)/2


• This concept called convolution. Filter masks are sometimes called
convolution masks or convolution kernels.
Basics of Spatial Filtering
Basics of Spatial Filtering
• Nonlinear spatial filtering usually uses a neighborhood too,
but some other mathematical operations are use. These can
include conditional operations (if …, then…), statistical
(sorting pixel values in the neighborhood), etc.
• Because the neighborhood includes pixels on all sides of the
center pixel, some special procedure must be used along the
top, bottom, left and right sides of the image so that the
processing does not try to use pixels that do not exist.
Smoothing Spatial Filters
• Smoothing linear filters
– Averaging filters (Lowpass filters)
• Box filter
• Weighted average filter

Box filter Weighted average


Smoothing Spatial Filters
• The general implementation for filtering an MXN image with
a weighted averaging filter of size mxn is given by

a b

  w (s, t ) f ( x  s, y  t )
g ( x, y )  s  at  b
a b

  w(s, t)
s  at  b

where a=(m-1)/2 and b=(n-1)/2


Image Filtering
• For example, the image is:
17 24 1 8 15
23 5 7 14 16
x  4 6 13 20 22
10 12 19 21 3
11 18 25 2 9

• The correlation kernel is:


8 1 6
w3 5 7
4 9 2
Image Filtering
• Rotate the correlation kernel 180 degrees about its center
element to create a convolution kernel.
• Slide the center element of the convolution kernel so that it
lies on top of the (2,4) element of A.
• Multiply each weight in the rotated convolution kernel by the
pixel of A underneath.
• Sum the individual products from step 3.
Image Filtering

• Hence the (2,4) output pixel is:


1.2+8.9+15.4+7.7+14.5+16.3+20.1+22.8=575
Smoothing Spatial Filters
Image smoothing with masks of various sizes
Smoothing Spatial Filters
Another Example
Order-Statistic Filters
• Order-statistic filters
– Median filter: to reduce impulse noise (salt-and-
pepper noise)
Sharpening Spatial Filters
• Sharpening filters are based on computing spatial
derivatives of an image.
• The first-order derivative of a one-dimensional
function f(x) is f
 f ( x  1)  f ( x)
x
• The second-order derivative of a one-dimensional
function f(x) is  2 f
2
 f ( x  1)  f ( x  1)  2 f ( x)
x
Sharpening Spatial Filters
An Example
Use of Second Derivatives for Enhancement
The Laplacian
• Development of the Laplacian method
– The two dimensional Laplacian operator for continuous
functions: 2 f 2 f
2 f  2

x y 2
– The Laplacian is a linear operator.
2 f
 f ( x  1, y )  f ( x  1, y )  2 f ( x, y )
x 2
2 f
2
 f ( x, y  1)  f ( x, y  1)  2 f ( x, y )
y

 2 f  [ f ( x  1, y)  f ( x  1, y)  f ( x, y  1)  f ( x, y  1)]  4 f ( x)
Use of Second Derivatives for Enhancement
The Laplacian
Use of Second Derivatives for Enhancement
The Laplacian

• To sharpen an image, the Laplacian of the image is subtracted


from the original image.
 f ( x, y )   2 f if the center coefficient of the Laplacian mask is negative.
g ( x, y )   2
 f ( x, y )   f if the center coefficient of the Laplacian mask is positive.

• Example: Figure 3.40


Use of Second Derivatives for Enhancement
The Laplacian: Simplifications

The g(x,y) mask


Not only  2 f
Use of First Derivatives for Enhancement
The Gradient
• Development of the Gradient method
– The gradient of function f at coordinates (x,y) is defined as
the two-dimensional column vector:
 f 
Gx   x 
f      f 
G y   
 y 
– The magnitude of this vector is given by
1
 f  2  f  2
 2
 
1
2 2 2
f  mag(f )  G  Gx y       
 x   y  
f  G x  G y
Use of First Derivatives for Enhancement
The Gradient

Roberts cross-gradient
operators

Sobel
operators
Use of First Derivatives for Enhancement
The Gradient: Using Sobel Operators
Combining Spatial
Enhancement Methods
Combining Spatial
Enhancement Methods

You might also like