Maximum Likelihood Classification (Spatial Analyst)

Available with Spatial Analyst license.

Summary

Performs a maximum likelihood classification on a set of raster bands and creates a classified raster as output.

Learn more about how Maximum Likelihood Classification works

Usage

  • When a multiband raster is specified as one of the Input raster bands (in_raster_bands in Python), all the bands will be used.

    To process a selection of bands from a multiband raster, you can first create a new raster dataset composed of those particular bands with the Composite Bands tool, and use the result in the list of the Input raster bands (in_raster_bands in Python).

  • Any signature file created by the Create Signature, Edit Signature, or Iso Cluster tools is a valid entry for the input signature file. These will have a .gsg extension.

  • By default, all cells in the output raster will be classified, with each class having equal probability weights attached to their signatures.

  • The input a priori probability file must be an ASCII file consisting of two columns. The values in the left column represent class IDs. The values in the right column represent the a priori probabilities for the respective classes. Valid values for class a priori probabilities must be greater than or equal to zero. If zero is specified as a probability, the class will not appear on the output raster. The sum of the specified a priori probabilities must be less than or equal to one. The format of the file is as follows:

        1  .3
        2  .1
        4  .0
        5  .15
        7  .05
        8  .2

    The classes omitted in the file will receive the average a priori probability of the remaining portion of the value of one. In the above example, all classes from 1 to 8 are represented in the signature file. The a priori probabilities of classes 3 and 6 are missing in the input a priori probability file. Since the sum of all probabilities specified in the above file is equal to 0.8, the remaining portion of the probability (0.2) is divided by the number of classes not specified (2). Therefore, classes 3 and 6 will each be assigned a probability of 0.1.

  • A specified reject fraction, which lies between any two valid values, will be assigned to the next upper valid value. For example, 0.02 will become 0.025.

  • There is a direct relationship between the number of unclassified cells on the output raster resulting from the reject fraction and the number of cells represented by the sum of levels of confidence smaller than the respective value entered for the reject fraction.

  • If the Class Name in the signature file is different than the Class ID, then an additional field will be added to the output raster attribute table called CLASSNAME. For each class in the output table, this field will contain the Class Name associated with the class. For example, if the Class Names for the classes in the signature file are descriptive string names (for example, conifers, water, and urban), these names will be carried to the CLASSNAME field.

  • The extension for an input a priori probability file is .txt.

  • See Analysis environments and Spatial Analyst for additional details on the geoprocessing environments that apply to this tool.

Parameters

LabelExplanationData Type
Input raster bands

The input raster bands.

While the bands can be integer or floating point type, the signature file only allows integer class values.

Raster Layer
Input signature file

The input signature file whose class signatures are used by the maximum likelihood classifier.

A .gsg extension is required.

File
Reject fraction
(Optional)

Select a reject fraction, which determines whether a cell will be classified based on its likelihood of being correctly assigned to one of the classes. Cells whose likelihood of being correctly assigned to any of the classes is lower than the reject fraction will be given a value of NoData in the output classified raster.

  • 0.0 —
  • 0.005 —
  • 0.01 —
  • 0.025 —
  • 0.05 —
  • 0.1 —
  • 0.25 —
  • 0.5 —
  • 0.75 —
  • 0.9 —
  • 0.95 —
  • 0.975 —
  • 0.99 —
  • 0.995 —
String
A priori probability weighting
(Optional)

Specifies how a priori probabilities will be determined.

  • Equal — All classes will have the same a priori probability.
  • Sample — A priori probabilities will be proportional to the number of cells in each class relative to the total number of cells sampled in all classes in the signature file.
  • File —The a priori probabilities will be assigned to each class from an input ASCII a priori probability file.
String
Input a priori probability file
(Optional)

A text file containing a priori probabilities for the input signature classes.

An input for the a priori probability file is only required when the File option is used.

The extension for the a priori file can be .txt or .asc.

File
Output confidence raster
(Optional)

The output confidence raster dataset shows the certainty of the classification in 14 levels of confidence, with the lowest values representing the highest reliability. If there are no cells classified at a particular confidence level, that confidence level will not be present in the output confidence raster.

It will be of integer type.

Raster Dataset

Return Value

LabelExplanationData Type
Output classified raster

The output classified raster.

It will be of integer type.

Raster

MLClassify(in_raster_bands, in_signature_file, {reject_fraction}, {a_priori_probabilities}, {in_a_priori_file}, {out_confidence_raster})
NameExplanationData Type
in_raster_bands
[in_raster_band,...]

The input raster bands.

While the bands can be integer or floating point type, the signature file only allows integer class values.

Raster Layer
in_signature_file

The input signature file whose class signatures are used by the maximum likelihood classifier.

A .gsg extension is required.

File
reject_fraction
(Optional)

Select a reject fraction, which determines whether a cell will be classified based on its likelihood of being correctly assigned to one of the classes. Cells whose likelihood of being correctly assigned to any of the classes is lower than the reject fraction will be given a value of NoData in the output classified raster.

The default value is 0.0, which means that every cell will be classified.

Valid entries are:

  • 0.0
  • 0.005
  • 0.01
  • 0.025
  • 0.05
  • 0.1
  • 0.25
  • 0.5
  • 0.75
  • 0.9
  • 0.95
  • 0.975
  • 0.99
  • 0.995
String
a_priori_probabilities
(Optional)

Specifies how a priori probabilities will be determined.

  • EQUAL All classes will have the same a priori probability.
  • SAMPLE A priori probabilities will be proportional to the number of cells in each class relative to the total number of cells sampled in all classes in the signature file.
  • FILEThe a priori probabilities will be assigned to each class from an input ASCII a priori probability file.
String
in_a_priori_file
(Optional)

A text file containing a priori probabilities for the input signature classes.

An input for the a priori probability file is only required when the File option is used.

The extension for the a priori file can be .txt or .asc.

File
out_confidence_raster
(Optional)

The output confidence raster dataset shows the certainty of the classification in 14 levels of confidence, with the lowest values representing the highest reliability. If there are no cells classified at a particular confidence level, that confidence level will not be present in the output confidence raster.

It will be of integer type.

Raster Dataset

Return Value

NameExplanationData Type
out_classified_raster

The output classified raster.

It will be of integer type.

Raster

Code sample

MaximimumLikelihoodClassification example 1 (Python window)

This example creates an output classified raster containing five classes derived from an input signature file and a multiband raster.

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
mlcOut = MLClassify("redlands", "c:/sapyexamples/data/wedit5.gsg", "0.0", 
                    "EQUAL", "", "c:/sapyexamples/output/redmlcconf")
mlcOut.save("c:/sapyexamples/output/redmlc")
MaximimumLikelihoodClassification example 2 (stand-alone script)

This example creates an output classified raster containing five classes derived from an input signature file and a multiband raster.

# Name: MLClassify_Ex_02.py
# Description: Performs a maximum likelihood classification on a set of 
#    raster bands.
# 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 = "redlands"
sigFile = "c:/sapyexamples/data/wedit5.gsg"
probThreshold = "0.0"
aPrioriWeight = "EQUAL"
aPrioriFile = ""
outConfidence = "c:/sapyexamples/output/redconfmlc"


# Execute 
mlcOut = MLClassify(inRaster, sigFile, probThreshold, aPrioriWeight, 
                    aPrioriFile, outConfidence) 

# Save the output 
mlcOut.save("c:/sapyexamples/output/redmlc02")

Licensing information

  • Basic: Requires Spatial Analyst
  • Standard: Requires Spatial Analyst
  • Advanced: Requires Spatial Analyst

Related topics