The term spatial filtering is principally associated with digital image processing, although such methods may be applied to almost any type of grid or image. The term is also used, in a related manner, in the area of spatial statistics (see further, Section 5.6.5, Spatial filtering models).
Most GIS packages provide simple grid filtering functions, whilst those that have a bias towards image processing and grid file handling (e.g. TNTMips, Surfer, Idrisi) tend to provide a broader range of functions. The most commonly provided functions are socalled lowpass and highpass spatial filters. These are focal functions whose operation is determined by a kernel or neighborhood of NxN cells around each pixel or grid position. Grid cells “covered” by the kernel are multiplied by the matching kernel entry and then the weighted average is calculated and assigned as the value for the central cell, G. A 3x3 symmetric kernel might look something like:
or perhaps
In the first of these examples a and b are positive numbers, typically integers. If a=b=1 then the kernel provides a simple averaging or smoothing operation, whereas if a=1 and b=4 more weight would be applied to the grid cell being filtered. In both cases the weighted average is divided by the sum of the kernel elements. No divisor is applied in cases where the kernel sums to 0 or 1. Filters of this type are sometimes described as lowpass spatial filters. For example, consider the filter:
and grid section
The value at the central grid position G(2,2)=187 is replaced by the weighted average of itself (assigned a weight of 4) and the surrounding 8 cells (each assigned a weight of 1). The adjusted value is 164 after rounding. In the second example if a, b and c are positive with b>a>c the kernel is described as Gaussian, being symmetric but centerweighted, for example:
With the same data grid as above the filtered value is G=162. More generally, if {Ci} is the set of coefficients of an m=NxN kernel matrix and {Pi} is the set of source grid values within this kernel neighborhood, then the filtered grid value, G, is defined as:
The extra term, B, here is often set to 0. It is a bias factor that increases or decreases the resulting filter value by a fixed amount.
Highpass spatial filters emphasize the difference between the central point of the kernel and the values in its immediate neighborhood. Typically the entries in such kernels have a mix of positive and negative values, but the entries still add up to 1:
Values are often used to provide image sharpening prior to further processing. Table 4‑11 provides examples and a summary of typical linear spatial filters used in GIS and image analysis. Basic linear image filtering operations fall into a number of categories:
•  Sharpening — for which the kernel matrix elements sum to 1 and the matrix is symmetric. Matrix elements are a mix of positive, negative and zero entries 
•  Blurring — also known as a smoothing, averaging or lowpass filtering, since this reduces or removes extreme values. In this case the kernel matrix elements sum to >1, entries are normally all positive and the matrix is symmetric 
•  Edge detection — for which the kernel matrix elements sum to 0 and the matrix exhibits some symmetry. As with sharpening, matrix elements are a mix of positive, negative and zero entries 
•  Embossing — for which the kernel matrix elements sum to 0 as per edge detection, but the matrix is asymmetric. It is usual to compute the embossed version of an image on a grayscale version, which is obtained by finding the average value of the bands, e.g. red (r), green (g) and blue (b) components, as x=(r+g+b)/3 for each pixel, and assigning the resulting values in the range [0,255] to a gray scale (where 0=black and 255=white) 
A number of general characteristics of this type of filtering should be noted:
•  if the range of values permitted within the grid are limited (e.g. RGB values in the range [0,255]) then computed values that fall outside of this range must be truncated to the range limits. This generates some computational (as opposed to user defined) bias in the processing 
•  multiband image data filters are applied to each band separately. Hence a sharpening filter applied to an RGB image, for example, would be applied to the R, G and B components 
•  filtering may be conducted more than once (single pass or multipass). Each pass reapplies the same filter or filters to the target grid or image (layer or band) 
•  userdefined kernels are widely supported, both in image processing packages and within GIS software. Users may be able to select a predefined filter and modify this to suit their requirements, or to create their own NxN kernel 
•  all of the examples described involve simple linear operations, essentially weighted averaging (sometimes described as linear convolution). Nonlinear filtering is also widely available and is described in more detail in Section 4.6.3 
Table 4‑11 Linear spatial filters
Filter type 
Filter 
Sample 3x3 kernels 
Description 

Lowpass (symmetric) 
Averaging 
Smoothing, noise reduction or blurring filter (focal mean) 

Gaussian 
Smoothing, noise reduction or blurring filter (focal weighted mean) 

Highpass (symmetric) 
Sharpening 
Mean effect removal/sharpening filter (focal sum). Provides limited edge detection. Typically entries sum to 1 but may be greater. 3x3 Laplacian kernels typical add to 1. Larger Laplacian kernels (e.g. 7x7) may be more complex and sum to >1 

Gradient (asymmetric) 
Edge detection 

Applied singly or as a twopass process. These kernels highlight vertical and horizontal edges. When used in combination they are known as Gradient or Order 1 derivative filters. Typically a=1 and b=1 or 2 and entries sum to 0. A variant known as the Roberts method has row 3 all zero and column 1 zero for the first pass and column 3 zero for the second pass (i.e. a 2x2 filter) 
Embossing 
Edge detecting filters that enhance edges in a selected compass direction to provide an embossed effect. The example here shows a sample northeast kernel 

Directional 

Simple computation of gradient in one of 8 compass directions. east and north directional derivatives are illustrated in the first two examples here. Note that the third example shown corresponds to Horn’s method of derivative calculation for the north/south component (dz/dy) as described in Section 6.1.3. Compares with Edge detection filtering. A nonlinear variant of this procedure is to compute all 8 values and select the maximum absolute value of these as the output 
It should be noted that at image or grid edges it is not possible to apply the kernel symmetrically. This effect is more pronounced for larger kernels, but applies in every instance. There are many options for resolving such effects. Common procedures include: leaving the edge pixels unaltered; blanking edge pixels (which causes the grid to shrink); using an asymmetric (i.e. partial) kernel, which can generate artifacts; and mirroring, where grid values inside the kernel are used as surrogates for the missing values outside the kernel
In addition to filters that operate in the spatial domain, pure frequency domain filters may also be applied. These operate on the set of grid values within an image without reference to the spatial pattern. Frequency domain filtering (for example Fast Fourier Transforms or FFTs) is provided in some GIS packages such as TNTMips and Idrisi, but such procedures are not described in this Guide. FFTs are used, for example, to removing striping effects from remotelysensed imagery.