You are on page 1of 53

Advanced Image Processing

Spatial Filtering

CSE 535 Advanced Image Processing

Asif Khan, PhD


asifkhan@giki.edu.pk
http://www.giki.edu.pk/Faculty/Dr-Asif-Khan

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Contents
Spatial domain
Intensity transformation
Basic functions
Histogram processing
Spatial filtering

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Spatial
The image plane or direct manipulation of pixels
g(x,y) = T[f(x,y)]

Spatial filtering (Chap 3)


Operate on a neighborhood of a pixel
Filter, mask, kernel, template, window

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Spatial filtering

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering
Origin x
a b c j k l
d
g
e
h
f
i
* m
p
n
q
o
r

Simple 3*3
Original Filter (w)
e 3*3 Filter
Neighbourhood Image
Pixels
eprocessed = n*e +
j*a + k*b + l*c +
y Image f (x, y) m*d + o*f +
p*g + q*h + r*i

The above is repeated for every pixel in the original image to generate the filtered image

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Spatial filtering

Gaussian

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Spatial filtering
Correlation
Convolution

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Spatial filtering
Image convolution

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Spatial filtering
Vector representation

R = wTz

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Correlation filtering
we have been talking about so far

Convolution filtering
similar operation, with just one subtle difference

a b c r s t eprocessed = v*e +
z*a + y*b + x*c +
d
f
e
g
e
h
* u
x
v
y
w
z
w*d + u*e +
t*f + s*g + r*h

For symmetric filters it makes no difference

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Smoothing spatial filtering


Linear filters
Averaging/lowpass

Box filter Weighted average


filter

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Smoothing spatial filtering


Linear filters
Averaging/lowpass

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering
1 1 1

f [.,.] g[.,.] h[ , ] 1 1 1

1 1 1

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0
0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0
0 0
0 0
0 90
90 0
0 90
90 90
90 90
90 0
0 0
0

0
0 0
0 0
0 90
90 90
90 90
90 90
90 90
90 0
0 0
0

0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0

0
0 0
0 90
90 0
0 0
0 0
0 0
0 0
0 0
0 0
0

0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0

a b
g ( x, y ) h ( s, t ) f ( x s, y t )
s a t b
Dr. Asif Khan, GIK Institute, Spring 2017 Credit: S. Seitz
Advanced Image Processing
Spatial Filtering
1 1 1

f [.,.] g[.,.] h[ , ] 1 1 1

1 1 1

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0
0 10

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 0 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 0 0 0 0 0 0 0

0 0 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

Dr. Asif Khan, GIK Institute, Spring 2017 Credit: S. Seitz


Advanced Image Processing
Spatial Filtering
1 1 1

f [.,.] g[.,.] h[ , ] 1 1 1

1 1 1

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0
0 10 20

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 0 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 0 0 0 0 0 0 0

0 0 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

Dr. Asif Khan, GIK Institute, Spring 2017 Credit: S. Seitz


Advanced Image Processing
Spatial Filtering
1 1 1

f [.,.] g[.,.] h[ , ] 1 1 1

1 1 1

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0
0 10 20 30

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 0 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 0 0 0 0 0 0 0

0 0 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

Dr. Asif Khan, GIK Institute, Spring 2017 Credit: S. Seitz


Advanced Image Processing
Spatial Filtering
1 1 1

f [.,.] g[.,.] h[ , ] 1 1 1

1 1 1

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0
0 10 20 30 30

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 0 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 0 0 0 0 0 0 0

0 0 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

Dr. Asif Khan, GIK Institute, Spring 2017


17 Credit: S. Seitz
Advanced Image Processing
Spatial Filtering
1 1 1

f [.,.] g[.,.] h[ , ] 1 1 1

1 1 1

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0
0 10 20 30 30

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 0 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 0 0 0 0 0 0 0
?
0 0 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

Dr. Asif Khan, GIK Institute, Spring 2017


18 Credit: S. Seitz
Advanced Image Processing
Spatial Filtering
1 1 1

f [.,.] g[.,.] h[ , ] 1 1 1

1 1 1

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0
0 10 20 30 30

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 0 90 90 90 0 0
?
0 0 0 90 90 90 90 90 0 0

0 0 0 0 0 0 0 0 0 0
50
0 0 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

Dr. Asif Khan, GIK Institute, Spring 2017


19 Credit: S. Seitz
Advanced Image Processing
Spatial Filtering
1 1 1

f [.,.] g[.,.] h[ , ] 1 1 1

1 1 1

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0
0 10 20 30 30 30 20 10

0 0 0 90 90 90 90 90 0 0
0 20 40 60 60 60 40 20
0 0 0 90 90 90 90 90 0 0

0 30 60 90 90 90 60 30
0 0 0 90 90 90 90 90 0 0

0 0 0 90 0 90 90 90 0 0 0 30 50 80 80 90 60 30

0 0 0 90 90 90 90 90 0 0
0 30 50 80 80 90 60 30

0 0 0 0 0 0 0 0 0 0
0 20 30 50 50 60 40 20
0 0 90 0 0 0 0 0 0 0

10 20 30 30 30 30 20 10
0 0 0 0 0 0 0 0 0 0

10 10 10 0 0 0 0 0

Dr. Asif Khan, GIK Institute, Spring 2017


20 Credit: S. Seitz
Advanced Image Processing
Spatial Filtering

Smoothing spatial filtering


Order-statistics (nonlinear) filters
Median good for impulse/salt-and-pepper noise
Min - Set the pixel value to the minimum in the neighbourhood
Max - Set the pixel value to the maximum in the neighbourhood

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Smoothing spatial filtering


Order-statistics (nonlinear) filters
Median good for impulse/salt-and-pepper noise
Min - Set the pixel value to the minimum in the neighbourhood
Max - Set the pixel value to the maximum in the neighbourhood

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Sharpening spatial filtering

highlights fine details (e.g. edges)


removes blurring
based on spatial differentiation

measures the rate of change of a function


first-order derivatives
second-order derivates

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Sharpening spatial filtering


first-order derivatives
A B

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Sharpening spatial filtering


first-order derivatives

f
f ( x 1) f ( x)
x

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

f(x)

5 5 4 3 2 1 0 0 0 6 0 0 0 0 1 3 1 0 0 0 0 7 7 7 7
0 -1 -1 -1 -1 -1 0 0 6 -6 0 0 0 1 2 -2 -1 0 0 0 7 0 0 0

f
f ( x 1) f ( x)
x
f(x)

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

f(x)

4 +3 52+ +35 2(5)


4+
2(4)
1 2(3)0 + 0 2(6)
2(2) 0+
7+7 7+ 2(7)
7 2(7)
2(7)
= -1
= =0 0= 0 = -12 ==-70= 0
5 5 4 3 2 1 0 0 0 6 0 0 0 0 1 3 1 0 0 0 0 7 7 7 7
-1 0 0 0 0 1 0 6 -12 6 0 0 1 1 -4 1 1 0 0 7 -7 0 0

f(x)

2 f
f ( x 1) f ( x 1) 2 f ( x )
x
2

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Isolated point
Step
f(x)
Thin Line

Nonzero along
the entire ramp
f(x)

Thick Edge Almost same response


Nonzero
Nonzero only at the only at the
onset & endonset & ramp
of the end of the ramp Double Response
f(x)

Fine Edges
Stronger response
Dr. Asif Khan, GIK Institute, Spring 2017
Advanced Image Processing
Spatial Filtering

First Order Derivative Second Order Derivative

Generally produce thicker edges in an Have a stronger response to fine detail,


image such as thin lines and isolated points
Generally have a stronger response to a Produce a double response at step
gray-level step. changes in gray level
For similar changes in gray-level
values in an image, their response is
stronger to a line than to a step, and to a
point than to a line.

Highlight intensity discontinuities

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Sharpening spatial filtering


second-order derivates
Laplacian
Isotropic rotation invariant
One of the simplest sharpening filters

2 f [ f ( x 1, y ) f ( x 1, y )
f f
2 2
2 f 2 f ( x, y 1) f ( x, y 1)]
x y
2

4 f ( x, y )
f2
f ( x 1, y ) f ( x 1, y ) 2 f ( x, y )
x
2
0 1 0
2 f 1 -4 1
f ( x, y 1) f ( x, y 1) 2 f ( x, y )
y
2

0 1 0
Dr. Asif Khan, GIK Institute, Spring 2017
Advanced Image Processing
Spatial Filtering

Sharpening spatial filtering


second-order derivates
Laplacian

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Sharpening spatial filtering


Laplacian

g ( x, y ) f ( x, y ) 2 f

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Sharpening spatial filtering


Laplacian

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Sharpening spatial filtering


Laplacian

g ( x, y ) f ( x, y ) f 2

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)
Dr. Asif Khan, GIK Institute, Spring 2017
Advanced Image Processing
Spatial Filtering

Sharpening spatial filtering


Laplacian
a new filter which does the whole job in one step

0 -1 0

-1 5 -1

0 -1 0

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Sharpening spatial filtering


Unsharp masking
sequence of linear spatial filters to get sharpening
blur
subtract from original image (to get mask)
add resulting mask to original image

Highboost filtering
If A > 1

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Sharpening spatial filtering


Unsharp masking
sequence of linear spatial filters to get sharpening
blur
subtract from original image (to get mask)
add resulting mask to original image

Highboost filtering
If A > 1

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Highboost filtering

(a) A dark (b) Laplacian


image computed
with the high
boost filter
using A = 0.

(c) Laplacian of (a)


(d) Laplacian
computed with the
computed with
high boost filter
the high boost
using A = 1.
filter. A = 1.7.

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Highboost filtering

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Sharpening spatial filtering


first-order derivates (the gradient)
the gradient of f at coordinates (x, y) is

f
Gx x
f f
Gy
y
the direction of the greatest rate of change of f at location (x, y)

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Sharpening spatial filtering


first-order derivates (the gradient)
f
Gx x
f f f
f ( x 1) f ( x) Forward Distance
Gy
x y

f
f ( x ) f ( x 1) Backward Distance
x
f
f ( x 1) f ( x 1) Central Distance
x

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Sharpening spatial filtering


first-order derivates (the gradient)
the gradient of f at coordinates (x, y) is
f
mag( f ) 2
Gx G y
1
2 2
f
Gx x
f
Gy
1

f 2 f 2 2
y

x y
Gx G y

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Sharpening spatial filtering


first-order derivates (the gradient)
the gradient of f at coordinates (x, y) is

mag( f ) 2
Gx G y
1
2 2

Gx G y
Gx ( z8 z5 ) and G y ( z6 z5 ) Forward Distance

Gx ( z9 z5 ) and G y ( z8 z6 ) Roberts cross-


gradient operators
z1 z2 z3
mag( f ) z9 z5 z8 z6
-1 0 0 -1 z4 z5 z6
0 1 1 0
z7 z8 z9
Dr. Asif Khan, GIK Institute, Spring 2017
Advanced Image Processing
Spatial Filtering

Sharpening spatial filtering


first-order derivates (the gradient)
An approximation using absolute values, still at point z5 , but
using a 33 mask, is

mag( f ) z3 z6 z9 z1 z4 z7

z7 z8 z9 z1 z2 z3

-1 0 1 z1 z2 z3 -1 -1 -1
-1 0 1 z4 z5 z6 0 0 0

-1 0 1 z7 z8 z9 1 1 1

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Sharpening spatial filtering


first-order derivates (the gradient)

-1 0 1 -1 -1 -1 Remember the central distance


f
f ( xy 1) f ( xy 11))
-1 0 1 0 0 0 yx
-1 0 1 1 1 1 mag( f ) Gx G y

Gx f ( x 1, y 1) f ( x 1, y ) f ( x 1, y 1)
f ( x 1, y 1) f ( x 1, y ) f ( x 1, y 1)

G y f ( x 1, y 1) f ( x, y 1) f ( x 1, y 1)
f ( x 1, y 1) f ( x, y 1) f ( x 1, y 1)
Dr. Asif Khan, GIK Institute, Spring 2017
Advanced Image Processing
Spatial Filtering

Sharpening spatial filtering


first-order derivates (the gradient)
Sobel operator

-1 0 1 -1 -2 -1

-2 0 2 0 0 0

-1 0 1 1 2 1

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Sharpening spatial filtering


first-order derivates (the gradient) Vertical Edge
Sobel operator (absolute value)

1 0 -1
2 0 -2
1 0 -1

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Sharpening spatial filtering


first-order derivates (the gradient)
Sobel operator

1 2 1
0 0 0
-1 -2 -1

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Sharpening spatial filtering


first-order derivates (the gradient)
Sobel operator

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Combining spatial filters

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Combining spatial filters

Dr. Asif Khan, GIK Institute, Spring 2017


Advanced Image Processing
Spatial Filtering

Acknowledgement

Images taken from Digital Image Processing by Gonzalez


and Woods, 3rd Ed.

Dr. Asif Khan, GIK Institute, Spring 2017

You might also like