Vector Classification

Hi everyone,

How to use the “Vector Classification” tool?, I’m traying to make a classification using stratifield statistic means of the polygon segmentation, nevertheless, how much squeeze the process is creating a new field in the shape file that should have value of the classes, based on the model generated in the traininimagesClassifer. Although a new field is created in the shape file processed in the “Vector Classification” the values that appear are 1 for all polygons. This process should create a new field with class values based on the media model, but not generate.

Someone can help me?



If I understand correctly you are trying to:

  • Train a supervised classifier on an image :
otbcli_TrainImagesClassifier -classifier rf inputImage  -io.vd classif_train.shp -io.out model.txt   -sample.vfn classlabel
  • Apply segmentation to this image, e.g.
otbcli_Segmentation  -in ../S2A_ROI.tif -mode.vector.out segmentation.shp -filter watershed
  • Compute the mean on each resulting segment, for each band of the input image, e.g.
otbcli_ZonalStatistics  -in ../S2A_ROI.tif segmentation.shp -out.vector.filename zonalStats.shp
  • Perform classification on the segment, using the trained model and the computed means:
otbcli_VectorClassifier  -in zonalStats.shp -model model.txt -feat mean_0 mean_1 mean_2 mean_3  -cfield predicted -out objectClassification.shp

I just tried it on some test data with the mentioned applications, and it works pretty well! If this is what you are trying to do.

Hope that helps,



I was about to start a new thread, but noted that my question relates to this one. Would it be possible to clarify the role of parameter ‘io.stats’ in otbcli_TrainImagesClassifier and ‘instat’ in otbcli_VectorClassifier?

From my tests, I have found that the tools work correctly when this parameter is omitted and most examples do not reference it. If this is the case, should the tool & corresponding documentation should be updated to remove this parameter?


These parameters can be used to provide statistic files to perform normalization (or feature scaling), before the training or the classification. The file should contain mean and stddev for each band/feature of the input data. Note that this file can be generated from an input image using the ComputeImagesStatistics application.

Whether you should perform normalization before training/classification depends of the algorithm used. For example algorithms using distances (KNN, svm …), if you don’t perform normalization some features (or bands) of the input image will have less weight in the classification than others. But for some algorithms like random forest normalization doesn’t matter and hence should not be performed.


Dear Cédric,

Thank you very much for the information.
I have one more question, because I still can’t run VectorClassifier. I would like to sort the vector based on segmentation in LargeScaleMeanShift - LSMS. In the option TrainImagesClassifier is a polygon that I must create before running LSMS, correct? but should this count count in the code attributes for the classes? In OTB, I didn’t find zonalStatistics, only ObjectRadiometricStatistic, is it the same algorithm as zonal?

thank you