# How Filter works

The Filter tool can be used to either eliminate spurious data or enhance features otherwise not visibly apparent in the data. Filters essentially create output values by a moving, overlapping 3x3 cell neighborhood window that scans through the input raster. As the filter passes over each input cell, the value of that cell and its 8 immediate neighbors are used to calculate the output value

There are two types of filters available in the tool: low pass and high pass.

## Types of filter

The filter type LOW employs a low pass, or averaging, filter over the input raster and essentially smooths the data. The HIGH filter type uses a high pass filter to enhance the edges and boundaries between features represented in the raster.

## Low pass filter

A low pass filter smooths the data by reducing local variation and removing noise. It calculates the average (mean) value for each 3 x 3 neighborhood. It is essentially equivalent to the Focal Statistics tool with the Mean statistic option. The effect is that the high and low values within each neighborhood will be averaged out, reducing the extreme values in the data.

### Example 1

Following is an example of the input neighborhood values for one processing cell, the center cell with the value 8.

`````` 7 5 2
4 8 3
3 1 5``````

The calculation for the processing cell (the center input cell with the value 8) is to find the average of the input cells. This is the sum of all the values in the input contained by the neighborhood, divided by the number of cells in the neighborhood (3 x 3 = 9).

`````` Value = ((7 + 5 + 2) + (4 + 8 + 3) + (3 + 1 + 5)) / 9
= 38 / 9
= 4.222``````

The output value for the processing cell location will be 4.22.

Since the mean is being calculated from all the input values, the highest value in the list, which is the value 8 of the processing cell, is averaged out.

### Example 2

This example shows the resulting raster generated by Filter with the LOW option on a small 5x5 cell raster.

To illustrate how NoData cells are handled, the output values with the Ignore NoData parameter set to Data then NODATA follow:

• Input cell values:
`````` 2.000   3.000   4.000   5.000   6.000
2.000   3.000   4.000   NoData  6.000
2.000   3.000   4.000   5.000   6.000
2.000  30.000   4.000   5.000   NoData
1.000   2.000   2.000   3.000   NoData``````
• Output cell values with DATA option set (NoData cells in a filter window will be ignored in the calculation):
`````` 2.500   3.000   3.800   5.000   5.667
2.500   3.000   3.875   5.000   5.600
7.000   6.000   7.250   4.857   5.500
6.667   5.556   6.444   4.143   4.750
8.750   6.833   7.667   3.500   4.000``````
• Output cell values with NODATA option set (the output will be NoData if any cell in the filter window is NoData):
`````` NoData  NoData  NoData  NoData  NoData
NoData  3.000   NoData  NoData  NoData
NoData  6.000   NoData  NoData  NoData
NoData  5.556   6.444   NoData  NoData
NoData  NoData  NoData  NoData  NoData``````

### Example 3

In the following example, the input raster has an anomalous data point caused by a data collection error. The averaging characteristics of the LOW option have smoothed the anomalous data point.

## High pass filter

The high pass filter accentuates the comparative difference between a cell's values and its neighbors. It has the effect of highlighting boundaries between features (for example, where a water body meets the forest), thus sharpening edges between objects. It is generally referred to as an edge-enhancement filter.

With the HIGH option, the nine input z-values are weighted in such a way that removes low frequency variations and highlights the boundary between different regions.

The 3 x 3 filter for the HIGH option is:

`````` -0.7  -1.0  -0.7
-1.0   6.8  -1.0
-0.7  -1.0  -0.7``````

Note that the values in the kernel sum to 0, since they are normalized.

The High Pass filter is essentially equivalent using the Focal Statistics tool with the Sum statistic option, and a specific weighted kernel.

The output z-values are an indication of the smoothness of the surface, but they have no relation to the original z-values. Z-values are distributed about zero with positive values on the upper side of an edge and negative values on the lower side. Areas where the z-values are close to zero are regions with nearly constant slope. Areas with values near z-min and z-max are regions where the slope is changing rapidly.

### Example 1

Following is a simple example of the calculations for one processing cell (the center cell with the value 8):

`````` 7 5 2
4 8 3
3 1 5``````

The calculation for the processing cell (the center cell with the value 8) is as follows:

`````` Value = ((7*-0.7) + (5*-1.0) + (2*-0.7) +
(4*-1.0) + (8*6.8)  + (3*-1.0) +
(3*-0.7) + (1*-1.0) + (5*-0.7))
= ((-4.9 + -5.0 + -1.4) +
(-4.0 + 54.4 + -3.0) +
(-2.1 + -1.0 + -3.5)
= -11.3 + 47.4 + -6.6
= 29.5
``````

The output value for the processing cell will be 29.5.

By giving negative weights to its neighbors, the filter accentuates the local detail by pulling out the differences or the boundaries between objects.

### Example 2

In the example below, the input raster has a sharp edge along the region where the values change from 5.0 to 9.0. The edge enhancement characteristic of the HIGH option has detected the edge.

## Processing cells of NoData

The Ignore NoData in calculations option controls how NoData cells within the neighborhood window are handled. When this option is checked (the DATA option), any cells in the neighborhood that are NoData will be ignored in the calculation of the output cell value. When unchecked (the NODATA option), if any cell in the neighborhood is NoData, the output cell will be NoData.

If the processing cell itself is NoData, with the Ignore NoData option selected, the output value for the cell will be calculated based on the other cells in the neighborhood that have a valid value. Of course, if all of the cells in the neighborhood are NoData, the output will be NoData, regardless of the setting for this parameter.

## References

Gonzalez, R. C., and P. Wintz. 1977. Digital Image Processing. Massachusetts: Addisonâ€“Wesley.

Hord, R. M. 1982. Digital Image Processing of Remotely Sensed Data. New York: Academic.

Moik, J. G. 1980. Digital Processing of Remotely Sensed Images. New York: Academic.

Richards, J. A. 1986. Remote Sensing Digital Image Analysis: An Introduction. Berlin: Springer-Verlag.

Rosenfeld, A. 1978. Image Processing and Recognition, Technical Report 664. University of Maryland Computer Vision Laboratory.