ENVICalculateConfusionMatrixFromRaster

This function returns a reference to an ENVIConfusionMatrix object computed from a classification raster and truth regions of interest (ROIs).

The classification raster contains predicted class values from a classification, which are accompanied by class names. The truth ROIs contain the actual, or expected, class names of a particular region of the raster. A confusion matrix is created by comparing the predicted names to the truth names.

Example

The code example below evaluates classifications using a confusion matrix.

PRO EvaluateClassificationUsingConfusionMatrix

    COMPILE_OPT IDL2

 

    ; Start the application

    e = ENVI()

 

    ; Open an input file

    File = Filepath('qb_boulder_msi', Subdir=['data'], $

    Root_Dir=e.Root_Dir)

    Raster = e.OpenRaster(File)

    File2 = Filepath('qb_boulder_roi.xml', Subdir=['data'], $

    Root_Dir=e.Root_Dir)

    Rois = envi.OpenROI(roiFile)

 

    ; Get training statistics

    StatTask = ENVITask('ROIStatistics')

    StatTask.INPUT_RASTER = Raster

    StatTask.INPUT_ROI = Rois

    StatTask.Execute

 

    ; Get the task from the catalog of ENVITasks

    Task = ENVITask('MahalanobisDistanceClassification')

 

    ; Define inputs

    Task.INPUT_RASTER = Raster

    Task.COVARIANCE = StatTask.Covariance

    Task.MEAN = StatTask.Mean

    Task.CLASS_PIXEL_COUNT = StatTask.Roi_Pixel_Count

    Task.CLASS_NAMES = [Rois[0].name, Rois[1].name, Rois[2].name]

    Task.CLASS_COLORS = [[0,0,255], [0,255,0], [255,0,0]]

 

    ; Run the task and display the result

    Task.Execute

    ClassRaster = Task.OUTPUT_RASTER

    View = e.GetView()

    Layer = View.CreateLayer(ClassRaster)

 

    ; Add the output to the Data Manager

    envi.Data.Add, ClassRaster

 

    ; Calculate the confusion matrix

    ConfusionMatrix = ENVICalculateConfusionMatrixFromRaster(ClassRaster, Rois)

 

    ; Print results

    Print, 'Confusion Matrix:'

    Print, ConfusionMatrix.Confusion_Matrix

    Print, 'Errors of commission: '

    Print, Transpose([[ConfusionMatrix.Column_Names+': '], [(ConfusionMatrix.CommissionError()).ToString()]])

    Print, 'Errors of omission: '

    Print, Transpose([[ConfusionMatrix.Column_Names+': '], [(ConfusionMatrix.OmissionError()).ToString()]])

    Print, 'Overall accuracy: ', ConfusionMatrix.Accuracy()

END

Syntax

Result = ENVICalculateConfusionMatrixFromRaster(Input_Raster, Input_ROIs [, Keywords=value])

Return Value

This function returns a reference to an ENVIConfusionMatrix object.

Arguments

Input_Raster

Specify a classification ENVIRaster.

Input_ROIs

Specify an array of ENVIROIs containing ground truth data.

Keywords

ERROR (optional)

Set this keyword to a named variable that will contain any error message issued during execution of this routine. If no error occurs, the ERROR variable will be set to a null string (''). If an error occurs and the routine is a function, then the function result will be undefined.

When this keyword is not set and an error occurs, ENVI returns to the caller and execution halts. In this case, the error message is contained within !ERROR_STATE and can be caught using IDL's CATCH routine. See IDL Help for more information on !ERROR_STATE and CATCH.

See Manage Errors for more information on error handling in ENVI programming.

Version History

ENVI 5.4

Introduced

API Version

4.2

See Also

ENVIConfusionMatrix, CalculateConfusionMatrixFromRaster Task