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 <boost/numeric/ublas/matrix.hpp>
35 
36 #include <vector>
37 #include <string>
38 #include <map>
39 #include <memory>
40 
41 namespace te
42 {
43  namespace rp
44  {
45  /*!
46  \class PCAFusion
47  \brief Fusion of a low-resolution multi-band image with a high resolution image using the PCA (Principal components analysis) method.
48  \details The PCA performs image fusion where the first principal component of the multi-spectral image is replaced by the histogram matched panchromatic imagery.
49  \note Reference: Tania Stathaki, "Image Fusion: Algorithms and Applications", Elsevier, First edition 2008.
50  \note This algorithm expects both images to be aligned over the same geographic region. No reprojection or crop operations are performed.
51  \ingroup rp_fus
52  */
54  {
55  public:
56 
57  /*!
58  \class InputParameters
59  \brief PCAFusion input parameters
60  */
62  {
63  public:
64 
65  /*!
66  \enum HRHistoFitMethod High resolution image histogram fitting method.
67  */
69  {
70  NoHistoFitMethod = 0, //!< No fitting performed method.
71  MeanStdDevHistoFitMethod = 1, //!< Fitting by using mean and Standard deviation.
72  MinMaxHistoFitMethod = 2 //!< Fitting by using the mininum and maximum values.
73  };
74 
75  te::rst::Raster const* m_lowResRasterPtr; //!< Input low-resolution multi-band raster.
76 
77  std::vector< unsigned int > m_lowResRasterBands; //!< The low-resolution raster band indexes.
78 
79  te::rst::Raster const* m_highResRasterPtr; //!< Input high-resolution raster.
80 
81  unsigned int m_highResRasterBand; //!< Band to process from the high-resolution raster.
82 
83  bool m_enableProgress; //!< Enable/Disable the progress interface (default:false).
84 
85  bool m_enableThreadedProcessing; //!< If true, threaded processing will be performed (best with multi-core or multi-processor systems (default:true).
86 
87  te::rst::Interpolator::Method m_interpMethod; //!< The raster interpolator method (default:NearestNeighbor).
88 
89  bool m_autoAlignRasters; //!< If true, the HR image will be clipped and reprojected to mach the LR image area.
90 
91  HRHistoFitMethod m_hrHistoFitMethod; //!< High resolution image histogram fitting method (default: MeanStdDevHistoFitMethod).
92 
93  boost::numeric::ublas::matrix< double > m_directPCAMatrix; //!< A valid direct transformation PCA matrix or an empty matrix (will be automcaticall calculated).
94 
96 
98 
100 
101  //overload
102  void reset() ;
103 
104  //overload
105  const InputParameters& operator=( const InputParameters& params );
106 
107  //overload
108  AbstractParameters* clone() const;
109 
110  //overload
111  bool serialize ( AlgorithmParametersSerializer& serializer ) const;
112  };
113 
114  /*!
115  \class OutputParameters
116  \brief PCAFusion output parameters
117  */
119  {
120  public:
121 
122  std::string m_rType; //!< Output raster data source type (as described in te::raster::RasterFactory ).
123 
124  std::map< std::string, std::string > m_rInfo; //!< The necessary information to create the output rasters (as described in te::raster::RasterFactory).
125 
126  std::unique_ptr< te::rst::Raster > m_outputRasterPtr; //!< The generated output fused raster.
127 
128  boost::numeric::ublas::matrix< double > m_directPCAMatrix; //!< The calculated direct PCA transformation matrix.
129 
131 
133 
135 
136  //overload
137  void reset() ;
138 
139  //overload
140  const OutputParameters& operator=( const OutputParameters& params );
141 
142  //overload
143  AbstractParameters* clone() const;
144  };
145 
147 
149 
150  //overload
151  bool execute( AlgorithmOutputParameters& outputParams ) ;
152 
153  //overload
154  void reset() ;
155 
156  //overload
157  bool initialize( const AlgorithmInputParameters& inputParams ) ;
158 
159  //overload
160  bool isInitialized() const;
161 
162  protected:
163 
165  {
168  unsigned int m_inputRasterBandIdx;
169  unsigned int m_outputRasterBandIdx;
170 
171  // std::get< 0 > == processed = true / not processed = false
172  // std::get< 1 > == output block X
173  // std::get< 2 > == output block Y
174  std::vector< std::tuple< bool, unsigned int, unsigned int > >*
176 
178  std::mutex* m_mutexPtr;
179  double m_inOffset;
180  double m_outOffset;
181  double m_gain;
182  };
183 
184  InputParameters m_inputParameters; //!< Input execution parameters.
185 
186  bool m_isInitialized; //!< Tells if this instance is initialized.
187 
188  /*!
189  \brief Swap the band values by the normalized high resolution raster data.
190  \param highResRaster High resolution raster.
191  \param highResRaster High resolution raster.
192  \param pcaRaster The PCA raster.
193  \param pcaRasterBandIdx The band index where the values will be swapped.
194  \return true if ok, false on errors.
195  */
196  bool swapBandByHighResRaster( const te::rst::Raster& highResRaster,
197  const unsigned int highResRasterBand,
198  te::rst::Raster& pcaRaster, const unsigned int pcaRasterBandIdx );
199 
201 
202  };
203 
204  } // end namespace rp
205 } // end namespace te
206 
207 #endif
208 
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:62
bool m_enableThreadedProcessing
If true, threaded processing will be performed (best with multi-core or multi-processor systems (defa...
Definition: PCAFusion.h:85
bool m_autoAlignRasters
If true, the HR image will be clipped and reprojected to mach the LR image area.
Definition: PCAFusion.h:89
const InputParameters & operator=(const InputParameters &params)
boost::numeric::ublas::matrix< double > m_directPCAMatrix
A valid direct transformation PCA matrix or an empty matrix (will be automcaticall calculated).
Definition: PCAFusion.h:93
unsigned int m_highResRasterBand
Band to process from the high-resolution raster.
Definition: PCAFusion.h:81
std::vector< unsigned int > m_lowResRasterBands
The low-resolution raster band indexes.
Definition: PCAFusion.h:77
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:83
HRHistoFitMethod m_hrHistoFitMethod
High resolution image histogram fitting method (default: MeanStdDevHistoFitMethod).
Definition: PCAFusion.h:91
te::rst::Interpolator::Method m_interpMethod
The raster interpolator method (default:NearestNeighbor).
Definition: PCAFusion.h:87
te::rst::Raster const * m_lowResRasterPtr
Input low-resolution multi-band raster.
Definition: PCAFusion.h:75
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:79
AbstractParameters * clone() const
Create a clone copy of this instance.
PCAFusion output parameters.
Definition: PCAFusion.h:119
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:124
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:126
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition: PCAFusion.h:122
boost::numeric::ublas::matrix< double > m_directPCAMatrix
The calculated direct PCA transformation matrix.
Definition: PCAFusion.h:128
Fusion of a low-resolution multi-band image with a high resolution image using the PCA (Principal com...
Definition: PCAFusion.h:54
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:186
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:184
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:175
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:139
Abstract algorithm.