Request for Changes-29: Sampling Framework - Polygon analysis

From OTBWiki
Revision as of 12:29, 16 March 2016 by Gpasero (Talk | contribs) ([Request for Changes - 29] Sampling Framework - Polygon analysis)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

[Request for Changes - 29] Sampling Framework - Polygon analysis


  • Author: Guillaume Pasero
  • Additional Contributors :
  • Submitted on 10.03.2016
  • Proposed target release : 5.4
  • Adopted : +4 (Guillaume, Julien, Manuel, Jordi)
  • Merged : cc8b62663484c3d80c81366ca3410e5160321aef


This RFC is the first part of new developments to introduce a new sampling framework for machine learning. The purpose of this RFC is to :

  • add a filter to analyse the geometries that contain training regions
  • compute the number of samples per class, and per polygon
  • handle an optional mask on the support image


This analysis is the first step to a coherent sampling strategy between several images.

Implementation details

Classes and files

A dedicated module has been added : OTBSampling (under group Learning)

A       Modules/Learning/Sampling/CMakeLists.txt
A       Modules/Learning/Sampling/include/otbOGRDataToClassStatisticsFilter.h
A       Modules/Learning/Sampling/include/otbOGRDataToClassStatisticsFilter.txx
A       Modules/Learning/Sampling/include/otbPolygonClassStatisticsAccumulator.h
A       Modules/Learning/Sampling/include/otbPolygonClassStatisticsAccumulator.txx
A       Modules/Learning/Sampling/otb-module.cmake
A       Modules/Learning/Sampling/src/CMakeLists.txt
A       Modules/Learning/Sampling/src/otbPolygonClassStatisticsAccumulator.cxx

In a nutshell :

  • otb::OGRDataToClassStatisticsFilter : Filter that computes number of samples per class or per geometry from an OGRDataSource. It can use an optional mask, thus the filter is persistent. The input support image is actually never read (only its extent is needed).
  • otb::PolygonClassStatisticsAccumulator : small class used to do the real work on OGR geometries.
  • This filter supports Polygons, Lines, Points, as well as geometry containers (multi-polygons, multi-lines, ...)


The associated application has been added in module OTBAppClassification

M       Modules/Applications/AppClassification/app/CMakeLists.txt
A       Modules/Applications/AppClassification/app/otbPolygonClassStatistics.cxx
M       Modules/Applications/AppClassification/otb-module.cmake

The statistics are exported into an XML file (like the one produced by ComputeImagesStatistics). In order to easily export/import these stats, the filter otb::StatisticsXMLFileReader and otb::StatisticsXMLFileWriter have been enhanced to support the storage of map structures :

M       Modules/IO/IOXML/include/otbStatisticsXMLFileReader.h
M       Modules/IO/IOXML/include/otbStatisticsXMLFileReader.txx
M       Modules/IO/IOXML/include/otbStatisticsXMLFileWriter.h
M       Modules/IO/IOXML/include/otbStatisticsXMLFileWriter.txx
M       Modules/IO/IOXML/otb-module.cmake
A       Modules/IO/IOXML/test/CMakeLists.txt
A       Modules/IO/IOXML/test/otbIOXMLTestDriver.cxx
A       Modules/IO/IOXML/test/otbStatisticsXMLFileWriteAndRead.cxx

In addition, missing tests have been added to the module IOXML, and some methods that were missing in the API have been added :

  • otb::StatisticsXMLFileReader::GetStatisticsVectorNames() : return available stats
  • otb::StatisticsXMLFileWriter::CleanInputs() : remove all previous inputs added with AddInput() or AddInputMap()


A       Modules/Learning/Sampling/test/CMakeLists.txt
A       Modules/Learning/Sampling/test/otbOGRDataToClassStatisticsFilterTest.cxx
A       Modules/Learning/Sampling/test/otbSamplingTestDriver.cxx
M       Modules/Applications/AppClassification/test/CMakeLists.txt

Tests have been added for the base filter (quite exhaustive), and the application (simple use-case).


TODO : start a CookBook recipe

Additional notes