Majority Filter (Spatial Analyst)

License Level:BasicStandardAdvanced

Summary

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
OutRas = MajorityFilter(InRas1)

Usage

Syntax

MajorityFilter (in_raster, {number_neighbors}, {majority_definition})
ParameterExplanationData Type
in_raster

The input raster to be filtered based on the the majority of contiguous neighboring cells.

It must be of integer type.

Raster Layer
number_neighbors
(Optional)

Determines the 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)

Specifies 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 option will have a more smoothing effect.
String

Return Value

NameExplanationData Type
out_raster

The output filtered raster.

Raster

Code Sample

MajorityFilter example 1 (Python window)

This example filters the input raster using all eight neighbors, with the greater smoothing effect by requiring half of them to have the same value for replacement.

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outMajFilt = MajorityFilter("land", "EIGHT", "HALF")
outMajFilt.save("c:/sapyexamples/output/outmajfilt")
MajorityFilter example 2 (stand-alone script)

This example filters the input raster using all eight neighbors, with the greater smoothing effect by requiring half of them to have the same value for replacement.

# Name: MajorityFilter_Ex_02.py
# Description: Replaces cells in a raster based on the 
#              majority of their contiguous neighboring cells.
# Requirements: Spatial Analyst Extension

# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *

# Set environment settings
env.workspace = "C:/sapyexamples/data"

# Set local variables
inRaster = "land"

# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")

# Execute MajorityFilter
outMajFilt = MajorityFilter(inRaster, "EIGHT", "HALF")

# Save the output 
outMajFilt.save("c:/sapyexamples/output/majfilter")

Environments

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Requires Spatial Analyst
ArcGIS for Desktop Standard: Requires Spatial Analyst
ArcGIS for Desktop Advanced: Requires Spatial Analyst
11/8/2012