Sample Selection

Selects samples from a training vector data set.

Detailed 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

This section describes in details the parameters available for this application. Table [1] presents a summary of these parameters and the parameters keys to be used in command-line and programming languages. Application key is SampleSelection .

[1]Table: Parameters table for Sample Selection.
Parameter Key Parameter Type Parameter Description
in Input image Input image
mask Input image Input image
vec Input File name Input File name
out Output File name Output File name
instats Input File name Input File name
outrates Output File name Output File name
sampler Choices Choices
sampler periodic Choice Periodic sampler
sampler random Choice Random sampler
sampler.periodic.jitter Int Int
strategy Choices Choices
strategy byclass Choice Set samples count for each class
strategy constant Choice Set the same samples counts for all classes
strategy percent Choice Use a percentage of the samples available for each class
strategy total Choice Set the total number of samples to generate, and use class proportions.
strategy smallest Choice Set same number of samples for all classes, with the smallest class fully sampled
strategy all Choice Take all samples
strategy.byclass.in Input File name Input File name
strategy.constant.nb Int Int
strategy.percent.p Float Float
strategy.total.v Int Int
field List List
layer Int Int
elev Group Group
elev.dem Directory Directory
elev.geoid Input File name Input File name
elev.default Float Float
ram Int Int
rand Int Int
inxml XML input parameters file XML input parameters file
outxml XML output parameters file XML output parameters file

InputImage: Support image that will be classified.

InputMask: Validity mask (only pixels corresponding to a mask value greater than 0 will be used for statistics).

Input vectors: Input geometries to analyse.

Output vectors: Output resampled geometries.

Input Statistics: Input file storing statistics (XML format).

Output rates: Output rates (CSV formatted).

Sampler type: Type of sampling (periodic, pattern based, random). Available choices are:

  • Periodic sampler: Takes samples regularly spaced.
  • Jitter amplitude: Jitter amplitude added during sample selection (0 = no jitter).
  • Random sampler: The positions to select are randomly shuffled.

Sampling strategy Available choices are:

  • Set samples count for each class: Set samples count for each class.
  • Number of samples by class: Number of samples by class (CSV format with class name in 1st column and required samples in the 2nd.
  • Set the same samples counts for all classes: Set the same samples counts for all classes.
  • Number of samples for all classes: Number of samples for all classes.
  • Use a percentage of the samples available for each class: Use a percentage of the samples available for each class.
  • The percentage to use: The percentage to use.
  • Set the total number of samples to generate, and use class proportions.: Set the total number of samples to generate, and use class proportions.
  • The number of samples to generate: The number of samples to generate.
  • Set same number of samples for all classes, with the smallest class fully sampled: Set same number of samples for all classes, with the smallest class fully sampled.
  • Take all samples: Take all samples.

Field Name: Name of the field carrying the class name in the input vectors.

Layer Index: Layer index to read in the input vector file.

[Elevation management]: This group of parameters allows managing elevation values. Supported formats are SRTM, DTED or any geotiff. DownloadSRTMTiles application could be a useful tool to list/download tiles related to a product.

  • DEM directory: This parameter allows selecting a directory containing Digital Elevation Model files. Note that this directory should contain only DEM files. Unexpected behaviour might occurs if other images are found in this directory.
  • Geoid File: Use a geoid grid to get the height above the ellipsoid in case there is no DEM available, no coverage for some points or pixels with no_data in the DEM tiles. A version of the geoid can be found on the OTB website (http://hg.orfeo-toolbox.org/OTB-Data/raw-file/404aa6e4b3e0/Input/DEM/egm96.grd).
  • Default elevation: This parameter allows setting the default height above ellipsoid when there is no DEM available, no coverage for some points or pixels with no_data in the DEM tiles, and no geoid file has been set. This is also used by some application as an average elevation value.

Available RAM (Mb): Available memory for processing (in MB).

set user defined seed: Set specific seed. with integer value.

Load otb application from xml file: Load otb application from xml file.

Save otb application to xml file: Save otb application to xml file.

Example

To run this example in command-line, use the following:

otbcli_SampleSelection -in support_image.tif -vec variousVectors.sqlite -field label -instats apTvClPolygonClassStatisticsOut.xml -out resampledVectors.sqlite

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 SampleSelection application
SampleSelection = otbApplication.Registry.CreateApplication("SampleSelection")

# The following lines set all the application parameters:
SampleSelection.SetParameterString("in", "support_image.tif")

SampleSelection.SetParameterString("vec", "variousVectors.sqlite")

# The following line execute the application
SampleSelection.ExecuteAndWriteOutput()

Limitations

None

Authors

This application has been written by OTB-Team.