Support GDAL statitistics into OTB
What changes will be made and why they would make a better Orfeo ToolBox?
This issue is about computing full-image statistics (min, max, mean, standard-deviation) and histogram on all bands as a Monteverdi-driven background task.
Currently, since it takes considerable time to process full image-data, Monteverdi approximates this calculation by doing it synchronously on a reduced pixel-data set which is the 512x512 best-fit overview. However, GDAL allows to compute full image-data statistics and store them in its meta-data file. This feature could be used by Monteverdi and OTB in order to process full image-data statistics and histogram in a background task and store it for future use.
High level description
GDAL
At the lowest level, the GDAL API provides some statistics and histogram functions on full or resampled image-data. The following ones could be used:
-
GDALRasterBand::ComputeStatistics()
: compute statistics (min, max, mean, standard-deviation) and usually caches it, if possible -
GDALRasterBand::GetStatistics()
: gets cached statistics, if available -
GDALRasterBand::SetStatistics()
: caches statistics -
GDALRasterBand::GetHistogram()
: computes histogram data -
GDALRasterBand::SetDefaultHistogram()
: stores default histogram data -
GDALRasterBand::GetDefaultHistogram()
: fetches default histogram data
When histogram-data has been processed by GDALRasterBand::GetHistogram()
on full image-data, it could be stored as the default histogram for further uses by using GDALRasterBand::SetDefaultHistogram()
.
OTB
Similarly to ITK, otb::ImageFileReader
and otb::ImageFileWriter
use the otb::ImageIOBase
abstract class in order to access image-data via polymorphism. The abstract interface of this class could be improved in order to mimic the GDAL API by adding the following pure virtual functions:
::SupportsStatistics()
::GetStatistics()
::SetStatistics()
::SupportsHistogram()
::GetHistogram()
::GetDefaultHistogram()
::SetDefaultHistogram()
This interface can be implemented in the otb::GDALImageIO
using the GDAL API. Other otb::ImageIOBase
-derived classes could use the ITK classes to compute statistics and histogram.
Likewise, the otb::ImageFileReader
and otb::ImageFileWriter
interfaces could be improved the same way by simply forwarding calls to their underlying otb::ImageIOBase
instances.
Monteverdi
A QToolButton
could be added to the histogram QDockWidget
in order to start the background computation. The GDAL API statistics and histogram functions provide a progress callback which can be linked to a QProgressBar
of the Monteverdi QStatusBar
. Also, the background computation could be linked to Monteverdi, thanks to the already existing mvd::BackgroundTask
and mvd::AbstractWorkerThread
classes.
Also, a statistics editor QWidget
could be implemented and added as a QDockWidget
tabbed with the histogram one.
Similarly to the histogram-view, the statistics computation could be done asynchronously and ordered from a QToolButton
which could be added to the statistics QDockWidget
.
Risks and benefits
OTB would benefit from an API allowing to drive cached statistics and histogram computation on full image-data directly from otb::ImageFileReader
and otb::ImageFileWriter
. Moreover, the implementation of a otb::HistogramDataObject
and some statistics and histogram filters based on the above-mentioned API could be considered (or, maybe the refactoring of existing filters) in order to use statistics and histogram as input and output in OTB pipelines.
However, the use of the No-Data value is not stated in the documentation of statistics and histogram functions of the GDAL API and should be checked (source code and/or experimentaly). Moreover, since the user can edit and enable/disable the use of the No-Data value which should be taken into acount in the statistics and histograms computations, the statistics and histogram might be inconsistent with image-data setup. Thus, a guarding or identifying mechanism should be discussed (e.g. adding the No-Data value of the last computation in the GDAL meta-data and/or popping-up a warning/failure dialog in Monteverdi).
Alternatives for implementations
Not Applicable.
Who will be developing the proposed changes?
(TBD) :
- Developer who has strong knowledge of OTB and ITK core IO and pipeline.
- Developer who has strong knowledge of Monteverdi Model-View-Controller architecture.