The SVM classification framework
The aim of the new SVM classification framework is to provide a supervised pixel-wise classification chain based on learning from multiple images. It supports huge images through streaming and multi-threading.
Please note that this framework is still in development. We would be glad to receive feedbacks on these tools.
Building a training data set
The chain is supervised : one has to build a training set with positive examples of different objects of interest. This can be done with the Vectorization Monteverdi module, by building a VectorData containing polygons centered on occurrences of the different objects of interest. This operation will be reproduce on each images used as input of the training function.
Please note that the positive examples in the vector data should have a Class field with a label higher than 1 and coherent in each different images.
Training the classification tool
The classification chain will perform a SVM training step based on the intensities of each pixel as features. Please note that the images will have the same number of bands to be comparable.
In order to make these features comparable between each images, the first step is to estimate the statistic of the group of input images. These statistics will be used to center and reduce the intensities (mean of 0, std dev of 1) of samples based on the vector data produced by the user. To do so, the otbEstimateImagesStatistics tool can be used :
otbEstimateImagesStatistics-cli -in list_of_input_images -out statistics.xml
This tool will compute the mean of each band, compute the standard deviation based on pooled variance of each band and finally exporting them to an XML file.
The features statistics XML file will be an input of the following tools.
Once images statistics have been estimated, the learning scheme is the following :
- For each of the input images
- Read the region of interest (ROI) inside the shapefile,
- Generate validation and training data within the ROI,
- Add the vectors respectively to the training samples set and the validation samples set.
- Center and reduce each sample using statistics from the XML statistics file,
- Increase the size of the training samples set and balance it by generating new noisy samples from the previous ones,
- SVM learn with this training set
- Estimate performances of the SVM classifier on the validation samples set (confusion matrix, precision, recall).
These steps can be performed by the otbTrainImagesClassifier using the following :
otbTrainImagesClassifier-cli -is images_statistics.xml -in list_of_input_images -vd list_of_positive_examples_shapefiles -out model.svm -b
Some options are available:
- -dem a DEM repository to keep accurate reprojection of vectordata
- -m margin_value
- -k svm_kernel (0 = LINEAR (default), 1 = RBF, 2 = POLY, 3 = SIGMOID)
- -opt use svm parameters optimization
- -mt maximum_training_samples_size
- -mv maximum_validation_samples_size
- -vrt ratio_validation_training
Validate the classification model
It is also possible to estimate the performance of the svm model with a new set of validation samples and another image with the following application. It will compute the global confusion matrix and precision, recall and F-score of each class based on the ConfusionMatrixCalculator class. It is done by otbValidateImagesClassifier:
otbValidateImagesClassifier-cli -is images_statistics.xml -svm model.svm -in input_image -vd list_of_positive_examples_shapefiles
You can save these results with the option -out output_filename. You can set a DEM repository (-dem) to keep accurate reprojection of vectordata
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 otbImageSVMClassifier tool:
otbImageSVMClassifier-cli -is images_statistics.xml -svm model.svm -in input_image -out labeled_image
You can set an input mask to restricted the classification to the mask area with value >0.
Fancy classification results
In order to get an RGB classification map instead of greylevel labels, one can use the otbLabeledImageColorMapping tool. This tool will replace each label with an 8-bits RGB color specificied 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 :
otbLabeledImageColorMapping-cli -in labeled_image -out color_image -ct mapping_file