Loading...
Searching...
No Matches
AssistedHarmonization.h
Go to the documentation of this file.
1/* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2
3 This file is part of the TerraLib - a Framework for building GIS enabled applications.
4
5 TerraLib is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 TerraLib is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with TerraLib. See COPYING. If not, write to
17 TerraLib Team at <terralib-team@terralib.org>.
18 */
19
20#ifndef __TERRALIB_RP_INTERNAL_ASSISTEDHARMONIZATION_H
21#define __TERRALIB_RP_INTERNAL_ASSISTEDHARMONIZATION_H
22
23#include "Algorithm.h"
24#include "../raster/Raster.h"
25#include "../geometry/Polygon.h"
27
28#include <boost/ptr_container/ptr_vector.hpp>
29
30#include <vector>
31#include <map>
32#include <string>
33
34namespace te
35{
36 namespace rp
37 {
38 /*!
39 \class AssistedHarmonization
40 \brief Performs raster data assisted histogram harmonization.
41 \ingroup rp_gen
42 \sa Reference: MOREIRA, N. A. P. ; KORTING, T. S. ; DUTRA, L. V. ; CASTEJON, E. F. ; ARAI, E. . Calibração relativa para extensão de assinaturas em série de imagens MODIS. Journal of Information and Data Management, v. 20, p. 230-236, 2019.
43 */
45 {
46 public:
47
48 /*!
49 \class InputParameters
50 \brief AssistedHarmonization input parameters
51 */
53 {
54 public:
55
57
58 typedef unsigned int TargetAreasClassIDT;
59
60 typedef std::vector< TargetAreasGeomT* > TargetAreasGeomContT;
61
62 typedef std::map< TargetAreasClassIDT, TargetAreasGeomContT >
64
65 /*! \enum BlendMethod te::rp::Blender class pixel blend methods. */
67 {
68 InvalidMethod = 0, //!< Invalid method.
69 MeanStdHMethod = 1, //!< Mean and Standart deviation are used to perform equalization by gain and offset.
70 MSEHMethod = 2 //!< Mean square errors of classes means are used to calculate gain & offset"
71 };
72
74
75 bool m_enableProgress; //!< Enable/Disable the progress interface (default:false).
76
77 te::rst::Raster const* m_refInputRasterPtr; //!< Reference Input raster.
78
79 std::vector< unsigned int > m_refInputRasterBands; //!< Referebce input raster bands to process.
80
81 te::rst::Raster const* m_adjInputRasterPtr; //!< Adjust Input raster.
82
83 std::vector< unsigned int > m_adjInputRasterBands; //!< Adjust input raster bands to process.
84
85 TargetAreasContT m_referenceTargetAreas; //!< Areas of interest over the reference image groupped by class ID.
86
87 TargetAreasContT m_adjustTargetAreas; //!< Areas of interest over the adjust image groupped by class ID.
88
90
92
94
95 //overload
96 void reset() ;
97
98 //overload
99 const InputParameters& operator=( const InputParameters& params );
100
101 //overload
103
104 //overload
105 bool serialize ( AlgorithmParametersSerializer& serializer ) const;
106
107 void getMethodsInfo( std::map< HarmonizationMethod, std::pair<
108 std::string, std::string > >& info ) const;
109 };
110
111 /*!
112 \class OutputParameters
113 \brief AssistedHarmonization output parameters
114 */
116 {
117 public:
118
119 std::string m_rType; //!< Output raster data source type (as described in te::raster::RasterFactory ).
120
121 std::map< std::string, std::string > m_rInfo; //!< The necessary information to create the output rasters (as described in te::raster::RasterFactory).
122
123 std::unique_ptr< te::rst::Raster > m_outputRasterPtr; //!< The generated output registered raster.
124
125 std::vector< double > m_gains; //!< The bands gains used to generate the output raster (output = ( ( input - input_offset ) * gain ) + output_offset).
126
127 std::vector< double > m_inOffsets; //!< The bands input offsets used to generate the output raster (output = ( ( input - input_offset ) * gain ) + output_offset).
128
129 std::vector< double > m_outOffsets; //!< The bands output offsets used to generate the output raster (output = ( ( input - input_offset ) * gain ) + output_offset).
130
132
134
136
137 //overload
138 void reset() ;
139
140 //overload
142
143 //overload
145 };
146
148
150
151 //overload
152 bool execute( AlgorithmOutputParameters& outputParams ) ;
153
154 //overload
155 void reset() ;
156
157 //overload
158 bool initialize( const AlgorithmInputParameters& inputParams ) ;
159
160 bool isInitialized() const;
161
162 protected:
163
165
166 bool m_isInitialized; //!< Tells if this instance is initialized.
167
169 const te::mem::CachedRaster& adjInputCRaster,
170 const std::vector< double >& gains,
171 const std::vector< double >& inputOffsets,
172 const std::vector< double >& outputOffsets,
174
176 const te::mem::CachedRaster& refInputCRaster,
177 const te::mem::CachedRaster& adjInputCRaster,
178 const InputParameters::TargetAreasContT& referenceTargetAreasReproj,
179 const InputParameters::TargetAreasContT& adjustTargetAreasReproj,
181
183 const te::mem::CachedRaster& refInputCRaster,
184 const te::mem::CachedRaster& adjInputCRaster,
185 const InputParameters::TargetAreasContT& referenceTargetAreasReproj,
186 const InputParameters::TargetAreasContT& adjustTargetAreasReproj,
188
190 const te::rst::Raster& inputRaster,
191 const std::vector< unsigned int >& inputRasterBandsIndexes,
192 const InputParameters::TargetAreasContT& targetAreas,
193 std::map< InputParameters::TargetAreasClassIDT, unsigned int>& samplesNumber,
194 std::map< unsigned int, std::vector< double > >& means,
195 std::map< unsigned int, std::vector< double > >& stdDevs ) const;
196
200 boost::ptr_vector< InputParameters::TargetAreasGeomT >& outGeomHandler,
201 const int targetSRID );
202
203 // gains and offsets under reference ranges.
204 // gain = ref / adj
205 // off = ref - ( gain * adj )
207 const std::map< InputParameters::TargetAreasClassIDT, std::vector< double > >&
208 referenceMeans,
209 const std::map< InputParameters::TargetAreasClassIDT, std::vector< double > >&
210 referenceStdDevs,
211 const std::map< InputParameters::TargetAreasClassIDT, unsigned int>&
212 referenceSamplesNumber,
213 const std::map< InputParameters::TargetAreasClassIDT, std::vector< double > >&
214 adjustMeans,
215 const std::map< InputParameters::TargetAreasClassIDT, std::vector< double > >&
216 adjustStdDevs,
217 std::map< InputParameters::TargetAreasClassIDT, std::vector< double > >&
218 classesGains,
219 std::map< InputParameters::TargetAreasClassIDT, std::vector< double > >&
220 classesOffsets );
221
222 // output = ( ( input - input_offset ) * gain ) + output_offset
223 bool copyRasterData( const te::rst::Raster& inRaster,
224 const std::vector< double >& gains,
225 const std::vector< double >& inputOffsets,
226 const std::vector< double >& outputOffsets,
227 te::rst::Raster& outRaster );
228
229 // means square root to find a and b ( y = a + b * x ).
230 // given a set off coods
231 // reference: https://pt.wikipedia.org/wiki/M%C3%A9todo_dos_m%C3%ADnimos_quadrados
232 bool linearRegression( std::vector< std::pair< double, double > >& coords,
233 double&a, double& b );
234 };
235
236 } // end namespace rp
237} // end namespace te
238
239#endif
240
A RAM cache adaptor to an external existent raster that must always be avaliable.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition Polygon.h:51
A RAM cache adaptor to an external existent raster that must always be avaliable.
Raster Processing algorithm input parameters base interface.
Raster Processing algorithm output parameters base interface.
A class to standardize algorithm parameters serialization.
AssistedHarmonization input parameters.
const InputParameters & operator=(const InputParameters &params)
te::rst::Raster const * m_refInputRasterPtr
Reference Input raster.
@ MeanStdHMethod
Mean and Standart deviation are used to perform equalization by gain and offset.
@ MSEHMethod
Mean square errors of classes means are used to calculate gain & offset".
TargetAreasContT m_referenceTargetAreas
Areas of interest over the reference image groupped by class ID.
std::map< TargetAreasClassIDT, TargetAreasGeomContT > TargetAreasContT
std::vector< unsigned int > m_adjInputRasterBands
Adjust input raster bands to process.
bool m_enableProgress
Enable/Disable the progress interface (default:false).
TargetAreasContT m_adjustTargetAreas
Areas of interest over the adjust image groupped by class ID.
te::rst::Raster const * m_adjInputRasterPtr
Adjust Input raster.
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state.
std::vector< unsigned int > m_refInputRasterBands
Referebce input raster bands to process.
std::vector< TargetAreasGeomT * > TargetAreasGeomContT
bool serialize(AlgorithmParametersSerializer &serializer) const
Returns a parameter serialization object.
AbstractParameters * clone() const
Create a clone copy of this instance.
void getMethodsInfo(std::map< HarmonizationMethod, std::pair< std::string, std::string > > &info) const
AssistedHarmonization output parameters.
const OutputParameters & operator=(const OutputParameters &params)
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state.
std::vector< double > m_outOffsets
The bands output offsets used to generate the output raster (output = ( ( input - input_offset ) * ga...
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
AbstractParameters * clone() const
Create a clone copy of this instance.
std::vector< double > m_gains
The bands gains used to generate the output raster (output = ( ( input - input_offset ) * gain ) + ou...
std::unique_ptr< te::rst::Raster > m_outputRasterPtr
The generated output registered raster.
std::map< std::string, std::string > m_rInfo
The necessary information to create the output rasters (as described in te::raster::RasterFactory).
std::vector< double > m_inOffsets
The bands input offsets used to generate the output raster (output = ( ( input - input_offset ) * gai...
AssistedHarmonization::InputParameters m_inputParameters
Input execution parameters.
void reset()
Clear all internal allocated objects and reset the algorithm to its initial state.
bool m_isInitialized
Tells if this instance is initialized.
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
void reprojectGeometries(const AssistedHarmonization::InputParameters::TargetAreasContT &inGeoms, AssistedHarmonization::InputParameters::TargetAreasContT &outGeoms, boost::ptr_vector< InputParameters::TargetAreasGeomT > &outGeomHandler, const int targetSRID)
bool calcClassGainsOffsets(const std::map< InputParameters::TargetAreasClassIDT, std::vector< double > > &referenceMeans, const std::map< InputParameters::TargetAreasClassIDT, std::vector< double > > &referenceStdDevs, const std::map< InputParameters::TargetAreasClassIDT, unsigned int > &referenceSamplesNumber, const std::map< InputParameters::TargetAreasClassIDT, std::vector< double > > &adjustMeans, const std::map< InputParameters::TargetAreasClassIDT, std::vector< double > > &adjustStdDevs, std::map< InputParameters::TargetAreasClassIDT, std::vector< double > > &classesGains, std::map< InputParameters::TargetAreasClassIDT, std::vector< double > > &classesOffsets)
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
bool copyRasterData(const te::rst::Raster &inRaster, const std::vector< double > &gains, const std::vector< double > &inputOffsets, const std::vector< double > &outputOffsets, te::rst::Raster &outRaster)
bool isInitialized() const
Returns true if the algorithm instance is initialized and ready for execution.
bool MSEHMethodImp(const te::mem::CachedRaster &refInputCRaster, const te::mem::CachedRaster &adjInputCRaster, const InputParameters::TargetAreasContT &referenceTargetAreasReproj, const InputParameters::TargetAreasContT &adjustTargetAreasReproj, AssistedHarmonization::OutputParameters *outParamsPtr)
bool MeanStdHMethodImp(const te::mem::CachedRaster &refInputCRaster, const te::mem::CachedRaster &adjInputCRaster, const InputParameters::TargetAreasContT &referenceTargetAreasReproj, const InputParameters::TargetAreasContT &adjustTargetAreasReproj, AssistedHarmonization::OutputParameters *outParamsPtr)
bool getRasterStatistics(const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBandsIndexes, const InputParameters::TargetAreasContT &targetAreas, std::map< InputParameters::TargetAreasClassIDT, unsigned int > &samplesNumber, std::map< unsigned int, std::vector< double > > &means, std::map< unsigned int, std::vector< double > > &stdDevs) const
bool CreateOutRaster(const te::mem::CachedRaster &adjInputCRaster, const std::vector< double > &gains, const std::vector< double > &inputOffsets, const std::vector< double > &outputOffsets, AssistedHarmonization::OutputParameters *outParamsPtr)
bool linearRegression(std::vector< std::pair< double, double > > &coords, double &a, double &b)
An abstract class for raster data strucutures.
Definition Raster.h:72
Namespace for Raster Processing module of TerraLib.
TerraLib.
An abstract class for raster data strucutures.
Raster Processing algorithm base interface class.
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition Config.h:139