0% found this document useful (0 votes)
139 views6 pages

Fundamental of Spatial Filtering

Spatial filtering is a fundamental technique in image processing that involves applying a filter to an image. A spatial filter consists of a neighborhood of pixels and an operation performed on those pixels. Common linear spatial filters include convolution and correlation filters. Convolution filters an image by rotating a filter mask and calculating the sum of products of overlapping pixels. Correlation similarly calculates the sum of products but without rotating the filter mask. Both techniques essentially copy the filter across the image to create a new filtered output image.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
139 views6 pages

Fundamental of Spatial Filtering

Spatial filtering is a fundamental technique in image processing that involves applying a filter to an image. A spatial filter consists of a neighborhood of pixels and an operation performed on those pixels. Common linear spatial filters include convolution and correlation filters. Convolution filters an image by rotating a filter mask and calculating the sum of products of overlapping pixels. Correlation similarly calculates the sum of products but without rotating the filter mask. Both techniques essentially copy the filter across the image to create a new filtered output image.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Fundamental of Spatial Filtering

Spatial filtering is one of the principal tools used in image processing for a broad
spectrum of applications.

The Mechanics of Spatial Filtering


As explained briefly in Figure 3.1, a spatial filter consists of a neighbourhood and a
predefined operation that is performed on the image pixels encompassed by the
neighbourhood.
Filtering creates a new pixel with coordinates equal to the coordinates of the center of
the neighbourhood, and whose value is the result of the filtering operation.
If the operation performed on the image pixels is linear, then the filter is called a
linear spatial filter. Otherwise, the filter is nonlinear.
Figure 3.28 shows the mechanics of linear spatial filtering using a 3*3
neighbourhood.

37
At any point (x,y) in Figure 3.28, the response, g(x,y) , of the filter is the sum of
products of the filter coefficients and the image pixels encompassed by the filter:

In general, linear spatial filtering of an image of size M ×N with a filter of size m ×n is


given by the expression:

where x and y are varied so that each pixel in w visits every pixel in f.

Spatial Correlation and Convolution


There are two closely related concepts when performing linear spatial filtering,
correlation and convolution.
Correlation is the process of moving a filter mask over the image and computing the
sum of products at each location. A 1-D example of correlation and convolution:
Figure 3.29 (a) – (h).
The concept of convolution is a cornerstone of linear system theory. A fundamental
property of convolution is that convolving a function with a unit impulse yields a copy
of the function at the location of the impulse.
To perform convolution, all we do is to rotate one function by 1800 and perform the
same operation as in correlation, as the right column in Figure 3.29 shows.

38
The proceeding concepts can be extended to images. Figure 3.30 shows an example.

39
Figure 3.29(a) shows a 1-D function, f , and a filter,w , and Fig.3.29 (b) shows the
starting position to perform correlation. The first thing we note is that there are parts
of the functions that do not overlap. The solution to this problem is to pad f with
enough 0s on either side to allow each pixel in w to visit every pixel in f .if the filter is
of size m. We need m-1 0s on either side of f .figure 3.29(c) shows a properly padded
function. The first value of correlation is the sum of products of f and w for the initial
position shown in Fig.3.29(c) (the sum of products is 0). This corresponds to a
displacement x=0. To obtain the second value of correlation, we shift w one pixel
location to the right (a displacement of x=1) and compute the sum of products. The
result again is 0. In fact, the first nonzero result is when x=3, in which case the 8 in w
overlaps the 1 in f and the result of correlation is 8.proceeding in this manner, we
obtain the full correlation result in fig.3.29(g). Note that it took 12 values of x (i.e.,
x=0,1,2….11) to fully slide w past f so that each pixel in w visited every pixel in f .

Often, we like to work with correlation arrays that are the same size as f ,in which case
We crop the full correlation to the size of the original function, as fig.3.29(h)shows.

There are two important points to note from the discussion in the preceding paragraph.
First, correlation is a function of displacement of the filter.in other words, the first
value of correlation corresponds to zero displacement of the filter, the second
corresponds to one unit displacement, and so on. The second thing to notice is that
correlating a filter w with a function that contains all 0s and a single 1 yields a result
that is a copy of w but rotated by 1800. We call a function that contains a single 1 with
the rest being 0s a discrete unit impulse. So we conclude that correlation of a function
with a discrete unit impulse yields a rotated version of the function at the location of
the impulse yields a rotated version of the function at the location of the impulse.

40
The concept of convolution is a cornerstone of linear system theory.as you will learn
in chapter 4, a fundamental property of convolution is that convolving a function with
a unit impulse yields a copy of the function at the location of the impulse. We saw in
the previous paragraph that correlation yields a copy of the function also, but rotated
by 1800. Therefore, if we pre-rotate the filter and perform the same sliding sum of
products operation. We should be able to obtain the desired result. As the right
column in fig.3.29 shows, this indeed is the case. Thus, we see that to perform
convolution all we do is rotate one function by 180 0 and perform the same operation
as in correlation. As it turns out, it makes no difference which of the two functions we
rotate.

The preceding concepts extend easily to images, as fig.330 shows. For a filter of size
m× n, we pad the image with a minimum of m−1rows of 0s at the top and bottom and

n−1 columns of 0s on the left and right. In this case, m and n are equal to 3, so we pad

f with two rows of 0s above and below and two columns of 0s to the left and right, as

fig.3.30(b) shows. Figure 3.30(c) shows the initial position of the filter mask for
performing correlation, and fig, 3.30(d) shows the full correlation result. Figure
3.30(e) shows the corresponding cropped result. Note again that the result is rotated
by 1800 for convolution, we pre-rotate the mask as before and repeat the sliding sum
of products just explained. Figures 3.30(f) through (h) show the result. You see again
that convolution of a function with an impulse copies the function at the location of
the impulse. It should be clear that if the filter mask is symmetric, correlation and
convolution yield the same result. If, instead of containing a single1, image f in
fig.3.30 had contained a region identically equal to w , the value of the correlation
function (after normalization) would have been maximum when w was centered on
that region of f . Thus, as you will see in chapter 12, correlation can be used also to
find matches between images.

41
Summarizing the discussion in equation form, we have that the correlation of filter
w(x,y) of size m ×n with an image f (x,y) , denoted as w(x,y)☆f (x,y) , is given by the
equation:

where a = (m −1)/2, b = (n −1)/2 , and we assume for notational convenience that m


and n are odd integers.
In a similar manner, the convolution of w(x,y) and f (x,y) , denoted by w(x,y)★f (x,y) ,
is given by the expression

We will revisit the issue in Chapter 4 in the context of the Fourier transform and the
convolution theorem, though the focus will be on the convolution functions that are
the same size. Using correlation or convolution to perform spatial filtering is a matter
of preference. In fact, either (3.4-1) or (3.4-2) can be made to perform the function of
other by a simple rotation of the filter.

42

You might also like