Spatial Filtering Fundamentals

Only available on StudyMode
  • Download(s) : 86
  • Published : April 21, 2013
Open Document
Text Preview
4/28/2008

Spatial filtering fundamentals

by Gleb V. Tcheslavski: gleb@ee.lamar.edu http://ee.lamar.edu/gleb/dip/index.htm Spring 2008 ELEN 4304/5365 DIP 1

Mechanics of spatial filtering
Considering frequency domain filtering, the effect of LPF applied to an image is to blur (smooth) it. Similar smoothing effect can be achieved by using spatial filters (spatial masks, kernels, templates, or windows). We discussed that a spatial filter consists of a neighborhood and a pre-defined operation performed on the image pixels defining the neighborhood. The result of filtering – a new pixel with coordinated of the neighborhood’s center and the value defined by the operation. g y p If the operation is linear, the filter is said to be a linear spatial filter.

Spring 2008

ELEN 4304/5365 DIP

2

1

4/28/2008

Mechanics of spatial filtering
Assuming a 3 x 3 neighborhood, at any point (x,y) in the image, the response of the spatial filter is

g ( x, y ) = w(−1, −1) f ( x − 1, y − 1) + w(−1, 0) f ( x − 1, y ) + ... + w(0, 0) f ( x, y ) + ... + w(1,1) f ( x + 1, y + 1) Filter coefficient Pixel intensity

In general:

g ( x, y ) =

s =− a t =− b

∑ ∑ w(s, t ) f ( x + s, y + t )

a

b

Spring 2008

ELEN 4304/5365 DIP

3

Mechanics of spatial filtering
Here a mask size is m x n.

m = 2a + 1 n = 2b + 1
Where a and b are some integers.

For a 3 x 3 mask

Spring 2008

ELEN 4304/5365 DIP

4

2

4/28/2008

Spatial correlation and convolution
Correlation is a process of moving the filter mask over the image and computing the sum of products at each location as previously described. Convolution is the same except that the filter is first rotated by 1800. For a 1D case, we first zeropad f by m-1 zeros on each size. We compute a sum of products in both cases… Spring 2008 ELEN 4304/5365 DIP 5

Spatial correlation and convolution
Correlation is a function of displacement of the filter. A function containing a single 1 with the rest being zeros is g g g called a discrete unit impulse. Correlation of a function with a discrete unit impulse yields a rotated version of a function at the location of the impulse. To perform a convolution, we need to pre-rotate the filter by 1800 and perform the same operation as in correlation.

Spring 2008

ELEN 4304/5365 DIP

6

3

4/28/2008

Spatial correlation and convolution
In a 2D case, for a filter of size m x n, we pad the image with m-1 rows of zeros at the top and bottom and n-1 columns of zeros on the left and right. For convolution, we pre-rotate the mask and perform the sliding sum of products.

Spring 2008

ELEN 4304/5365 DIP

7

Spatial correlation and convolution
Correlation of a filter w(x,y) of size m x n with an image f(x,y) is

w( x, y )

f ( x, y ) =

s =− a t =− b

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

a

b

Convolution of a filter w(x,y) of size m x n with an image f(x,y) is

w( x, y ) ⊗ f ( x, y) =

s =− a t =− b

Spring 2008

ELEN 4304/5365 DIP

8

4

4/28/2008

Vector representation of linear filtering
It is convenient sometimes to represent a sum of products as

R = ∑ wk zk = w T z
k =1
Filter coeffs Image intensities

mn

For example, for a 3 x 3 filter: p ,

R = ∑ wk zk = w T z
k =1
Spring 2008 ELEN 4304/5365 DIP 9

9

Generating spatial filter masks
Generating an m x n linear spatial filter requires specification of mn mask coefficients. These coefficients are selected based on what the filter is supposed to do keeping in mind that all we can do with linear filtering is to implement a sum of products. Assuming that we need to replace the pixels in an image with the average pixel intensities of a 3x3 neighborhood centered on those pixels. If zi are the intensities, the average is

R=
9

1 9 ∑ zi 9 i =1

Which is:

R = ∑ wi zi = w T z;
i =1
ELEN 4304/5365 DIP

wi =

1 9
10

Spring 2008

5

4/28/2008...
tracking img