Fundamental of Spatial Filtering
Fundamental of Spatial Filtering
Spatial filtering is one of the principal tools used in image processing for a broad
spectrum of applications.
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:
where x and y are varied so that each pixel in w visits every pixel in f.
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:
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