All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Contrast.h
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 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/Contrast.h
22  \brief Contrast enhancement.
23  */
24 
25 #ifndef __TERRALIB_RP_INTERNAL_CONTRAST_H
26 #define __TERRALIB_RP_INTERNAL_CONTRAST_H
27 
28 #include "Algorithm.h"
29 
30 #include <vector>
31 #include <string>
32 #include <map>
33 #include <memory>
34 
35 namespace te
36 {
37  namespace da
38  {
39  class DataSource;
40  };
41 
42  namespace rst
43  {
44  class Raster;
45  class Band;
46  };
47 
48  namespace rp
49  {
50  /*!
51  \class Contrast
52  \brief Contrast enhancement.
53  \details Apply contrast enhencement on the selected bands.
54  \ingroup rp
55  */
56  class TERPEXPORT Contrast : public Algorithm
57  {
58  public:
59 
60  /*!
61  \class InputParameters
62  \brief Contrast input parameters
63  */
65  {
66  public:
67 
68  /*! \enum Allowed contrast types. */
70  {
71  InvalidContrastT = 0, /*!< Invalid contrast. */
72  LinearContrastT = 1, /*!< The histogram range will be changed to the supplied min/max range ( linear function ). */
73  HistogramEqualizationContrastT = 2, /*!< The histogram of the image will be equalized automatically. */
74  SetMeanAndStdContrastT = 3, /*!< The contrasted image will have a predefined mean and standard deviation. */
75  };
76 
77  ContrastType m_type; //!< The contrast type to be applied.
78 
79  std::vector< double > m_lCMinInput; //!< The contrast minimum input greyscale value of each band.
80 
81  std::vector< double > m_lCMaxInput; //!< The contrast maximum input greyscale value of each band.
82 
83  std::vector< double > m_hECMaxInput; //!< The contrast maximum input greyscale value of each band.
84 
85  std::vector< double > m_sMASCMeanInput; //!< The mean greyscale to be applied in each band.
86 
87  std::vector< double > m_sMASCStdInput; //!< The standard deviation to be applied in each band.
88 
89  te::rst::Raster const* m_inRasterPtr; //!< Input raster.
90 
91  std::vector< unsigned int > m_inRasterBands; //!< Bands to be processed from the input raster.
92 
93  bool m_enableProgress; //!< Enable/Disable the progress interface (default:false).
94 
96 
97  ~InputParameters();
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 Contrast output parameters
112  \details The result will be written to the raster instance pointed
113  by m_outRasterPtr (in this case the output bands must also be
114  passed by m_outRasterBands ); or written to a new raster instance
115  created inside the given data source pointed by m_outDataSourcePtr
116  (in this case the data set name must be supplied - m_outDataSetName ).
117  */
119  {
120  public:
121 
122  te::rst::Raster* m_outRasterPtr; //!< A pointer to a valid initiated raster instance where the result must be written, leave NULL to create a new instance(in this case the other output parameters must be used).
123 
124  std::auto_ptr< te::rst::Raster > m_createdOutRasterPtr; //!< A pointer to the created output raster instance, or an empty pointer empty if the result must be written to the raster pointed m_outRasterPtr.
125 
126  std::vector< unsigned int > m_outRasterBands; //!< Bands to be processed from the output raster.
127 
128  std::string m_createdOutRasterDSType; //!< Output raster data source type (as described in te::raster::RasterFactory ), leave empty if the result must be written to the raster pointed m_outRasterPtr.
129 
130  std::map< std::string, std::string > m_createdOutRasterInfo; //!< The necessary information to create the raster (as described in te::raster::RasterFactory), leave empty if the result must be written to the raster pointed m_outRasterPtr.
131 
133 
135 
136  ~OutputParameters();
137 
138  //overload
139  void reset() throw( te::rp::Exception );
140 
141  //overload
142  const OutputParameters& operator=( const OutputParameters& params );
143 
144  //overload
145  AbstractParameters* clone() const;
146  };
147 
148  Contrast();
149 
150  ~Contrast();
151 
152  //overload
153  bool execute( AlgorithmOutputParameters& outputParams ) throw( te::rp::Exception );
154 
155  //overload
156  void reset() throw( te::rp::Exception );
157 
158  //overload
159  bool initialize( const AlgorithmInputParameters& inputParams ) throw( te::rp::Exception );
160 
161  bool isInitialized() const;
162 
163  protected:
164 
165  /*!
166  \brief Type definition for a remapping function pointer.
167  */
168  typedef void (Contrast::*RemapFuncPtrT)( const double& inValue,
169  double& outValue );
170 
171  Contrast::InputParameters m_inputParameters; //!< Contrast input execution parameters.
172  Contrast::OutputParameters* m_outputParametersPtr; //!< Contrast input execution parameters.
173 
174  bool m_isInitialized; //!< Tells if this instance is initialized.
175 
176  /*!
177  \brief Execute a linear contrast following the internal parameters
178  \return true if OK, false on errors.
179  */
180  bool execLinearContrast();
181 
182  /*!
183  \brief Execute the histogram equalization contrast following the internal parameters
184  \return true if OK, false on errors.
185  */
186  bool execHistogramEqualizationContrast();
187 
188  /*!
189  \brief Execute the histogram equalization contrast following the internal parameters
190  \return true if OK, false on errors.
191  */
192  bool execSetMeanAndStdContrast();
193 
194  /*!
195  \brief Band gray levels remap using a remap function.
196  \param inRasterBand Input raster band.
197  \param outRasterBand Output raster band.
198  \param remapFuncPtr The remap function pointer used.
199  \param enableProgress Enable the use of a progress interface.
200  \return true if OK, false on errors.
201  */
202  bool remapBandLevels( const te::rst::Band& inRasterBand,
203  te::rst::Band& outRasterBand, RemapFuncPtrT remapFuncPtr,
204  const bool enableProgress );
205 
206  // Variables used by offSetGainRemap
207  double m_offSetGainRemap_offset;
208  double m_offSetGainRemap_gain;
209 
210  /*!
211  \brief Remap on gray level using an offset
212  (Contrast::m_offSetGainRemap_offset) and a gain value
213  (Contrast::m_offSetGainRemap_gain.
214  \param inValue Input gray level.
215  \param outValue Output gray level.
216  */
217  inline void offSetGainRemap( const double& inValue, double& outValue )
218  {
219  outValue = ( inValue + m_offSetGainRemap_offset ) * m_offSetGainRemap_gain;
220  };
221 
222  };
223 
224  } // end namespace rp
225 } // end namespace te
226 
227 #endif
228 
std::vector< unsigned int > m_outRasterBands
Bands to be processed from the output raster.
Definition: Contrast.h:126
te::rst::Raster * m_outRasterPtr
A pointer to a valid initiated raster instance where the result must be written, leave NULL to create...
Definition: Contrast.h:122
Raster Processing algorithm base interface class.
Contrast enhancement.
Definition: Contrast.h:56
Contrast output parameters.
Definition: Contrast.h:118
std::vector< unsigned int > m_inRasterBands
Bands to be processed from the input raster.
Definition: Contrast.h:91
std::vector< double > m_lCMaxInput
The contrast maximum input greyscale value of each band.
Definition: Contrast.h:81
std::map< std::string, std::string > m_createdOutRasterInfo
The necessary information to create the raster (as described in te::raster::RasterFactory), leave empty if the result must be written to the raster pointed m_outRasterPtr.
Definition: Contrast.h:130
Raster Processing algorithm base interface.
Definition: Algorithm.h:42
std::string m_createdOutRasterDSType
Output raster data source type (as described in te::raster::RasterFactory ), leave empty if the resul...
Definition: Contrast.h:128
te::rst::Raster const * m_inRasterPtr
Input raster.
Definition: Contrast.h:89
std::vector< double > m_lCMinInput
The contrast minimum input greyscale value of each band.
Definition: Contrast.h:79
ContrastType m_type
The contrast type to be applied.
Definition: Contrast.h:77
bool m_enableProgress
Enable/Disable the progress interface (default:false).
Definition: Contrast.h:93
Contrast input parameters.
Definition: Contrast.h:64
std::auto_ptr< te::rst::Raster > m_createdOutRasterPtr
A pointer to the created output raster instance, or an empty pointer empty if the result must be writ...
Definition: Contrast.h:124
std::vector< double > m_hECMaxInput
The contrast maximum input greyscale value of each band.
Definition: Contrast.h:83
Raster Processing algorithm output parameters base interface.
An abstract class for raster data strucutures.
Definition: Raster.h:70
std::vector< double > m_sMASCMeanInput
The mean greyscale to be applied in each band.
Definition: Contrast.h:85
std::vector< double > m_sMASCStdInput
The standard deviation to be applied in each band.
Definition: Contrast.h:87
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:91
Raster Processing algorithm input parameters base interface.