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 
92 
94 
96 
97  //overload
98  void reset() throw( te::rp::Exception );
99 
100  //overload
101  const InputParameters& operator=( const InputParameters& params );
102 
103  //overload
104  AbstractParameters* clone() const;
105  };
106 
107  /*!
108  \class OutputParameters
109  \brief IHSFusion output parameters
110  */
112  {
113  public:
114 
115  std::string m_rType; //!< Output raster data source type (as described in te::raster::RasterFactory ).
116 
117  std::map< std::string, std::string > m_rInfo; //!< The necessary information to create the output rasters (as described in te::raster::RasterFactory).
118 
119  std::unique_ptr< te::rst::Raster > m_outputRasterPtr; //!< The generated output fused raster.
120 
122 
124 
126 
127  //overload
128  void reset() throw( te::rp::Exception );
129 
130  //overload
131  const OutputParameters& operator=( const OutputParameters& params );
132 
133  //overload
134  AbstractParameters* clone() const;
135  };
136 
138 
140 
141  //overload
142  bool execute( AlgorithmOutputParameters& outputParams ) throw( te::rp::Exception );
143 
144  //overload
145  void reset() throw( te::rp::Exception );
146 
147  //overload
148  bool initialize( const AlgorithmInputParameters& inputParams ) throw( te::rp::Exception );
149 
150  //overload
151  bool isInitialized() const;
152 
153  protected:
154 
155  InputParameters m_inputParameters; //!< Input execution parameters.
156 
157  bool m_isInitialized; //!< Tells if this instance is initialized.
158 
159  /*!
160  \brief Get the minimum and maximum values from the RGB input image.
161  \param rgbMin RGB minimum value.
162  \param rgbMax RGB maximum value.
163  \return true if ok, false on errors.
164  */
165  bool getRGBRange( double& rgbMin, double& rgbMax ) const;
166 
167  /*!
168  \brief Get statistics from the given matrix.
169  \param matrix Input matrix.
170  \param mean Mean value.
171  \param variance Variance value.
172  \return true if ok, false on errors.
173  */
174  template< typename DataTypeT >
175  bool getStatistics( const te::rp::Matrix< DataTypeT >& matrix,
176  DataTypeT& mean, DataTypeT& variance,
177  DataTypeT& minimum, DataTypeT& maximum ) const
178  {
179  const unsigned int nRows = matrix.getLinesNumber();
180  const unsigned int nCols = matrix.getColumnsNumber();
181 
182  if( ( nRows == 0 ) || ( nCols == 0 ) ) return false;
183 
184  unsigned int col = 0;
185  unsigned int row = 0;
186  DataTypeT const * rowPtr = nullptr;
187 
188  minimum = std::numeric_limits< DataTypeT >::max();
189  maximum = ((DataTypeT)-1) * std::numeric_limits< DataTypeT >::max();
190  mean = 0.0;
191 
192  for( row = 0 ; row < nRows ; ++row )
193  {
194  rowPtr = matrix[ row ];
195 
196  for( col = 0 ; col < nCols ; ++col )
197  {
198  mean += rowPtr[ col ];
199  minimum = std::min( minimum, rowPtr[ col ] );
200  maximum = std::max( maximum, rowPtr[ col ] );
201  }
202  }
203 
204  mean /= ( nCols * nRows );
205 
206  DataTypeT diff = 0.0;
207  variance = 0.0;
208 
209  for( row = 0 ; row < nRows ; ++row )
210  {
211  rowPtr = matrix[ row ];
212 
213  for( col = 0 ; col < nCols ; ++col )
214  {
215  diff = rowPtr[ col ] - mean;
216  variance += ( diff * diff );
217  }
218  }
219 
220  return true;
221  };
222 
223  /*!
224  \brief Load resampled IHS data from the input image.
225  \param rgbMin RGB minimum value.
226  \param rgbMax RGB maximum value.
227  \param maxSimultaneousLinesPerMatrix The maximum number of RAM lines for each matrix.
228  \param intensityData Intensity channel data.
229  \param hueData Hue channel data.
230  \param saturationData Saturation channel data.
231  \return true if ok, false on errors.
232  \note IHS data with the following channels ranges: I:[0,1] H:[0,2pi] (radians) S:[0,1].
233  */
234  bool loadIHSData(
235  const double& rgbMin,
236  const double rgbMax,
237  const unsigned int maxSimultaneousLinesPerMatrix,
238  te::rp::Matrix< double >& intensityData,
239  te::rp::Matrix< float >& hueData, te::rp::Matrix< float >& saturationData ) const;
240 
241  /*!
242  \brief Swap the intensity data by the high resolution image data.
243  \param intensityData Intensity channel data.
244  \return true if ok, false on errors.
245  */
246  bool swapIntensity( te::rp::Matrix< double >& intensityData );
247 
248  /*!
249  \brief Save resampled IHS data as RGB data to the output image.
250  \param rgbMin RGB minimum value.
251  \param rgbMax RGB maximum value.
252  \param intensityData Intensity channel data.
253  \param hueData Hue channel data.
254  \param saturationData Saturation channel data.
255  \return true if ok, false on errors.
256  */
257  bool saveIHSData( const double& rgbMin, const double rgbMax,
258  const te::rp::Matrix< double >& intensityData,
259  const te::rp::Matrix< float >& hueData,
260  const te::rp::Matrix< float >& saturationData,
261  const std::string& rType, const std::map< std::string, std::string >& rInfo,
262  std::unique_ptr< te::rst::Raster >& outputRasterPtr ) const;
263  };
264 
265  } // end namespace rp
266 } // end namespace te
267 
268 #endif
269 
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::swapIntensity
bool swapIntensity(te::rp::Matrix< double > &intensityData)
Swap the intensity data by the high resolution image data.
te::rp::IHSFusion::OutputParameters::m_rType
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition: IHSFusion.h:115
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::loadIHSData
bool loadIHSData(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_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::InputParameters::m_highResRasterBand
unsigned int m_highResRasterBand
Band to process from the high-resolution raster.
Definition: IHSFusion.h:79
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::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:119
te::rp::IHSFusion::saveIHSData
bool saveIHSData(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::OutputParameters::~OutputParameters
~OutputParameters()
te::rp::IHSFusion::OutputParameters::OutputParameters
OutputParameters(const OutputParameters &)
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:117
te::rp::IHSFusion::OutputParameters
IHSFusion output parameters.
Definition: IHSFusion.h:112
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