3.4.1 Pixel based classification

The classification in the application framework provides a supervised pixel-wise classification chain based on learning from multiple images, and using one specified machine learning method like SVM, Bayes, KNN, Random Forests, Artificial Neural Network, and others...(see application help of TrainImagesClassifier for further details about all the available classifiers). It supports huge images through streaming and multi-threading. The classification chain performs a training step based on the intensities of each pixel as features. Please note that all the input images must have the same number of bands to be comparable.

Statistics estimation

In order to make these features comparable between each training images, the first step consists in estimating the input images statistics. These statistics will be used to center and reduce the intensities (mean of 0 and standard deviation of 1) of samples based on the vector data produced by the user. To do so, the ComputeImagesStatistics tool can be used:

otbcli_ComputeImagesStatistics -il  im1.tif im2.tif im3.tif  
                               -out images_statistics.xml

This tool will compute each band mean, compute the standard deviation based on pooled variance of each band and finally export them to an XML file. The features statistics XML file will be an input of the following tools.

Building the training data set

As the chain is supervised, we first need to build a training set with positive examples of different objects of interest. These polygons must be saved in OGR vector format supported by GDAL like ESRI shapefile for example.

Please note that the positive examples in the vector data should have a “Class“ field with a label value higher than 1 and coherent in each images.

You can generate the vector data set with Quantum GIS software for example and save it in an OGR vector format supported by GDAL (ESRI shapefile for example). OTB Applications should be able to transform the vector data into the image coordinate system.

Performing the learning scheme

Once images statistics have been estimated, the learning scheme is the following:

  1. For each input image:
    1. Read the region of interest (ROI) inside the shapefile,
    2. Generate validation and training data within the ROI,
    3. Add vectors respectively to the training samples set and the validation samples set.
  2. Increase the size of the training samples set and balance it by generating new noisy samples from the previous ones,
  3. Perform the learning with this training set
  4. Estimate performances of the classifier on the validation samples set (confusion matrix, precision, recall and F-Score).

Let us consider a SVM classification. These steps can be performed by the TrainImagesClassifier command-line using the following:

otbcli_TrainImagesClassifier -io.il      im1.tif im2.tif im3.tif  
                             -io.vd      vd1.shp vd2.shp vd3.shp  
                             -io.imstat  images_statistics.xml  
                             -classifier svm (classifier_for_the_training)  
                             -io.out     model.svm

Additional groups of parameters are also available (see application help for more details):

Using the classification model

Once the classifier has been trained, one can apply the model to classify pixel inside defined classes on a new image using the ImageClassifier application:

otbcli_ImageClassifier -in     image.tif  
                       -imstat images_statistics.xml  
                       -model  model.svm  
                       -out    labeled_image.tif

You can set an input mask to limit the classification to the mask area with value >0.

Validating the classification model

The performance of the model generated by the TrainImagesClassifier application is directly estimated by the application itself, which displays the precision, recall and F-score of each class, and can generate the global confusion matrix as an output *.CSV file.

With the ConputeConfusionMatrix application, it is also possible to estimate the performance of a model from a classification map generated with the ImageClassifier application. This labeled image is compared to positive reference samples (either represented as a raster labeled image or as a vector data containing the reference classes). It will compute the confusion matrix and precision, recall and F-score of each class too, based on the ConfusionMatrixCalculator class.

otbcli_ComputeConfusionMatrix -in                labeled_image.tif  
                              -ref               vector  
                              -ref.vector.in     vectordata.shp  
                              -ref.vector.field  Class (name_of_label_field)  
                              -out               confusion_matrix.csv

Fancy classification results

Color mapping can be used to apply color transformations on the final graylevel label image. It allows to get an RGB classification map by re-mapping the image values to be suitable for display purposes. One can use the ColorMapping application. This tool will replace each label with an 8-bits RGB color specified in a mapping file. The mapping file should look like this :

# Lines beginning with a # are ignored  
1 255 0 0

In the previous example, 1 is the label and 255 0 0 is a RGB color (this one will be rendered as red). To use the mapping tool, enter the following :

otbcli_ColorMapping -in                labeled_image.tif  
                    -method            custom  
                    -method.custom.lut lut_mapping_file.txt  
                    -out               RGB_color_image.tif

Other look-up tables (LUT) are available : standard continuous LUT, optimal LUT, and LUT computed over a support image.

Example

We consider 4 classes: water, roads, vegetation and buildings with red roofs. Data is available in the OTB-Data repository and this image is produced with the commands inside this file.


PIC PIC PIC

Figure 3.17: From left to right: Original image, result image with fusion (with monteverdi viewer) of original image and fancy classification and input image with fancy color classification from labeled image.