Majority Filter |
|
Release 9.2
Last modified January 3, 2008 |
![]() ![]() ![]() Print all topics in : "Generalization (Spatial Analyst)" |
Replaces cells in a raster based on the majority of their contiguous neighboring cells.
Learn more about how Majority Filter works
Illustration
Usage tips
Command line and Scripting
The input raster must be integer.
A number can be used as an input; however, the cell size and extent must first be set in the environment.
The use of FOUR will retain the corners of rectangular regions. The use of EIGHT will smooth the corners of rectangular regions.
Contiguous is defined as sharing an edge for a kernel of EIGHT and as sharing a corner for a kernel of FOUR.
If the keyword HALF is specified and two values occur as equal halves, a replacement will not occur if the value of the processing cell is the same as one of the halves. HALF allows more extensive filtering than MAJORITY.
While the contiguity criterion is the same for edge and corner raster cells, they obey different MAJORITY and HALF rules. Using a kernel of FOUR, an edge or corner cell always requires two matching neighbors before replacement will occur. With a kernel of EIGHT, a corner cell must have all neighbors of the same value before it is changed, while an edge cell requires three contiguous neighbors, including one along the edge, before any change will occur.
The output raster will be stabilized (will no longer change) after a few runs of Majority Filter.
The following environment settings affect this tool:
Map Algebra
The <in_grid> must be an integer raster.
The use of FOUR will retain the corners of rectangular regions. The use of EIGHT will smooth the corners of rectangular regions.
Contiguous is defined as sharing an edge for a kernel of EIGHT and as sharing a corner for a kernel of FOUR.
If the keyword HALF is specified and two values occur as equal halves, a replacement will not occur if the value of the processing cell is the same as one of the halves. HALF allows more extensive filtering than MAJORITY.
While the contiguity criterion is the same for edge and corner raster cells, the cells obey different MAJORITY and HALF rules. Using a kernel of FOUR, an edge or corner cell always requires two matching neighbors before replacement will occur. With a kernel of EIGHT, a corner cell must have all neighbors of the same value before it is changed, while an edge cell requires three contiguous neighbors, including one along the edge, before any change will occur.
The output raster will be stabilized (will no longer change) after a few runs of MajorityFilter.
Learn more about how to specify the input raster dataset in the Map Algebra expression of Raster Calculator.
ArcObjects
The input raster must be integer.
Setting useDiagonalNeighbors to False will retain the corners of rectangular regions. Contiguous is defined as sharing a corner.
Setting useDiagonalNeighbors to True will smooth the corners of rectangular regions. Contiguous is defined as sharing an edge.
If halfIsMajority is True and two values occur as equal halves, a replacement will not occur if the value of the processing cell is the same as one of the halves. The True option allows more filtering than the False option.
While the contiguity criterion is the same for edge and corner raster cells, they obey different rules between the True and False settings for halfIsMajority. If useDiagonalNeighbors is set to False, an edge or corner cell always requires two matching neighbors before replacement will occur. If useDiagonalNeighbors is set to True, a corner cell must have all neighbors of the same value before it is changed, while an edge cell requires three contiguous neighbors, including one along the edge, before any change will occur.
The output raster will be stabilized (will no longer change) after a few runs of MajorityFilter.
The output from the ArcObjects method is a raster object.
Command line syntax
An overview of the Command Line window
MajorityFilter_sa <in_raster> <out_raster> {FOUR | EIGHT} {MAJORITY | HALF}
Parameter | Explanation | Data Type |
<in_raster> |
Input raster. |
Composite Geodataset |
<out_raster> |
The raster to be created. |
Raster Dataset |
{FOUR | EIGHT} |
Number of neighboring cells to use in the kernel of the filter.
|
String |
{MAJORITY | HALF} |
The number of contiguous (spatially connected) cells that must be of the same value before a replacement will occur.
|
String |
MajorityFilter_sa C:/data/ras_1 C:/data/final_1 FOUR MAJORITY
Scripting syntax
About getting started with writing geoprocessing scripts
MajorityFilter_sa (in_raster, out_raster, number_neighbors, majority_definition)
Parameter | Explanation | Data Type |
in_raster (Required) |
Input raster. |
Composite Geodataset |
out_raster (Required) |
The raster to be created. |
Raster Dataset |
number_neighbors (Optional) |
Number of neighboring cells to use in the kernel of the filter.
|
String |
majority_definition (Optional) |
The number of contiguous (spatially connected) cells that must be of the same value before a replacement will occur.
|
String |
# MajorityFilter_sample.py # Description: # Replaces cells in a raster based upon the majority of their # contiguous neighboring cells.# Requirements: None # Author: ESRI # Date: Sept 6, 2005 # Import system modules import arcgisscripting # Create the Geoprocessor object gp = arcgisscripting.create() try: # Set local variables outRaster = "C:/data/final_1" inRaster = "C:/data/ras_1" # Check out Spatial Analyst extension license gp.CheckOutExtension("Spatial") # Process: Majority Filter... gp.MajorityFilter_sa(inRaster, outRaster, "FOUR", "MAJORITY") except: # If an error occurred while running a tool, then print the messages. print gp.GetMessages()
Map Algebra syntax
MajorityFilter(<in_grid>, {FOUR | EIGHT}, {MAJORITY | HALF})
Parameter | Explanation |
<in_grid> | The name of a raster. |
{FOUR | EIGHT} | The number of cells in the filter kernel.
|
{MAJORITY | HALF} | The number of contiguous (spatially connected) cells that must be of the same value before a replacement will occur.
|
majorityfilter(ingrid) majorityfilter(ingrid, eight, majority) majorityfilter(ingrid, #, half) majorityfilter(ingrid1 + ingrid2, four)
ArcObjects syntax
IGeneralizeOp::MajorityFilter (raster As IGeoDataset, useDiagonalNeighborsAs Boolean, halfIsMajority As Boolean) As IGeoDataset
Parameter | Explanation |
raster | An input Raster, RasterDataset, RasterBand, or RasterDescriptor. |
useDiagonalNeighbors | A Boolean expression specifying the number of cells in the filter kernel.
If True, the kernel of the filter will be the eight nearest neighbors (a 3 by 3 window) to the present cell. If False, the kernel of the filter will be the four direct (orthogonal) neighbors to the present cell. This is the default. |
halfIsMajority | A Boolean expression specifying the number of contiguous (spatially connected) cells that must be of the same value before a replacement will occur.
If True, half of the cells must have the same value and be contiguous. Two out of four or four out of eight connected cells must have the same value. Using the Half setting will have a more smoothing effect. If False, a majority of cells must have the same value and be contiguous. Three out of four or five out of eight connected cells must have the same value. This is the default. |
' Create the GeneralizeOp object Dim pGeneralizeOp As IGeneralizeOp Set pGeneralizeOp = New RasterGeneralizeOp ' Create the input raster object Dim pInputDataset As IGeoDataset ' Calls function to open the input raster dataset from disk Set pInputDataset = OpenRasterDataset ("D:\SpatialData", "inputraster") ' Create the output dataset object Dim pOutputDataset As IGeoDataset ' Calls the method Set pOutputDataset = pGeneralizeOp.MajorityFilter (pInputDataset, True, True)