ComputeConfusionMatrix

Computes the confusion matrix of a classification

Description

This application computes the confusion matrix of a classification map relative to a ground truth dataset. The ground truth can be provided as either a raster or a vector data. Only reference and produced pixels with values different from NoData are handled in the calculation of the confusion matrix. The confusion matrix is organized the following way: rows = reference labels, columns = produced labels. In the header of the output file, the reference and produced class labels are ordered according to the rows/columns of the confusion matrix.

Parameters

Input Image -in image Mandatory
The input classification image.

Matrix output -out filename [dtype] Mandatory
Filename to store the output matrix (csv format)

set the output format to contingency table or confusion matrix -format [confusionmatrix|contingencytable] Default value: confusionmatrix
Choice of the output format as a contingency table for unsupervised algorithmsor confusion matrix for supervised ones.

  • Choice of a confusion matrix as output.
  • Choice of a contingency table as output.

Ground truth -ref [raster|vector] Default value: raster
Choice of ground truth format

  • Ground truth as a raster image
  • Ground truth as a vector data file

Ground truth as a raster image options

Input reference image -ref.raster.in image Mandatory
Input image containing the ground truth labels

Value for nodata pixels in the reference raster -ref.raster.nodata int Default value: 0
Label to be treated as nodata in the reference raster.

Ground truth as a vector data file options

Input reference vector data -ref.vector.in filename [dtype] Mandatory
Input vector data of the ground truth

Field name -ref.vector.field string
Field name containing the label values

Value for nodata pixels in the reference vector -ref.vector.nodata int Default value: 0
Label to be treated as nodata in the reference vector. Please note that this value is always used in vector mode, to generate default values. Please set it to a value that does not correspond to a class label.


Value for nodata pixels in the input image -nodatalabel int Default value: 0
Label to be treated as nodata in the input image

Available RAM (MB) -ram int Default value: 256
Available memory for processing (in MB).

Examples

From the command-line:

otbcli_ComputeConfusionMatrix -in clLabeledImageQB1.tif -out ConfusionMatrix.csv -ref vector -ref.vector.in VectorData_QB1_bis.shp -ref.vector.field Class -ref.vector.nodata 255

From Python:

import otbApplication

app = otbApplication.Registry.CreateApplication("ComputeConfusionMatrix")

app.SetParameterString("in", "clLabeledImageQB1.tif")
app.SetParameterString("out", "ConfusionMatrix.csv")
app.SetParameterString("ref","vector")
app.SetParameterString("ref.vector.in", "VectorData_QB1_bis.shp")
app.SetParameterString("ref.vector.field", "Class")
app.SetParameterInt("ref.vector.nodata", 255)

app.ExecuteAndWriteOutput()