Loading...
Searching...
No Matches
IHSFusion.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/IHSFusion.h
22 \brief Creation of skeleton imagems.
23 */
24
25#ifndef __TERRALIB_RP_INTERNAL_IHSFUSION_H
26#define __TERRALIB_RP_INTERNAL_IHSFUSION_H
27
28#include "Algorithm.h"
29#include "Matrix.h"
30#include "../raster/Raster.h"
31#include "../raster/Interpolator.h"
32#include "../raster/RasterSynchronizer.h"
33
34#include <vector>
35#include <string>
36#include <map>
37#include <limits>
38#include <memory>
39
40namespace te
41{
42 namespace rp
43 {
44 /*!
45 \class IHSFusion
46
47 \brief Fusion of a low-resolution multi-band image with a high resolution image using the IHS method.
48
49 \details The IHS is one of the widespread image fusion methods in the remote sensing community and has been employed as a standard procedure in many commercial packages; IHS is the intrinsic method when the intensity channel is replaced by the high-resolution Pan image.
50
51 \note This algorithm expects both images to be aligned over the same geographic region. No reprojection or crop operations are performed.
52
53 \note Reference: Te-Ming Tu, Shun-Chi Su, Hsuen-Chyun Shyu, Ping S. Huang, A new look at IHS-like image fusion methods, Information Fusion, Volume 2, Issue 3, September 2001, Pages 177-186, ISSN 1566-2535.
54
55 \note Reference: W.J. Carper, T.M. Lillesand, R.W. Kiefer, The use of intensity-hue-saturation transformations for merging SPOT panchromatic and multispectral image data Photogramm. Eng. Remote Sensing, 56 (1990), pp. 459–467.
56
57 \ingroup rp_fus
58 */
60 {
61 public:
62
63 /*!
64 \class InputParameters
65 \brief IHSFusion input parameters
66 */
68 {
69 public:
70
71 /*!
72 \enum HRHistoFitMethod High resolution image histogram fitting method.
73 */
75 {
76 NoHistoFitMethod = 0, //!< No fitting performed method.
77 MeanStdDevHistoFitMethod = 1, //!< Fitting by using mean and Standard deviation.
78 MinMaxHistoFitMethod = 2 //!< Fitting by using the mininum and maximum values.
79 };
80
81 te::rst::Raster const* m_lowResRasterPtr; //!< Input low-resolution multi-band raster.
82
83 unsigned int m_lowResRasterRedBandIndex; //!< The low-resolution raster red band index (default:0).
84
85 unsigned int m_lowResRasterGreenBandIndex; //!< The low-resolution raster green band index (default:1).
86
87 unsigned int m_lowResRasterBlueBandIndex; //!< The low-resolution raster blue band index (default:2).
88
89 te::rst::Raster const* m_highResRasterPtr; //!< Input high-resolution raster.
90
91 unsigned int m_highResRasterBand; //!< Band to process from the high-resolution raster.
92
93 bool m_enableProgress; //!< Enable/Disable the progress interface (default:false).
94
95 te::rst::Interpolator::Method m_interpMethod; //!< The raster interpolator method (default:NearestNeighbor).
96
97 double m_RGBMin; //!< The used RGB minimum value (default:0 - leave zero for automatic detection based on the input images).
98
99 double m_RGBMax; //!< The used RGB maximum value (default:0 - leave zero for automatic detection based on the input images).
100
101 bool m_enableThreadedProcessing; //!< If true, threaded processing will be performed (best with multi-core or multi-processor systems (default:true).
102
103 bool m_autoAlignRasters; //!< If true, the HR image will be clipped and reprojected to mach the LR image area.
104
105 bool m_enableRasterCache; //!< If true, raster cache will be used (default:true).
106
107 HRHistoFitMethod m_hrHistoFitMethod; //!< High resolution image histogram fitting method (default: MeanStdDevHistoFitMethod).
108
110
112
114
115 //overload
116 void reset() ;
117
118 //overload
120
121 //overload
122 AbstractParameters* clone() const;
123
124 //overload
125 bool serialize ( AlgorithmParametersSerializer& serializer ) const;
126 };
127
128 /*!
129 \class OutputParameters
130 \brief IHSFusion output parameters
131 */
133 {
134 public:
135
136 std::string m_rType; //!< Output raster data source type (as described in te::raster::RasterFactory ).
137
138 std::map< std::string, std::string > m_rInfo; //!< The necessary information to create the output rasters (as described in te::raster::RasterFactory).
139
140 std::unique_ptr< te::rst::Raster > m_outputRasterPtr; //!< The generated output fused raster.
141
143
145
147
148 //overload
149 void reset() ;
150
151 //overload
153
154 //overload
155 AbstractParameters* clone() const;
156 };
157
159
161
162 //overload
163 bool execute( AlgorithmOutputParameters& outputParams ) ;
164
165 //overload
166 void reset() ;
167
168 //overload
169 bool initialize( const AlgorithmInputParameters& inputParams ) ;
170
171 //overload
172 bool isInitialized() const;
173
174 protected:
175
177 {
180
181 // std::get< 0 > == processed = true / not processed = false
182 // std::get< 1 > == output block X
183 // std::get< 2 > == output block Y
184 std::vector< std::tuple< bool, unsigned int, unsigned int > >*
186
188 std::mutex* m_mutexPtr;
190 unsigned int m_interpWindowRadius;
194 double m_rgbMin;
195 double m_rgbMax;
196 };
197
199 {
204
205 // std::get< 0 > == processed = true / not processed = false
206 // std::get< 1 > == output block X
207 // std::get< 2 > == output block Y
208 std::vector< std::tuple< bool, unsigned int, unsigned int > >*
210
212 std::mutex* m_mutexPtr;
215 double m_gain;
216 };
217
219 {
222
223 // std::get< 0 > == processed = true / not processed = false
224 // std::get< 1 > == output block X
225 // std::get< 2 > == output block Y
226 std::vector< std::tuple< bool, unsigned int, unsigned int > >*
228
230 std::mutex* m_mutexPtr;
231 double m_rgbMin;
232 double m_rgbMax;
233 };
234
235 InputParameters m_inputParameters; //!< Input execution parameters.
236
237 bool m_isInitialized; //!< Tells if this instance is initialized.
238
239 /*!
240 \brief Get the minimum and maximum values from the RGB input image.
241 \param rgbMin RGB minimum value.
242 \param rgbMax RGB maximum value.
243 \return true if ok, false on errors.
244 */
245 bool getRGBRange( double& rgbMin, double& rgbMax ) const;
246
247 /*!
248 \brief Get statistics from the given raster band.
249 \param inputRaster Input raster.
250 \param inputRasterBand Input raster band index.
251 \param mean Mean value.
252 \param variance Variance value.
253 \param max Maximum value.
254 \param min Minimum value.
255 \return true if ok, false on errors.
256 */
257 bool getStatistics( const te::rst::Raster& inputRaster,
258 const unsigned int inputRasterBand, double& mean, double& stdDev,
259 double&min, double& max ) const;
260
261 /*!
262 \brief Swap the intensity data by the high resolution image data.
263 \param highResRaster High resolution raster.
264 \param highResRasterBand Hight resolution raster band.
265 \param ihsRaster IHS raster.
266 \return true if ok, false on errors.
267 */
268 bool swapIntensity( const te::rst::Raster& highResRaster,
269 const unsigned int highResRasterBand,
270 te::rst::Raster& ihsRaster );
271
273
274 /*!
275 \brief Save resampled IHS data as RGB data to the output image.
276 \param rgbMin RGB minimum value.
277 \param rgbMax RGB maximum value.
278 \param rType Output raster driver type.
279 \param rInfo Output raster info.
280 \param ihsRaster IHS raster.
281 \param outputRasterPtr Output raster pointer.
282 \return true if ok, false on errors.
283 */
285 const double& rgbMin, const double& rgbMax,
286 const std::string& rType, const std::map< std::string, std::string >& rInfo,
287 std::unique_ptr< te::rst::Raster >& outputRasterPtr,
288 const te::rst::Raster& ihsRaster );
289
291
292 /*!
293 \brief Load resampled IHS data from the lower resolution input image.
294 \param upsampledGrid Target upsampled grid.
295 \param rgbMin RGB minimum value.
296 \param rgbMax RGB maximum value.
297 \param ihsRasterPtr Output raster (3 bands - IHS).
298 \return true if ok, false on errors.
299 \note IHS data with the following channels ranges: I:[0,1] H:[0,2pi] (radians) S:[0,1].
300 */
302 const te::rst::Grid& upsampledGrid,
303 const double& rgbMin,
304 const double rgbMax,
305 std::unique_ptr< te::rst::Raster >& ihsRasterPtr ) const;
306
308 };
309
310 } // end namespace rp
311} // end namespace te
312
313#endif
314
Generic template matrix.
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
IHSFusion input parameters.
Definition: IHSFusion.h:68
double m_RGBMax
The used RGB maximum value (default:0 - leave zero for automatic detection based on the input images)...
Definition: IHSFusion.h:99
te::rst::Raster const * m_lowResRasterPtr
Input low-resolution multi-band raster.
Definition: IHSFusion.h:81
const InputParameters & operator=(const InputParameters &params)
bool serialize(AlgorithmParametersSerializer &serializer) const
Returns a parameter serialization object.
InputParameters(const InputParameters &)
unsigned int m_lowResRasterRedBandIndex
The low-resolution raster red band index (default:0).
Definition: IHSFusion.h:83
unsigned int m_lowResRasterBlueBandIndex
The low-resolution raster blue band index (default:2).
Definition: IHSFusion.h:87
double m_RGBMin
The used RGB minimum value (default:0 - leave zero for automatic detection based on the input images)...
Definition: IHSFusion.h:97
bool m_autoAlignRasters
If true, the HR image will be clipped and reprojected to mach the LR image area.
Definition: IHSFusion.h:103
bool m_enableThreadedProcessing
If true, threaded processing will be performed (best with multi-core or multi-processor systems (defa...
Definition: IHSFusion.h:101
unsigned int m_lowResRasterGreenBandIndex
The low-resolution raster green band index (default:1).
Definition: IHSFusion.h:85
bool m_enableProgress
Enable/Disable the progress interface (default:false).
Definition: IHSFusion.h:93
unsigned int m_highResRasterBand
Band to process from the high-resolution raster.
Definition: IHSFusion.h:91
AbstractParameters * clone() const
Create a clone copy of this instance.
te::rst::Raster const * m_highResRasterPtr
Input high-resolution raster.
Definition: IHSFusion.h:89
te::rst::Interpolator::Method m_interpMethod
The raster interpolator method (default:NearestNeighbor).
Definition: IHSFusion.h:95
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state.
bool m_enableRasterCache
If true, raster cache will be used (default:true).
Definition: IHSFusion.h:105
HRHistoFitMethod m_hrHistoFitMethod
High resolution image histogram fitting method (default: MeanStdDevHistoFitMethod).
Definition: IHSFusion.h:107
IHSFusion output parameters.
Definition: IHSFusion.h:133
const OutputParameters & operator=(const OutputParameters &params)
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state.
AbstractParameters * clone() const
Create a clone copy of this instance.
std::unique_ptr< te::rst::Raster > m_outputRasterPtr
The generated output fused raster.
Definition: IHSFusion.h:140
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition: IHSFusion.h:136
std::map< std::string, std::string > m_rInfo
The necessary information to create the output rasters (as described in te::raster::RasterFactory).
Definition: IHSFusion.h:138
OutputParameters(const OutputParameters &)
Fusion of a low-resolution multi-band image with a high resolution image using the IHS method.
Definition: IHSFusion.h:60
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
bool getStatistics(const te::rst::Raster &inputRaster, const unsigned int inputRasterBand, double &mean, double &stdDev, double &min, double &max) const
Get statistics from the given raster band.
bool loadUpsampledIHSData(const te::rst::Grid &upsampledGrid, const double &rgbMin, const double rgbMax, std::unique_ptr< te::rst::Raster > &ihsRasterPtr) const
Load resampled IHS data from the lower resolution input image.
bool saveRGBData(const double &rgbMin, const double &rgbMax, const std::string &rType, const std::map< std::string, std::string > &rInfo, std::unique_ptr< te::rst::Raster > &outputRasterPtr, const te::rst::Raster &ihsRaster)
Save resampled IHS data as RGB data to the output image.
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
static void swapIntensityThreadEntry(SwapIntensityThreadParameters *paramsPtr)
static void saveRGBDataThreadEntry(SaveRGBDataThreadParameters *paramsPtr)
bool getRGBRange(double &rgbMin, double &rgbMax) const
Get the minimum and maximum values from the RGB input image.
bool m_isInitialized
Tells if this instance is initialized.
Definition: IHSFusion.h:237
static void loadUpsampledIHSDataThreadEntry(LoadUpsampledIHSDataThreadParameters *paramsPtr)
InputParameters m_inputParameters
Input execution parameters.
Definition: IHSFusion.h:235
bool isInitialized() const
Returns true if the algorithm instance is initialized and ready for execution.
void reset()
Clear all internal allocated objects and reset the algorithm to its initial state.
bool swapIntensity(const te::rst::Raster &highResRaster, const unsigned int highResRasterBand, te::rst::Raster &ihsRaster)
Swap the intensity data by the high resolution image data.
A rectified grid is the spatial support for raster data.
Definition: Grid.h:69
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.
te::rst::RasterSynchronizer * m_inputRasterSyncPtr
Definition: IHSFusion.h:178
te::rst::RasterSynchronizer * m_outputRasterSyncPtr
Definition: IHSFusion.h:179
std::vector< std::tuple< bool, unsigned int, unsigned int > > * m_rasterBlocksStatusPtr
Definition: IHSFusion.h:185
te::rst::RasterSynchronizer * m_outputRasterSyncPtr
Definition: IHSFusion.h:221
te::rst::RasterSynchronizer * m_inputRasterSyncPtr
Definition: IHSFusion.h:220
std::vector< std::tuple< bool, unsigned int, unsigned int > > * m_rasterBlocksStatusPtr
Definition: IHSFusion.h:227
te::rst::RasterSynchronizer * m_outputRasterSyncPtr
Definition: IHSFusion.h:201
te::rst::RasterSynchronizer * m_inputRasterSyncPtr
Definition: IHSFusion.h:200
std::vector< std::tuple< bool, unsigned int, unsigned int > > * m_rasterBlocksStatusPtr
Definition: IHSFusion.h:209
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:139
Abstract algorithm.