ImageClassifier - Image Classification¶
Performs a classification of the input image according to a model file.
This application performs an image classification based on a model file produced by the TrainImagesClassifier application. Pixels of the output image will contain the class labels decided by the classifier (maximal class label = 65535). The input pixels can be optionally centered and reduced according to the statistics file produced by the ComputeImagesStatistics application. An optional input mask can be provided, in which case only input image pixels whose corresponding mask value is greater than 0 will be classified. By default, the remaining of pixels will be given the label 0 in the output image.
This section describes in details the parameters available for this application. Table  presents a summary of these parameters and the parameters keys to be used in command-line and programming languages. Application key is ImageClassifier .
|||Table: Parameters table for Image Classification.|
|Parameter Key||Parameter Name||Parameter Type|
|in||Input Image||Input image|
|mask||Input Mask||Input image|
|model||Model file||Input File name|
|imstat||Statistics file||Input File name|
|nodatalabel||Label mask value||Int|
|out||Output Image||Output image|
|confmap||Confidence map||Output image|
|ram||Available RAM (Mb)||Int|
|inxml||Load otb application from xml file||XML input parameters file|
|outxml||Save otb application to xml file||XML output parameters file|
- Input Image: The input image to classify.
- Input Mask: The mask allows restricting classification of the input image to the area where mask pixel values are greater than 0.
- Model file: A model file (produced by TrainImagesClassifier application, maximal class label = 65535).
- Statistics file: A XML file containing mean and standard deviation to center and reduce samples before classification (produced by ComputeImagesStatistics application).
- Label mask value: By default, hidden pixels will have the assigned label 0 in the output image. It’s possible to define the label mask by another value, but be careful to not take a label from another class (max. 65535).
- Output Image: Output image containing class labels.
- Confidence map: Confidence map of the produced classification. The confidence index depends on the model : - LibSVM : difference between the two highest probabilities (needs a model with probability estimates, so that classes probabilities can be computed for each sample) - OpenCV * Boost : sum of votes * DecisionTree : (not supported) * GradientBoostedTree : (not supported) * KNearestNeighbors : number of neighbors with the same label * NeuralNetwork : difference between the two highest responses * NormalBayes : (not supported) * RandomForest : Confidence (proportion of votes for the majority class). Margin (normalized difference of the votes of the 2 majority classes) is not available for now. * SVM : distance to margin (only works for 2-class models) .
- Available RAM (Mb): Available memory for processing (in MB).
- Load otb application from xml file: Load otb application from xml file.
- Save otb application to xml file: Save otb application to xml file.
To run this example in command-line, use the following:
otbcli_ImageClassifier -in QB_1_ortho.tif -imstat EstimateImageStatisticsQB1.xml -model clsvmModelQB1.svm -out clLabeledImageQB1.tif
To run this example from Python, use the following code snippet:
#!/usr/bin/python # Import the otb applications package import otbApplication # The following line creates an instance of the ImageClassifier application ImageClassifier = otbApplication.Registry.CreateApplication("ImageClassifier") # The following lines set all the application parameters: ImageClassifier.SetParameterString("in", "QB_1_ortho.tif") ImageClassifier.SetParameterString("imstat", "EstimateImageStatisticsQB1.xml") ImageClassifier.SetParameterString("model", "clsvmModelQB1.svm") ImageClassifier.SetParameterString("out", "clLabeledImageQB1.tif") # The following line execute the application ImageClassifier.ExecuteAndWriteOutput()
The input image must have the same type, order and number of bands than the images used to produce the statistics file and the SVM model file. If a statistics file was used during training by the TrainImagesClassifier, it is mandatory to use the same statistics file for classification. If an input mask is used, its size must match the input image size.
- These additional resources can be useful for further information:
- TrainImagesClassifier, ValidateImagesClassifier, ComputeImagesStatistics