Show Navigation | Hide Navigation
You are here:
Extensions > Spatial Analyst > Spatial Analyst functional reference > Generalization (Spatial Analyst)

Majority Filter

Release 9.2
Last modified January 3, 2008
E-mail This Topic Printable Version Give Us Feedback

Print all topics in : "Generalization (Spatial Analyst)"


Related Topics

Replaces cells in a raster based on the majority of their contiguous neighboring cells.

Learn more about how Majority Filter works


Illustration

Majority Filter illustration

Usage tips

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.

  • FOUR  — The kernel of the filter will be the four direct (orthogonal) neighbors to the present cell. This is the default.
  • EIGHT  — The kernel of the filter will be the eight nearest neighbors (a 3 by 3 window) to the present cell.

String
{MAJORITY | HALF}

The number of contiguous (spatially connected) cells that must be of the same value before a replacement will occur.

  • MAJORITY  — 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.
  • HALF  — 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.

String
Data types for geoprocessing tool parameters


Command line example

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.

  • FOUR  — The kernel of the filter will be the four direct (orthogonal) neighbors to the present cell. This is the default.
  • EIGHT  — The kernel of the filter will be the eight nearest neighbors (a 3 by 3 window) to the present cell.

String
majority_definition (Optional)

The number of contiguous (spatially connected) cells that must be of the same value before a replacement will occur.

  • MAJORITY  — 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.
  • HALF  — 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.

String

Data types for geoprocessing tool parameters


Script example

# 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.
  • FOUR  — The kernel of the filter will be the four direct (orthogonal) neighbors to the present cell. This is the default.
  • EIGHT  — The kernel of the filter will be the eight nearest neighbors (a 3 by 3 window) to the present cell.
{MAJORITY | HALF} The number of contiguous (spatially connected) cells that must be of the same value before a replacement will occur.
  • MAJORITY  — 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.
  • HALF  — 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.

Map Algebra example

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.

ArcObjects example

' 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)

Please visit the Feedback page to comment or give suggestions on ArcGIS Desktop Help.
Copyright © Environmental Systems Research Institute, Inc.