K-Means unsupervised classification calculates initial class means evenly distributed in the data space then iteratively clusters the pixels into the nearest class using a minimum distance technique. Each iteration recalculates class means and reclassifies pixels with respect to the new means. All pixels are classified to the nearest class unless a standard deviation or distance threshold is specified, in which case some pixels may be unclassified if they do not meet the selected criteria. This process continues until the number of pixels in each class changes by less than the selected pixel change threshold or the maximum number of iterations is reached.


Tou, J. T. and R. C. Gonzalez, 1974. Pattern Recognition Principles, Addison-Wesley Publishing Company, Reading, Massachusetts.

  1. From the Toolbox, select Classification > Unsupervised Classification > K-Means Classification. The Classification Input File dialog appears.
  2. Select an input file and perform optional spatial and spectral subsetting, and/or masking, then click OK. The K-Means Parameters dialog appears.
  3. Enter the number of classes and maximum number of iterations in the fields provided.
  4. Enter a Change Threshold % (0-100%) which ENVI uses to end the iterative process when the number of pixels in each class changes by less than the threshold. The classification ends when either this threshold is met or the maximum number of iterations is reached.
  5. To set the optional standard deviation to use around the class mean and/or the maximum allowable distance error (in DN), enter the values in the Maximum Stdev From Mean or Maximum Distance Error fields, respectively.

    If you enter values for both of these optional parameters, the classification uses the smaller of the two to determine which pixels to classified. If you do not enter a value for either parameter, then all pixels are classified.

  6. Select output to File or Memory.
  7. Click OK. The status bar cycles from 0 to 100% for each iteration of the classifier. ENVI adds the resulting output to the Layer Manager. ENVI computes the statistics for the initial class seeds with a skip factor of 2.5 for both the sample and line directions.