k-means classification

This tool can be used to perform classification, or clustering, in a group of images. This is most commonly applied to land cover classification using multi-spectral, remotely sensed images. Other applications and input data are, however, possible (e.g. this tool could be used for performing landform classification when applied to a group of terrain attribute images).

The user must specify the names of two or more input raster images. The user must also specify the complete name, including directory, of the output image. The user determines the maximum number of classes (k) in the output image. In some cases, fewer classes than the maximum will be identified.

Algorithm Description

k-means classification finds statistically similar groups in multi-spectral space, and is therefore, a type of unsupervised classifier. The algorithm starts by randomly locating k clusters in spectral space. Each pixel in the input image group are then assigned to the nearest cluster centre and the cluster centre locations are moved to the average of their class values. This process is then repeated until a stopping condition is met. The stopping condition may either be a maximum number of iterations (specified by the user) or a tolerance threshold which designates the smallest possible distance to move cluster centres before stopping the iterative process.

See Also:

Scripting:

The following is an example of a Python script using this tool:

wd = pluginHost.getWorkingDirectory()
# You may have multiple input files but they must
# be separated by semicolons in the string.
inputFiles = wd + "input1.dep" + ";" + wd + "input2.dep" + ";" + wd + "input3.dep"
outputFile = wd + "output.dep"
numClasses = "10"
maxNumIterations = "25"
changeThreshold = "2.0"
initialize = "randomly"
args = [inputFiles, outputFile, numClasses, maxNumIterations, changeThreshold, initialize]
pluginHost.runPlugin("kMeansClassification", args, False)

This is a Groovy script also using this tool:

def wd = pluginHost.getWorkingDirectory()
// You may have multiple input files but they must
// be separated by semicolons in the string.
def inputFiles = wd + "input1.dep" + ";" + wd + "input2.dep" + ";" + wd + "input3.dep"
def outputFile = wd + "output.dep"
def numClasses = "10"
def maxNumIterations = "25"
def changeThreshold = "2.0"
def initialize = "with max dispersion along diagonal"
String[] args = [inputFiles, outputFile, numClasses, maxNumIterations, changeThreshold, initialize]
pluginHost.runPlugin("kMeansClassification", args, false)

Credits: