Available with Spatial Analyst license.
You can use the Expand and Shrink tools to generalize, or simplify, rasters. In contrast to the Majority Filter and Boundary Clean tools, Expand and Shrink allow you to target the generalization to a particular zone or zones.In contrast to the Majority Filter and Boundary Clean tools, Expand and Shrink allow you to target the generalization to a particular zone or zones. Depending on the tool you use, you can make particular zones larger or smaller. You can also control the amount of generalization that will occur.
Both tools have two methods to from which to choose. The first is a mathematical morphological approach. The other is a distance-based approach.
Comparing Expand and Shrink
Both tools operate by allowing certain zones to replace cells of other zones.
Expand
With the Expand tool, the selected zones increase in size by expanding into other zones. Conceptually, the selected Zone Values can be viewed as foreground zones, while the other values remain background zones. The foreground zones can expand into the background zones.
Shrink
With the Shrink tool, the selected zones shrink, or reduce in size, by cells from other zones expand into them. Conceptually, the selected Zone Values are considered to be foreground zones, while the remaining zone values are considered to be background zones. With this tool, cells in the foreground zones are allowed to be replaced by cells in the background zones.
Thin islands inside a zone, which can be viewed as sharing boundaries with the zone, may also be replaced
Amount of generalization
The amount of generalization can be controlled with the Number of Cells parameter. By default, this value is 1, which means that depending on which tool is being used, the selected zones will expand or shrink by the amount corresponding to one cell's size. To increase the degree of generalization, you can specify a larger value for this parameter. Conceptually, this is like running the tool as many times as the number specified, with the results of the previous run being the input into the subsequent iteration
Methods
There are two method available when generalizing rasters with the Expand and Shrink tools, mathematical morphology and distance-based
Mathematical morphology
The mathematical morphology approach applies a structuring element to the raster to extract knowledge from it. There are several possible shapes, with the most common being a simple 3-cell by 3-cell square. During the operation, each cell in the raster being processed is checked for inclusion or exclusion in the set of the selected zone (Matheron, 1967, and Sera, 1982). The algorithms have evolved from the processing of binary images in the early days of image processing to apply to inputs with multiple zone values, and selectable sizes of the structuring element. For this method, the Expand and Shrink tools use a 3 by 3 square structuring element.
Distance-based
The distance-based approach supposes that cells with a selected input zone value or values are sources. Each cell in the input raster is considered in relation to its distance to the nearest source cell. The distance is limited to the Euclidean distance in integer multiples of the input raster's cell resolution.
The following conditions are evaluated to determine what the final output value that any particular cell within this distance will be. While descriptions are for the Expand tool, the same principles apply to the Shrink tool.
- If a cell can only find one type of zone source cell within the range of allowed distance, that cell will be expanded into with that zone value.
- If a cell has several types of zone values within the allowed distance, the cell will be expanded into by the value of the zone that is the nearest.
- If a cell has several types of source cells within the allowed distance, and there are two or more source cells with the same distance (a tie), the algorithm will first count the contribution of each of the source zones. The zone with the most overall contribution will be used as the output value for that cell.
- If a tie still remains, this means that there are two or more source zones that are both nearest and have equal contributions. In this case, the cell will be expanded into by the source with the smallest cell value.
Examples
The following are examples of using these tools with their respective Expand method or Shrink method parameters set to the default Morphological option.
Expand example
In the image below, the Expand tool is applied to the input raster with zone 5 expanding one cell. Notice that zone 5 expanded into the NoData values at the lower right.
Shrink example
In the image below, the Shrink tool is applied to the input raster, so zone 5 shrinks by one cell. Zone 5 is no more than two cells wide in any area; therefore, all cells containing 5 are replaced with the value of highest frequency in its neighborhood. NoData invades two locations at the bottom right, since it is the value of highest frequency to the two locations.
In the image below, Shrink is applied to the input raster, so zones 4 and 6 shrink by one cell. In the upper left corner, a value 4 remains, since it is deeper than one cell.
To specify more than one zone value in Python, use square brackets to define a multivalue list.
References
Matheron, G., Elements pour une Theorie del Milieux Poreux, Masson, Paris, 1967
Serra, J. Image Analysis and Mathematical Morphology, Academic Press, London 1982