The Boundary Clean and Majority Filter tools are used to generalize along the edges of zones in a raster. The edges are smoothed by either expanding and shrinking boundaries between the zones, or replacing cells with the majority value within their immediate neighborhood.
Boundary Clean
The Boundary Clean tool generalizes, or simplifies, rasters by smoothing the boundaries between zones. It applies an expand and shrink method to evaluate each cell using its immediate neighbors. Several options for controlling how the cells of the zones influence the smoothing are available. The degree of smoothing can also be controlled.
Sort by priority
The process begins by sorting the zones in the input raster by a particular priority. For each cell in the input, the priority is used to determine which zone value from the surrounding neighborhood can replace the value of the processing cell.
The sorting priority can be based on the values of the zones or the size of the zones. The Sort type parameter specifies the sorting priority to use. With the default Do not sort setting, cells from zones with larger values will have a higher priority to expand into zones with smaller values. With the Descending setting, zones that are larger in area will have the priority to expand into zones with smaller areas. With the Ascending setting, zones with smaller areas will have the priority to expand into zones with larger areas.
Amount of smoothing
The amount of smoothing is controlled by the number of times the expand and shrink process is performed: once or twice. The default is twice, which results in a greater amount of smoothing.
Expand and shrink process
The expand and shrink process evaluates the immediate neighbors of each processing cell according to the sorting priority type set in the Sort type parameter.
In the process, an expansion is followed by shrinking. This process will occur one time if the Run expansion and shrinking twice parameter is unchecked (the number_of_runs parameter is set to ONE_WAY in Python). If the parameter is checked (the number_of_runs parameter is set to TWO_WAY in Python), the expand and shrink process will be performed twice.
Additional details for the algorithms used in the process are below.
One-way expand and shrink
With the one-way setting, the expand and shrink process is performed once.
In the expand pass, the following occur:
- For each processing cell in the input raster, evaluate each neighbor cell.
- For each neighbor cell, assess whether the priority value of that neighbor cell is less than the priority value of the processing cell. If it is, assign the internal neighbor priority to be that of the input processing cell. Update the internal expanded raster with the new priority value, and proceed to the next neighbor cell.
In the shrink pass, the following occur:
- For each processing cell in the input raster, evaluate each neighbor cell using the value of the internal expanded raster that is created in the first pass.
- If the priority of a neighbor cell is equal to the priority of the processing cell, copy the cell value from the original input raster to the output. If the condition is not satisfied for any of the neighbor cells, copy the cell value from the expanded raster to the output.
Two-way expand and shrink
If the Run expansion and shrinking twice parameter is checked (the number_of_runs parameter is set to TWO_WAY in Python), a second expand and shrink process is performed, but this time the priorities will be reversed. The output from the first pass of the operation is used as input to the second pass.
In the first expand pass, the same logic that was used in the expand pass for one-way is used.
In the first shrink pass, the same logic that was used in the shrink pass for one-way is used.
In the second expand pass, the following occur:
- For each processing cell in the internal raster generated from the first expand and shrink process, evaluate each neighbor cell.
- For each neighbor cell, assess whether the priority value of that neighbor cell is greater than the priority value of the processing cell. If it is, assign the internal neighbor priority to be that of the input processing cell. Update the internal expanded raster with the new priority value, and proceed to the next neighbor cell.
In the second shrink pass, the following occur:
- For each processing cell in the internal expanded raster from the previous step, evaluate each neighbor cell.
- For each neighbor cell, if the priority value of the neighbor cell is less than or greater than the processing cell value in the expanded raster, copy the value of the processing cell from the original raster to the output.
- If the priority value of the neighbor cell is equal to the processing cell value in the expanded raster, copy the value of the processing cell from the expanded raster to the output.
NoData handling
Input cells of NoData have the lowest priority when the expand and shrink process is run once, or in the second pass if the expand and shrink process is run twice. In the second pass of two-way sorting, cells of NoData will have the highest priority.
Example
To show the effects of various parameters on the output, consider the input raster below.
The outputs for all settings of the Sort type parameter will be shown, for both settings of the Run expansion and shrinking twice parameter (unchecked or checked).
When the Sort type parameter is Do not sort, the output rasters are as follows:
When the Sort type parameter is Descending, the output rasters are as follows:
When the Sort type parameter is Ascending, the output rasters are as follows:
Majority Filter
The Majority Filter tool replaces cells based on the majority value in their contiguous neighborhoods. The tool has two criteria to satisfy before a replacement can occur. First, the number of neighboring cells with the same value must be large enough to be the majority value, or at least half the cells must have the same value (depending on the parameter specified). That is, three out of four or five out of eight connected cells must have the same value with the majority parameter and two out of four or four out of eight are needed for the half parameter. Second, those cells must be contiguous to the center of the specified filter (for example, three out of four cells must be the same). The second criteria concerning the spatial connectivity of the cells minimizes the corruption of cellular spatial patterns. If these criteria are not met, no replacement occurs, and the cell retains its value.
In the image below, Majority Filter is applied to the input raster using a filter of the closest four cells, which are the four orthogonal neighboring cells, requiring the majority (three out of four cells) to be the same before a cell will change its value. Only those cells surrounded by three or more (orthogonal) cells with the same value are changed.
In the image below, the Majority Filter tool is applied using the closest eight cells as a filter and requiring at least half the values (four out of eight cells) to have the same value before changing the cell's value. Notice there is a greater smoothing effect.