Loading...
Searching...
No Matches
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"
33
34#include <boost/numeric/ublas/matrix.hpp>
35
36#include <vector>
37#include <string>
38#include <map>
39#include <memory>
40
41namespace 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 MeanStdDevHistoFitAndClipMethod = 3, //!< Fitting by using mean and Standard deviation and clipping to minimum and maximum values.
74 };
75
76 te::rst::Raster const* m_lowResRasterPtr; //!< Input low-resolution multi-band raster.
77
78 std::vector< unsigned int > m_lowResRasterBands; //!< The low-resolution raster band indexes.
79
80 te::rst::Raster const* m_highResRasterPtr; //!< Input high-resolution raster.
81
82 unsigned int m_highResRasterBand; //!< Band to process from the high-resolution raster.
83
84 bool m_enableProgress; //!< Enable/Disable the progress interface (default:false).
85
86 bool m_enableThreadedProcessing; //!< If true, threaded processing will be performed (best with multi-core or multi-processor systems (default:true).
87
88 te::rst::Interpolator::Method m_interpMethod; //!< The raster interpolator method (default:NearestNeighbor).
89
90 bool m_autoAlignRasters; //!< If true, the HR image will be clipped and reprojected to mach the LR image area.
91
92 HRHistoFitMethod m_hrHistoFitMethod; //!< High resolution image histogram fitting method (default: MeanStdDevHistoFitMethod).
93
94 boost::numeric::ublas::matrix< double > m_directPCAMatrix; //!< A valid direct transformation PCA matrix or an empty matrix (will be automcaticall calculated).
95
96 std::vector< double > m_outputNoDataValues; //!< A vector of output raster band no-data values or an empty vector to use low-resolution raster no-data values.
97
98 std::vector< double > m_lowResRastersStdDevGains; //!< A vector of positive gains to be applied when normalizing the low resolution raster bands standard deviation. To automatically apply gains a vector of size 1 can be supplied. An empty vector means no gain will be applied.
99
101
103
105
106 //overload
107 void reset() ;
108
109 //overload
111
112 //overload
114
115 //overload
116 bool serialize ( AlgorithmParametersSerializer& serializer ) const;
117 };
118
119 /*!
120 \class OutputParameters
121 \brief PCAFusion output parameters
122 */
124 {
125 public:
126
127 std::string m_rType; //!< Output raster data source type (as described in te::raster::RasterFactory ).
128
129 std::map< std::string, std::string > m_rInfo; //!< The necessary information to create the output rasters (as described in te::raster::RasterFactory).
130
131 std::unique_ptr< te::rst::Raster > m_outputRasterPtr; //!< The generated output fused raster.
132
133 boost::numeric::ublas::matrix< double > m_directPCAMatrix; //!< The calculated direct PCA transformation matrix.
134
136
138
140
141 //overload
142 void reset() ;
143
144 //overload
146
147 //overload
149 };
150
152
154
155 //overload
156 bool execute( AlgorithmOutputParameters& outputParams ) ;
157
158 //overload
159 void reset() ;
160
161 //overload
162 bool initialize( const AlgorithmInputParameters& inputParams ) ;
163
164 //overload
165 bool isInitialized() const;
166
167 protected:
168
170 {
175
176 // std::get< 0 > == processed = true / not processed = false
177 // std::get< 1 > == output block X
178 // std::get< 2 > == output block Y
179 std::vector< std::tuple< bool, unsigned int, unsigned int > >*
181
183 std::mutex* m_mutexPtr;
186 double m_gain;
189 };
190
191 InputParameters m_inputParameters; //!< Input execution parameters.
192
193 bool m_isInitialized; //!< Tells if this instance is initialized.
194
195 /*!
196 \brief Swap the band values by the normalized high resolution raster data.
197 \param highResRaster High resolution raster.
198 \param highResRaster High resolution raster.
199 \param pcaRaster The PCA raster.
200 \param pcaRasterBandIdx The band index where the values will be swapped.
201 \return true if ok, false on errors.
202 */
203 bool swapBandByHighResRaster( const te::rst::Raster& highResRaster,
204 const unsigned int highResRasterBand,
205 te::rst::Raster& pcaRaster, const unsigned int pcaRasterBandIdx );
206
208
209 /*!
210 \brief Apply a gain to each band values.
211 \param raster Input raster.
212 \param gains Gains for each raster band.
213 \return true if ok, false on errors.
214 \note outValue = ( ( inValue - off ) * gain ] + off
215 */
217 std::vector< double >& gains, std::vector< double >& offsets );
218 };
219
220 } // end namespace rp
221} // end namespace te
222
223#endif
224
It interpolates one pixel based on a selected algorithm.
An access synchronizer to be used in SynchronizedRaster raster instances.
Raster Processing algorithm input parameters base interface.
Raster Processing algorithm output parameters base interface.
A class to standardize algorithm parameters serialization.
PCAFusion input parameters.
Definition PCAFusion.h:62
AbstractParameters * clone() const
Create a clone copy of this instance.
bool m_enableThreadedProcessing
If true, threaded processing will be performed (best with multi-core or multi-processor systems (defa...
Definition PCAFusion.h:86
bool m_autoAlignRasters
If true, the HR image will be clipped and reprojected to mach the LR image area.
Definition PCAFusion.h:90
std::vector< double > m_outputNoDataValues
A vector of output raster band no-data values or an empty vector to use low-resolution raster no-data...
Definition PCAFusion.h:96
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:94
unsigned int m_highResRasterBand
Band to process from the high-resolution raster.
Definition PCAFusion.h:82
@ MinMaxHistoFitMethod
Fitting by using the mininum and maximum values.
Definition PCAFusion.h:72
@ NoHistoFitMethod
No fitting performed method.
Definition PCAFusion.h:70
@ MeanStdDevHistoFitMethod
Fitting by using mean and Standard deviation.
Definition PCAFusion.h:71
@ MeanStdDevHistoFitAndClipMethod
Fitting by using mean and Standard deviation and clipping to minimum and maximum values.
Definition PCAFusion.h:73
std::vector< unsigned int > m_lowResRasterBands
The low-resolution raster band indexes.
Definition PCAFusion.h:78
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:84
HRHistoFitMethod m_hrHistoFitMethod
High resolution image histogram fitting method (default: MeanStdDevHistoFitMethod).
Definition PCAFusion.h:92
te::rst::Interpolator::Method m_interpMethod
The raster interpolator method (default:NearestNeighbor).
Definition PCAFusion.h:88
std::vector< double > m_lowResRastersStdDevGains
A vector of positive gains to be applied when normalizing the low resolution raster bands standard de...
Definition PCAFusion.h:98
te::rst::Raster const * m_lowResRasterPtr
Input low-resolution multi-band raster.
Definition PCAFusion.h:76
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:80
OutputParameters(const OutputParameters &)
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:129
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:131
const OutputParameters & operator=(const OutputParameters &params)
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition PCAFusion.h:127
AbstractParameters * clone() const
Create a clone copy of this instance.
boost::numeric::ublas::matrix< double > m_directPCAMatrix
The calculated direct PCA transformation matrix.
Definition PCAFusion.h:133
bool applyGainsAndOffsets(te::rst::Raster &raster, std::vector< double > &gains, std::vector< double > &offsets)
Apply a gain to each band values.
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:193
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:191
bool isInitialized() const
Returns true if the algorithm instance is initialized and ready for execution.
InterpolationMethod Method
Allowed interpolation methods.
An access synchronizer to be used in SynchronizedRaster raster instances.
An abstract class for raster data strucutures.
Definition Raster.h:72
Namespace for Raster Processing module of TerraLib.
TerraLib.
It gives access to values in one band (dimension) of a raster.
An abstract class for raster data strucutures.
Raster Processing algorithm base interface class.
std::vector< std::tuple< bool, unsigned int, unsigned int > > * m_rasterBlocksStatusPtr
Definition PCAFusion.h:180
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition Config.h:139