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
109 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.
110
112
114
116
117 //overload
118 void reset() ;
119
120 //overload
122
123 //overload
124 AbstractParameters* clone() const;
125
126 //overload
127 bool serialize ( AlgorithmParametersSerializer& serializer ) const;
128 };
129
130 /*!
131 \class OutputParameters
132 \brief IHSFusion output parameters
133 */
135 {
136 public:
137
138 std::string m_rType; //!< Output raster data source type (as described in te::raster::RasterFactory ).
139
140 std::map< std::string, std::string > m_rInfo; //!< The necessary information to create the output rasters (as described in te::raster::RasterFactory).
141
142 std::unique_ptr< te::rst::Raster > m_outputRasterPtr; //!< The generated output fused raster.
143
145
147
149
150 //overload
151 void reset() ;
152
153 //overload
155
156 //overload
157 AbstractParameters* clone() const;
158 };
159
161
163
164 //overload
165 bool execute( AlgorithmOutputParameters& outputParams ) ;
166
167 //overload
168 void reset() ;
169
170 //overload
171 bool initialize( const AlgorithmInputParameters& inputParams ) ;
172
173 //overload
174 bool isInitialized() const;
175
176 protected:
177
179 {
182
183 // std::get< 0 > == processed = true / not processed = false
184 // std::get< 1 > == output block X
185 // std::get< 2 > == output block Y
186 std::vector< std::tuple< bool, unsigned int, unsigned int > >*
188
190 std::mutex* m_mutexPtr;
192 unsigned int m_interpWindowRadius;
196 double m_rgbMin;
197 double m_rgbMax;
198 };
199
201 {
206
207 // std::get< 0 > == processed = true / not processed = false
208 // std::get< 1 > == output block X
209 // std::get< 2 > == output block Y
210 std::vector< std::tuple< bool, unsigned int, unsigned int > >*
212
214 std::mutex* m_mutexPtr;
217 double m_gain;
218 };
219
221 {
224
225 // std::get< 0 > == processed = true / not processed = false
226 // std::get< 1 > == output block X
227 // std::get< 2 > == output block Y
228 std::vector< std::tuple< bool, unsigned int, unsigned int > >*
230
232 std::mutex* m_mutexPtr;
233 double m_rgbMin;
234 double m_rgbMax;
235 };
236
237 InputParameters m_inputParameters; //!< Input execution parameters.
238
239 bool m_isInitialized; //!< Tells if this instance is initialized.
240
241 /*!
242 \brief Get the minimum and maximum values from the RGB input image.
243 \param rgbMin RGB minimum value.
244 \param rgbMax RGB maximum value.
245 \return true if ok, false on errors.
246 */
247 bool getRGBRange( double& rgbMin, double& rgbMax ) const;
248
249 /*!
250 \brief Get statistics from the given raster band.
251 \param inputRaster Input raster.
252 \param inputRasterBand Input raster band index.
253 \param mean Mean value.
254 \param variance Variance value.
255 \param max Maximum value.
256 \param min Minimum value.
257 \return true if ok, false on errors.
258 */
259 bool getStatistics( const te::rst::Raster& inputRaster,
260 const unsigned int inputRasterBand, double& mean, double& stdDev,
261 double&min, double& max ) const;
262
263 /*!
264 \brief Swap the intensity data by the high resolution image data.
265 \param highResRaster High resolution raster.
266 \param highResRasterBand Hight resolution raster band.
267 \param ihsRaster IHS raster.
268 \return true if ok, false on errors.
269 */
270 bool swapIntensity( const te::rst::Raster& highResRaster,
271 const unsigned int highResRasterBand,
272 te::rst::Raster& ihsRaster );
273
275
276 /*!
277 \brief Save resampled IHS data as RGB data to the output image.
278 \param rgbMin RGB minimum value.
279 \param rgbMax RGB maximum value.
280 \param rType Output raster driver type.
281 \param rInfo Output raster info.
282 \param ihsRaster IHS raster.
283 \param outputRasterPtr Output raster pointer.
284 \return true if ok, false on errors.
285 */
287 const double& rgbMin, const double& rgbMax,
288 const std::string& rType, const std::map< std::string, std::string >& rInfo,
289 std::unique_ptr< te::rst::Raster >& outputRasterPtr,
290 const te::rst::Raster& ihsRaster );
291
293
294 /*!
295 \brief Load resampled IHS data from the lower resolution input image.
296 \param upsampledGrid Target upsampled grid.
297 \param rgbMin RGB minimum value.
298 \param rgbMax RGB maximum value.
299 \param ihsRasterPtr Output raster (3 bands - IHS).
300 \return true if ok, false on errors.
301 \note IHS data with the following channels ranges: I:[0,1] H:[0,2pi] (radians) S:[0,1].
302 */
304 const te::rst::Grid& upsampledGrid,
305 const double& rgbMin,
306 const double rgbMax,
307 std::unique_ptr< te::rst::Raster >& ihsRasterPtr ) const;
308
310 };
311
312 } // end namespace rp
313} // end namespace te
314
315#endif
316
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)
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 IHSFusion.h:109
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:135
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:142
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition IHSFusion.h:138
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:140
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:239
static void loadUpsampledIHSDataThreadEntry(LoadUpsampledIHSDataThreadParameters *paramsPtr)
InputParameters m_inputParameters
Input execution parameters.
Definition IHSFusion.h:237
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_outputRasterSyncPtr
Definition IHSFusion.h:181
std::vector< std::tuple< bool, unsigned int, unsigned int > > * m_rasterBlocksStatusPtr
Definition IHSFusion.h:187
te::rst::RasterSynchronizer * m_outputRasterSyncPtr
Definition IHSFusion.h:223
te::rst::RasterSynchronizer * m_inputRasterSyncPtr
Definition IHSFusion.h:222
std::vector< std::tuple< bool, unsigned int, unsigned int > > * m_rasterBlocksStatusPtr
Definition IHSFusion.h:229
te::rst::RasterSynchronizer * m_outputRasterSyncPtr
Definition IHSFusion.h:203
te::rst::RasterSynchronizer * m_inputRasterSyncPtr
Definition IHSFusion.h:202
std::vector< std::tuple< bool, unsigned int, unsigned int > > * m_rasterBlocksStatusPtr
Definition IHSFusion.h:211
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition Config.h:139
Abstract algorithm.