PCAFusion.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 /*!
21  \file terralib/rp/PCAFusion.h
22  \brief Creation of skeleton imagems.
23  */
24 
25 #ifndef __TERRALIB_RP_INTERNAL_PCAFUSION_H
26 #define __TERRALIB_RP_INTERNAL_PCAFUSION_H
27 
28 #include "Algorithm.h"
29 #include "../raster/Raster.h"
30 #include "../raster/Band.h"
31 #include "../raster/Interpolator.h"
32 #include "../raster/RasterSynchronizer.h"
33 
34 #include <vector>
35 #include <string>
36 #include <map>
37 #include <memory>
38 
39 namespace te
40 {
41  namespace rp
42  {
43  /*!
44  \class PCAFusion
45  \brief Fusion of a low-resolution multi-band image with a high resolution image using the PCA (Principal components analysis) method.
46  \details The PCA performs image fusion where the first principal component of the multi-spectral image is replaced by the histogram matched panchromatic imagery.
47  \note Reference: Tania Stathaki, "Image Fusion: Algorithms and Applications", Elsevier, First edition 2008.
48  \note This algorithm expects both images to be aligned over the same geographic region. No reprojection or crop operations are performed.
49  \ingroup rp_fus
50  */
52  {
53  public:
54 
55  /*!
56  \class InputParameters
57  \brief PCAFusion input parameters
58  */
60  {
61  public:
62 
63  /*!
64  \enum HRHistoFitMethod High resolution image histogram fitting method.
65  */
67  {
68  NoHistoFitMethod = 0, //!< No fitting performed method.
69  MeanStdDevHistoFitMethod = 1, //!< Fitting by using mean and Standard deviation.
70  MinMaxHistoFitMethod = 2 //!< Fitting by using the mininum and maximum values.
71  };
72 
73  te::rst::Raster const* m_lowResRasterPtr; //!< Input low-resolution multi-band raster.
74 
75  std::vector< unsigned int > m_lowResRasterBands; //!< The low-resolution raster band indexes.
76 
77  te::rst::Raster const* m_highResRasterPtr; //!< Input high-resolution raster.
78 
79  unsigned int m_highResRasterBand; //!< Band to process from the high-resolution raster.
80 
81  bool m_enableProgress; //!< Enable/Disable the progress interface (default:false).
82 
83  bool m_enableThreadedProcessing; //!< If true, threaded processing will be performed (best with multi-core or multi-processor systems (default:true).
84 
85  te::rst::Interpolator::Method m_interpMethod; //!< The raster interpolator method (default:NearestNeighbor).
86 
87  bool m_autoAlignRasters; //!< If true, the HR image will be clipped and reprojected to mach the LR image area.
88 
89  HRHistoFitMethod m_hrHistoFitMethod; //!< High resolution image histogram fitting method (default: MeanStdDevHistoFitMethod).
90 
92 
94 
96 
97  //overload
98  void reset() ;
99 
100  //overload
101  const InputParameters& operator=( const InputParameters& params );
102 
103  //overload
104  AbstractParameters* clone() const;
105 
106  //overload
107  bool serialize ( AlgorithmParametersSerializer& serializer ) const;
108  };
109 
110  /*!
111  \class OutputParameters
112  \brief PCAFusion output parameters
113  */
115  {
116  public:
117 
118  std::string m_rType; //!< Output raster data source type (as described in te::raster::RasterFactory ).
119 
120  std::map< std::string, std::string > m_rInfo; //!< The necessary information to create the output rasters (as described in te::raster::RasterFactory).
121 
122  std::unique_ptr< te::rst::Raster > m_outputRasterPtr; //!< The generated output fused raster.
123 
125 
127 
129 
130  //overload
131  void reset() ;
132 
133  //overload
134  const OutputParameters& operator=( const OutputParameters& params );
135 
136  //overload
137  AbstractParameters* clone() const;
138  };
139 
141 
143 
144  //overload
145  bool execute( AlgorithmOutputParameters& outputParams ) ;
146 
147  //overload
148  void reset() ;
149 
150  //overload
151  bool initialize( const AlgorithmInputParameters& inputParams ) ;
152 
153  //overload
154  bool isInitialized() const;
155 
156  protected:
157 
159  {
162  unsigned int m_inputRasterBandIdx;
163  unsigned int m_outputRasterBandIdx;
164 
165  // std::get< 0 > == processed = true / not processed = false
166  // std::get< 1 > == output block X
167  // std::get< 2 > == output block Y
168  std::vector< std::tuple< bool, unsigned int, unsigned int > >*
170 
172  std::mutex* m_mutexPtr;
173  double m_inOffset;
174  double m_outOffset;
175  double m_gain;
176  };
177 
178  InputParameters m_inputParameters; //!< Input execution parameters.
179 
180  bool m_isInitialized; //!< Tells if this instance is initialized.
181 
182  /*!
183  \brief Swap the band values by the normalized high resolution raster data.
184  \param highResRaster High resolution raster.
185  \param highResRaster High resolution raster.
186  \param pcaRaster The PCA raster.
187  \param pcaRasterBandIdx The band index where the values will be swapped.
188  \return true if ok, false on errors.
189  */
190  bool swapBandByHighResRaster( const te::rst::Raster& highResRaster,
191  const unsigned int highResRasterBand,
192  te::rst::Raster& pcaRaster, const unsigned int pcaRasterBandIdx );
193 
195 
196  };
197 
198  } // end namespace rp
199 } // end namespace te
200 
201 #endif
202 
Raster Processing algorithm input parameters base interface.
Raster Processing algorithm output parameters base interface.
A class to standardize algorithm parameters serialization.
Raster Processing algorithm base interface.
Definition: Algorithm.h:42
PCAFusion input parameters.
Definition: PCAFusion.h:60
bool m_enableThreadedProcessing
If true, threaded processing will be performed (best with multi-core or multi-processor systems (defa...
Definition: PCAFusion.h:83
bool m_autoAlignRasters
If true, the HR image will be clipped and reprojected to mach the LR image area.
Definition: PCAFusion.h:87
const InputParameters & operator=(const InputParameters &params)
unsigned int m_highResRasterBand
Band to process from the high-resolution raster.
Definition: PCAFusion.h:79
std::vector< unsigned int > m_lowResRasterBands
The low-resolution raster band indexes.
Definition: PCAFusion.h:75
InputParameters(const InputParameters &)
bool serialize(AlgorithmParametersSerializer &serializer) const
Returns a parameter serialization object.
bool m_enableProgress
Enable/Disable the progress interface (default:false).
Definition: PCAFusion.h:81
HRHistoFitMethod m_hrHistoFitMethod
High resolution image histogram fitting method (default: MeanStdDevHistoFitMethod).
Definition: PCAFusion.h:89
te::rst::Interpolator::Method m_interpMethod
The raster interpolator method (default:NearestNeighbor).
Definition: PCAFusion.h:85
te::rst::Raster const * m_lowResRasterPtr
Input low-resolution multi-band raster.
Definition: PCAFusion.h:73
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state.
te::rst::Raster const * m_highResRasterPtr
Input high-resolution raster.
Definition: PCAFusion.h:77
AbstractParameters * clone() const
Create a clone copy of this instance.
PCAFusion output parameters.
Definition: PCAFusion.h:115
const OutputParameters & operator=(const OutputParameters &params)
OutputParameters(const OutputParameters &)
AbstractParameters * clone() const
Create a clone copy of this instance.
std::map< std::string, std::string > m_rInfo
The necessary information to create the output rasters (as described in te::raster::RasterFactory).
Definition: PCAFusion.h:120
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state.
std::unique_ptr< te::rst::Raster > m_outputRasterPtr
The generated output fused raster.
Definition: PCAFusion.h:122
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition: PCAFusion.h:118
Fusion of a low-resolution multi-band image with a high resolution image using the PCA (Principal com...
Definition: PCAFusion.h:52
void reset()
Clear all internal allocated objects and reset the algorithm to its initial state.
bool m_isInitialized
Tells if this instance is initialized.
Definition: PCAFusion.h:180
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
static void swapBandByHighResRasterThreadEntry(SwapBandByHighResRasterThreadParameters *paramsPtr)
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
bool swapBandByHighResRaster(const te::rst::Raster &highResRaster, const unsigned int highResRasterBand, te::rst::Raster &pcaRaster, const unsigned int pcaRasterBandIdx)
Swap the band values by the normalized high resolution raster data.
InputParameters m_inputParameters
Input execution parameters.
Definition: PCAFusion.h:178
bool isInitialized() const
Returns true if the algorithm instance is initialized and ready for execution.
An access synchronizer to be used in SynchronizedRaster raster instances.
An abstract class for raster data strucutures.
Definition: Raster.h:72
InterpolationMethod
Allowed interpolation methods.
Definition: Enums.h:93
TerraLib.
std::vector< std::tuple< bool, unsigned int, unsigned int > > * m_rasterBlocksStatusPtr
Definition: PCAFusion.h:169
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:139
Abstract algorithm.