# SampleSelection

## Brief Description

Selects samples from a training vector data set.

## Tags

Learning

## Long Description

The application selects a set of samples from geometries intended for training (they should have a field giving the associated class). First of all, the geometries must be analyzed by the PolygonClassStatistics application to compute statistics about the geometries, which are summarized in an xml file. Then, this xml file must be given as input to this application (parameter instats). The input support image and the input training vectors shall be given in parameters 'in' and 'vec' respectively. Only the sampling grid (origin, size, spacing)will be read in the input image. There are several strategies to select samples (parameter strategy) : - smallest (default) : select the same number of sample in each class so that the smallest one is fully sampled. - constant : select the same number of samples N in each class (with N below or equal to the size of the smallest class). - byclass : set the required number for each class manually, with an input CSV file (first column is class name, second one is the required samples number). - percent: set a target global percentage of samples to use. Class proportions will be respected. - total: set a target total number of samples to use. Class proportions will be respected. There is also a choice on the sampling type to performs : - periodic : select samples uniformly distributed - random : select samples randomly distributed Once the strategy and type are selected, the application outputs samples positions(parameter out). The other parameters to look at are : - layer : index specifying from which layer to pick geometries. - field : set the field name containing the class. - mask : an optional raster mask can be used to discard samples. - outrates : allows outputting a CSV file that summarizes the sampling rates for each class. As with the PolygonClassStatistics application, different types of geometry are supported : polygons, lines, points. The behavior of this application is different for each type of geometry : - polygon: select points whose center is inside the polygon - lines : select points intersecting the line - points : select closest point to the provided point

## Parameters

- [param] -in <string> Support image that will be classified. Mandatory: True. Default Value: ""
- [param] -mask <string> Validity mask (only pixels corresponding to a mask value greater than 0 will be used for statistics). Mandatory: False. Default Value: ""
- [param] -vec <string> Input geometries to analyse. Mandatory: True. Default Value: ""
- [param] -out <string> Output resampled geometries. Mandatory: True. Default Value: ""
- [param] -instats <string> Input file storing statistics (XML format). Mandatory: True. Default Value: ""
- [param] -outrates <string> Output rates (CSV formatted). Mandatory: False. Default Value: ""
- [param] -field <string> Name of the field carrying the class name in the input vectors.. Mandatory: False. Default Value: "class"
- [param] -layer <int32> Layer index to read in the input vector file.. Mandatory: False. Default Value: "0"
- [param] -ram <int32> Available memory for processing (in MB). Mandatory: False. Default Value: "128"
- [param] -rand <int32> Set specific seed. with integer value.. Mandatory: False. Default Value: "0"
- [param] -inxml <string> Load otb application from xml file. Mandatory: False. Default Value: ""
- [param] -outxml <string> Save otb application to xml file. Mandatory: False. Default Value: ""
[choice] -sampler Type of sampling (periodic, pattern based, random) periodic,random. Mandatory: True. Default Value: "periodic"

- [group] -periodic

- [param] -sampler.periodic.jitter <int32> Jitter amplitude added during sample selection (0 = no jitter). Mandatory: False. Default Value: "0"

- [group] -random

[choice] -strategy byclass,constant,percent,total,smallest,all. Mandatory: True. Default Value: "smallest"

- [group] -byclass

- [param] -strategy.byclass.in <string> Number of samples by class (CSV format with class name in 1st column and required samples in the 2nd.. Mandatory: True. Default Value: ""

- [group] -constant

- [param] -strategy.constant.nb <int32> Number of samples for all classes. Mandatory: True. Default Value: "0"

- [group] -percent

- [param] -strategy.percent.p <float> The percentage to use. Mandatory: True. Default Value: "0.5"

- [group] -total

- [param] -strategy.total.v <int32> The number of samples to generate. Mandatory: True. Default Value: "1000"

- [group] -smallest

- [group] -all

## Limitations

None

## Authors

OTB-Team

## See Also

## Example of use

- in: support_image.tif

- vec: variousVectors.sqlite

- field: label

- instats: apTvClPolygonClassStatisticsOut.xml

- out: resampledVectors.sqlite