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 
33 #include <vector>
34 #include <string>
35 #include <map>
36 #include <limits>
37 
38 namespace te
39 {
40  namespace rp
41  {
42  /*!
43  \class IHSFusion
44 
45  \brief Fusion of a low-resolution multi-band image with a high resolution image using the IHS method.
46 
47  \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.
48 
49  \note This algorithm expects both images to be aligned over the same geographic region. No reprojection or crop operations are performed.
50 
51  \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.
52 
53  \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.
54 
55  \ingroup rp_fus
56  */
58  {
59  public:
60 
61  /*!
62  \class InputParameters
63  \brief IHSFusion input parameters
64  */
66  {
67  public:
68 
69  te::rst::Raster const* m_lowResRasterPtr; //!< Input low-resolution multi-band raster.
70 
71  unsigned int m_lowResRasterRedBandIndex; //!< The low-resolution raster red band index (default:0).
72 
73  unsigned int m_lowResRasterGreenBandIndex; //!< The low-resolution raster green band index (default:1).
74 
75  unsigned int m_lowResRasterBlueBandIndex; //!< The low-resolution raster blue band index (default:2).
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  te::rst::Interpolator::Method m_interpMethod; //!< The raster interpolator method (default:NearestNeighbor).
84 
85  double m_RGBMin; //!< The used RGB minimum value (default:0 - leave zero for automatic detection based on the input images).
86 
87  double m_RGBMax; //!< The used RGB maximum value (default:0 - leave zero for automatic detection based on the input images).
88 
89  bool m_enableThreadedProcessing; //!< If true, threaded processing will be performed (best with multi-core or multi-processor systems (default:true).
90 
91  bool m_autoAlignRasters; //!< If true, the HR image will be clipped and reprojected to mach the LR image area.
92 
94 
96 
98 
99  //overload
100  void reset() throw( te::rp::Exception );
101 
102  //overload
103  const InputParameters& operator=( const InputParameters& params );
104 
105  //overload
106  AbstractParameters* clone() const;
107  };
108 
109  /*!
110  \class OutputParameters
111  \brief IHSFusion output parameters
112  */
114  {
115  public:
116 
117  std::string m_rType; //!< Output raster data source type (as described in te::raster::RasterFactory ).
118 
119  std::map< std::string, std::string > m_rInfo; //!< The necessary information to create the output rasters (as described in te::raster::RasterFactory).
120 
121  std::unique_ptr< te::rst::Raster > m_outputRasterPtr; //!< The generated output fused raster.
122 
124 
126 
128 
129  //overload
130  void reset() throw( te::rp::Exception );
131 
132  //overload
133  const OutputParameters& operator=( const OutputParameters& params );
134 
135  //overload
136  AbstractParameters* clone() const;
137  };
138 
140 
142 
143  //overload
144  bool execute( AlgorithmOutputParameters& outputParams ) throw( te::rp::Exception );
145 
146  //overload
147  void reset() throw( te::rp::Exception );
148 
149  //overload
150  bool initialize( const AlgorithmInputParameters& inputParams ) throw( te::rp::Exception );
151 
152  //overload
153  bool isInitialized() const;
154 
155  protected:
156 
157  InputParameters m_inputParameters; //!< Input execution parameters.
158 
159  bool m_isInitialized; //!< Tells if this instance is initialized.
160 
161  /*!
162  \brief Get the minimum and maximum values from the RGB input image.
163  \param rgbMin RGB minimum value.
164  \param rgbMax RGB maximum value.
165  \return true if ok, false on errors.
166  */
167  bool getRGBRange( double& rgbMin, double& rgbMax ) const;
168 
169  /*!
170  \brief Get statistics from the given matrix.
171  \param matrix Input matrix.
172  \param mean Mean value.
173  \param variance Variance value.
174  \return true if ok, false on errors.
175  */
176  template< typename DataTypeT >
177  bool getStatistics( const te::rp::Matrix< DataTypeT >& matrix,
178  DataTypeT& mean, DataTypeT& variance,
179  DataTypeT& minimum, DataTypeT& maximum ) const
180  {
181  const unsigned int nRows = matrix.getLinesNumber();
182  const unsigned int nCols = matrix.getColumnsNumber();
183 
184  if( ( nRows == 0 ) || ( nCols == 0 ) ) return false;
185 
186  unsigned int col = 0;
187  unsigned int row = 0;
188  DataTypeT const * rowPtr = nullptr;
189 
190  minimum = std::numeric_limits< DataTypeT >::max();
191  maximum = ((DataTypeT)-1) * std::numeric_limits< DataTypeT >::max();
192  mean = 0.0;
193 
194  for( row = 0 ; row < nRows ; ++row )
195  {
196  rowPtr = matrix[ row ];
197 
198  for( col = 0 ; col < nCols ; ++col )
199  {
200  mean += rowPtr[ col ];
201  minimum = std::min( minimum, rowPtr[ col ] );
202  maximum = std::max( maximum, rowPtr[ col ] );
203  }
204  }
205 
206  mean /= ( nCols * nRows );
207 
208  DataTypeT diff = 0.0;
209  variance = 0.0;
210 
211  for( row = 0 ; row < nRows ; ++row )
212  {
213  rowPtr = matrix[ row ];
214 
215  for( col = 0 ; col < nCols ; ++col )
216  {
217  diff = rowPtr[ col ] - mean;
218  variance += ( diff * diff );
219  }
220  }
221 
222  return true;
223  };
224 
225  /*!
226  \brief Load resampled IHS data from the input image.
227  \param highResRaster High resolution raster.
228  \param rgbMin RGB minimum value.
229  \param rgbMax RGB maximum value.
230  \param maxSimultaneousLinesPerMatrix The maximum number of RAM lines for each matrix.
231  \param intensityData Intensity channel data.
232  \param hueData Hue channel data.
233  \param saturationData Saturation channel data.
234  \return true if ok, false on errors.
235  \note IHS data with the following channels ranges: I:[0,1] H:[0,2pi] (radians) S:[0,1].
236  */
237  bool loadIHSData(
238  const te::rst::Raster& highResRaster,
239  const double& rgbMin,
240  const double rgbMax,
241  const unsigned int maxSimultaneousLinesPerMatrix,
242  te::rp::Matrix< double >& intensityData,
243  te::rp::Matrix< float >& hueData, te::rp::Matrix< float >& saturationData ) const;
244 
245  /*!
246  \brief Swap the intensity data by the high resolution image data.
247  \param highResRaster High resolution raster.
248  \param intensityData Intensity channel data.
249  \return true if ok, false on errors.
250  */
251  bool swapIntensity( const te::rst::Raster& highResRaster,
252  te::rp::Matrix< double >& intensityData );
253 
254  /*!
255  \brief Save resampled IHS data as RGB data to the output image.
256  \param highResRaster High resolution raster.
257  \param rgbMin RGB minimum value.
258  \param rgbMax RGB maximum value.
259  \param intensityData Intensity channel data.
260  \param hueData Hue channel data.
261  \param saturationData Saturation channel data.
262  \return true if ok, false on errors.
263  */
264  bool saveIHSData( const te::rst::Raster& highResRaster,
265  const double& rgbMin, const double rgbMax,
266  const te::rp::Matrix< double >& intensityData,
267  const te::rp::Matrix< float >& hueData,
268  const te::rp::Matrix< float >& saturationData,
269  const std::string& rType, const std::map< std::string, std::string >& rInfo,
270  std::unique_ptr< te::rst::Raster >& outputRasterPtr ) const;
271  };
272 
273  } // end namespace rp
274 } // end namespace te
275 
276 #endif
277 
te::rp::IHSFusion
Fusion of a low-resolution multi-band image with a high resolution image using the IHS method.
Definition: IHSFusion.h:58
te::rp::Matrix
A generic template matrix.
Definition: Matrix.h:55
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::rp::AlgorithmOutputParameters
Raster Processing algorithm output parameters base interface.
Definition: AlgorithmOutputParameters.h:40
te::rp::IHSFusion::OutputParameters::m_rType
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition: IHSFusion.h:117
te::rst::Raster
An abstract class for raster data strucutures.
Definition: Raster.h:72
te::rp::AlgorithmInputParameters
Raster Processing algorithm input parameters base interface.
Definition: AlgorithmInputParameters.h:40
te::rp::IHSFusion::InputParameters::m_lowResRasterRedBandIndex
unsigned int m_lowResRasterRedBandIndex
The low-resolution raster red band index (default:0).
Definition: IHSFusion.h:71
Matrix.h
Generic template matrix.
te::rp::IHSFusion::swapIntensity
bool swapIntensity(const te::rst::Raster &highResRaster, te::rp::Matrix< double > &intensityData)
Swap the intensity data by the high resolution image data.
te::rp::IHSFusion::InputParameters::m_highResRasterBand
unsigned int m_highResRasterBand
Band to process from the high-resolution raster.
Definition: IHSFusion.h:79
te::rp::IHSFusion::InputParameters::m_autoAlignRasters
bool m_autoAlignRasters
If true, the HR image will be clipped and reprojected to mach the LR image area.
Definition: IHSFusion.h:91
te::rp::Algorithm
Raster Processing algorithm base interface.
Definition: Algorithm.h:42
te::rst::InterpolationMethod
InterpolationMethod
Allowed interpolation methods.
Definition: Enums.h:93
te::rp::IHSFusion::loadIHSData
bool loadIHSData(const te::rst::Raster &highResRaster, const double &rgbMin, const double rgbMax, const unsigned int maxSimultaneousLinesPerMatrix, te::rp::Matrix< double > &intensityData, te::rp::Matrix< float > &hueData, te::rp::Matrix< float > &saturationData) const
Load resampled IHS data from the input image.
te::rp::IHSFusion::InputParameters::m_enableProgress
bool m_enableProgress
Enable/Disable the progress interface (default:false).
Definition: IHSFusion.h:81
te::rp::IHSFusion::InputParameters::m_RGBMax
double m_RGBMax
The used RGB maximum value (default:0 - leave zero for automatic detection based on the input images)...
Definition: IHSFusion.h:87
te::Exception
Base exception class for plugin module.
Definition: Exception.h:42
te::rp::IHSFusion::OutputParameters::reset
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state.
te::rp::IHSFusion::InputParameters
IHSFusion input parameters.
Definition: IHSFusion.h:66
TERPEXPORT
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:139
te::rp::IHSFusion::InputParameters::reset
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state.
te::rp::IHSFusion::OutputParameters::OutputParameters
OutputParameters()
te::rp::IHSFusion::InputParameters::InputParameters
InputParameters(const InputParameters &)
te::rp::IHSFusion::InputParameters::m_lowResRasterBlueBandIndex
unsigned int m_lowResRasterBlueBandIndex
The low-resolution raster blue band index (default:2).
Definition: IHSFusion.h:75
te::rp::IHSFusion::InputParameters::~InputParameters
~InputParameters()
te::rp::IHSFusion::InputParameters::InputParameters
InputParameters()
te::rp::IHSFusion::InputParameters::m_highResRasterPtr
te::rst::Raster const * m_highResRasterPtr
Input high-resolution raster.
Definition: IHSFusion.h:77
te::rp::IHSFusion::InputParameters::m_lowResRasterPtr
te::rst::Raster const * m_lowResRasterPtr
Input low-resolution multi-band raster.
Definition: IHSFusion.h:69
te::rp::IHSFusion::InputParameters::m_lowResRasterGreenBandIndex
unsigned int m_lowResRasterGreenBandIndex
The low-resolution raster green band index (default:1).
Definition: IHSFusion.h:73
Algorithm.h
Abstract algorithm.
te::rp::IHSFusion::OutputParameters::m_outputRasterPtr
std::unique_ptr< te::rst::Raster > m_outputRasterPtr
The generated output fused raster.
Definition: IHSFusion.h:121
te::rp::IHSFusion::OutputParameters::~OutputParameters
~OutputParameters()
te::rp::IHSFusion::OutputParameters::OutputParameters
OutputParameters(const OutputParameters &)
te::rp::IHSFusion::saveIHSData
bool saveIHSData(const te::rst::Raster &highResRaster, const double &rgbMin, const double rgbMax, const te::rp::Matrix< double > &intensityData, const te::rp::Matrix< float > &hueData, const te::rp::Matrix< float > &saturationData, const std::string &rType, const std::map< std::string, std::string > &rInfo, std::unique_ptr< te::rst::Raster > &outputRasterPtr) const
Save resampled IHS data as RGB data to the output image.
te::rp::IHSFusion::InputParameters::m_RGBMin
double m_RGBMin
The used RGB minimum value (default:0 - leave zero for automatic detection based on the input images)...
Definition: IHSFusion.h:85
te::rp::IHSFusion::OutputParameters::m_rInfo
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:119
te::rp::IHSFusion::OutputParameters
IHSFusion output parameters.
Definition: IHSFusion.h:114
te::rp::IHSFusion::InputParameters::m_interpMethod
te::rst::Interpolator::Method m_interpMethod
The raster interpolator method (default:NearestNeighbor).
Definition: IHSFusion.h:83
te::rp::IHSFusion::InputParameters::m_enableThreadedProcessing
bool m_enableThreadedProcessing
If true, threaded processing will be performed (best with multi-core or multi-processor systems (defa...
Definition: IHSFusion.h:89