~ubuntu-branches/ubuntu/hardy/libterralib/hardy

« back to all changes in this revision

Viewing changes to src/terralib/PDI/source/TePDIContrast.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2005-11-25 22:32:59 UTC
  • Revision ID: james.westby@ubuntu.com-20051125223259-3zubal8ux4ki4fjg
Tags: upstream-3.0.3b2
ImportĀ upstreamĀ versionĀ 3.0.3b2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
TerraLib - a library for developing GIS applications.
 
3
Copyright  2001, 2002, 2003 INPE and Tecgraf/PUC-Rio.
 
4
 
 
5
This code is part of the TerraLib library.
 
6
This library is free software; you can redistribute it and/or
 
7
modify it under the terms of the GNU Lesser General Public
 
8
License as published by the Free Software Foundation; either
 
9
version 2.1 of the License, or (at your option) any later version.
 
10
 
 
11
You should have received a copy of the GNU Lesser General Public
 
12
License along with this library.
 
13
 
 
14
The authors reassure the license terms regarding the warranties.
 
15
They specifically disclaim any warranties, including, but not limited to,
 
16
the implied warranties of merchantability and fitness for a particular
 
17
purpose. The library provided hereunder is on an "as is" basis, and the
 
18
authors have no obligation to provide maintenance, support, updates,
 
19
enhancements, or modifications.
 
20
In no event shall INPE be held liable to any party
 
21
for direct, indirect, special, incidental, or consequential damages arising
 
22
out of the use of this library and its documentation.
 
23
*/
 
24
 
 
25
#ifndef TEPDICONTRAST_HPP
 
26
  #define TEPDICONTRAST_HPP
 
27
 
 
28
  #include "TePDIAlgorithm.hpp"
 
29
  #include "TePDIRgbPalette.hpp"
 
30
  #include "TePDITypes.hpp"
 
31
 
 
32
  #include "TePDISharedPtr.cpp"
 
33
 
 
34
  /**
 
35
   *   This is the class for contrast image processing algorithms.
 
36
   */
 
37
  class TePDIContrast : public TePDIAlgorithm{
 
38
    public :
 
39
      typedef TePDISharedPtr< TePDIContrast > pointer;
 
40
      typedef const TePDISharedPtr< TePDIContrast > const_pointer;
 
41
 
 
42
      /**
 
43
       * Allowed contrast types.
 
44
       */
 
45
      enum TePDIContrastType{
 
46
        TePDIContrastMinMax = 1,
 
47
        TePDIContrastLinear = 2,
 
48
        TePDIContrastSquareRoot = 3,
 
49
        TePDIContrastSquare = 4,
 
50
        TePDIContrastLog = 5,
 
51
        TePDIContrastNegative = 6,
 
52
        TePDIContrastHistEqualizer = 7,
 
53
        TePDIContrastSimpleSlicer = 8
 
54
      };
 
55
 
 
56
      /**
 
57
       * Alternative Constructor.
 
58
       *
 
59
       * The general required parameters by any contrast type:
 
60
       *
 
61
       * contrast_type (TePDIContrastType),
 
62
       * input_image (TePDITypes::TePDIRasterPtrType),
 
63
       * output_image (TePDITypes::TePDIRasterPtrType),
 
64
       * histo_levels (int) - Number of interpolated histogram levels.
 
65
       *
 
66
       * The specific required parameters ( by parameter type ):
 
67
       *
 
68
       * channels (std::vector<int>) - Band(s) to process. For
 
69
       * TePDIContrastSimpleSlicer just one band is allowed.
 
70
       *
 
71
       * min_level (double) - Minimal level for Linear Luts
 
72
       * Required by: TePDIContrastLinear, TePDIContrastSquareRoot,
 
73
       * TePDIContrastSquare, TePDIContrastLog, TePDIContrastNegative,
 
74
       * TePDIContrastSimpleSlicer
 
75
       *
 
76
       * max_level (double) - Minimal level for Linear Luts
 
77
       * Required by: TePDIContrastLinear, TePDIContrastSquareRoot,
 
78
       * TePDIContrastSquare, TePDIContrastLog, TePDIContrastNegative,
 
79
       * TePDIContrastSimpleSlicer
 
80
       *
 
81
       * rgb_palette (TePDIRgbPalette::pointer) -
 
82
       * Reference RGB palette.
 
83
       * Required by: TePDIContrastSimpleSlicer
 
84
       *
 
85
       * @param params Algoritm parameters.
 
86
       */
 
87
      TePDIContrast( const TePDIParameters& params );
 
88
 
 
89
      /**
 
90
       * Default Constructor.
 
91
       *
 
92
       */
 
93
      TePDIContrast();
 
94
 
 
95
      /**
 
96
       * Default Destructor
 
97
       */
 
98
      ~TePDIContrast();
 
99
 
 
100
      /**
 
101
       * Checks if the supplied parameters fits the requirements of each
 
102
       * PDI algorithm implementation.
 
103
       *
 
104
       * Error log messages must be generated. No exceptions generated.
 
105
       *
 
106
       * @param parameters The parameters to be checked.
 
107
       * @return true if the parameters are OK. false if not.
 
108
       */
 
109
      bool CheckParameters( const TePDIParameters& parameters );
 
110
 
 
111
    protected :
 
112
      /**
 
113
       * A cache of level ordered histograms to avoid rebuilding
 
114
       * histograms all the times.
 
115
       */
 
116
      TePDITypes::TePDIHistogramsMapType histo_cache_;
 
117
 
 
118
      /**
 
119
       * Runs the current algorithm implementation.
 
120
       *
 
121
       * @return true if OK. false on error.
 
122
       */
 
123
      bool RunImplementation();
 
124
 
 
125
      /**
 
126
       * Reset the internal state to the initial state.
 
127
       */
 
128
      void ResetState();
 
129
 
 
130
      /**
 
131
       * Build level ordered histograms from the required raster channels.
 
132
       *
 
133
       * The result histograms will remain inside the protected
 
134
       * object histo_cache_
 
135
       *
 
136
       * @param inRaster The input Raster.
 
137
       * @param histo_levels Number of histogram interpolated levels.
 
138
       * @param channels Channels to use for histogram generation.
 
139
       * @param force Force histogram regeneratin even if already in cache.
 
140
       */
 
141
      void BuildHistograms(
 
142
        TePDITypes::TePDIRasterPtrType& inRaster,
 
143
        unsigned int histo_levels,
 
144
        std::vector< int >& channels,
 
145
        bool force = false );
 
146
 
 
147
      /**
 
148
       * Do level remapping from one raster to another.
 
149
       *
 
150
       * @param inRaster The input Raster.
 
151
       * @param outRaster The Output Raster.
 
152
       * @param lut The look-up table.
 
153
       * @param in_channel in_raster channel to remap.
 
154
       * @param out_channel out_raster channel to write on.
 
155
       */
 
156
      void RemapLevels(
 
157
        TePDITypes::TePDIRasterPtrType& inRaster,
 
158
        TePDITypes::TePDILutType& lut,
 
159
        int in_channel,
 
160
        int out_channel,
 
161
        TePDITypes::TePDIRasterPtrType& outRaster );
 
162
 
 
163
      /**
 
164
       * Get the maximum histogram level.
 
165
       *
 
166
       * Only for histograms with levels equal or greater than zero.
 
167
       *
 
168
       * @param hist The input LEVEL ORDERED histogram.
 
169
       * @return the maximum level.
 
170
       */
 
171
      double GetHistMax( TePDITypes::TePDIHistogramType& hist );
 
172
 
 
173
      /**
 
174
       * Get the minimum histogram level.
 
175
       *
 
176
       * Only for histograms with levels equal or greater than zero.
 
177
       *
 
178
       * @param hist The input LEVEL ORDERED histogram.
 
179
       * @return the minimum level.
 
180
       */
 
181
      double GetHistMin( TePDITypes::TePDIHistogramType& hist );
 
182
 
 
183
      /**
 
184
       * Build a min-max look-up table.
 
185
       *
 
186
       * @param hist Base histogram.
 
187
       * @return  The look-up table.
 
188
       */
 
189
      TePDITypes::TePDILutType GetMinMaxLut(
 
190
        TePDITypes::TePDIHistogramType& hist );
 
191
 
 
192
      /**
 
193
       * Build a Linear look-up table.
 
194
       *
 
195
       * @param min Minimal level value.
 
196
       * @param max Maximum level value.
 
197
       * @param hist Base histogram.
 
198
       * @return The look-up table.
 
199
       */
 
200
      TePDITypes::TePDILutType GetLinearLut(
 
201
        TePDITypes::TePDIHistogramType& hist,
 
202
        double min, double max );
 
203
 
 
204
      /**
 
205
       * Build a Square Root look-up table.
 
206
       *
 
207
       * @param min Minimal level value.
 
208
       * @param max Maximum level value.
 
209
       * @param hist Base histogram.
 
210
       * @return The look-up table.
 
211
       */
 
212
      TePDITypes::TePDILutType GetSquareRootLut(
 
213
        TePDITypes::TePDIHistogramType& hist,
 
214
        double min, double max );
 
215
 
 
216
      /**
 
217
       * Build a Square look-up table.
 
218
       *
 
219
       * @param min Minimal level value.
 
220
       * @param max Maximum level value.
 
221
       * @param hist Base histogram.
 
222
       * @return The look-up table.
 
223
       */
 
224
      TePDITypes::TePDILutType GetSquareLut(
 
225
        TePDITypes::TePDIHistogramType& hist,
 
226
        double min, double max );
 
227
 
 
228
      /**
 
229
       * Build a Log look-up table.
 
230
       *
 
231
       * @param min Minimal level value.
 
232
       * @param max Maximum level value.
 
233
       * @param hist Base histogram.
 
234
       * @return The look-up table.
 
235
       */
 
236
      TePDITypes::TePDILutType GetLogLut(
 
237
        TePDITypes::TePDIHistogramType& hist,
 
238
        double min, double max );
 
239
 
 
240
      /**
 
241
       * Build a Negative look-up table.
 
242
       *
 
243
       * @param min Minimal level value.
 
244
       * @param max Maximum level value.
 
245
       * @param hist Base histogram.
 
246
       * @return The look-up table.
 
247
       */
 
248
      TePDITypes::TePDILutType GetNegativeLut(
 
249
        TePDITypes::TePDIHistogramType& hist,
 
250
        double min, double max );
 
251
 
 
252
      /**
 
253
       * Build a Histogram equalizer look-up table.
 
254
       *
 
255
       * @param hist A LEVEL-ORDERED Base histogram.
 
256
       * @return The look-up table.
 
257
       */
 
258
      TePDITypes::TePDILutType GetHistEqualizerLut(
 
259
        TePDITypes::TePDIHistogramType& hist );
 
260
 
 
261
      /**
 
262
       * Builds a Simple slicer look-up table.
 
263
       *
 
264
       * @param hist A LEVEL-ORDERED Base histogram.
 
265
       * @param in_palette The reference RGB palette.
 
266
       * @param min Minimal level value.
 
267
       * @param max Maximum level value.
 
268
       * @param out_lut The look-up table.
 
269
       */
 
270
      void GetSimpleSlicerLut(
 
271
        TePDITypes::TePDIHistogramType& hist,
 
272
        TePDIRgbPalette::pointer in_palette,
 
273
        double min,
 
274
        double max,
 
275
        TePDITypes::TePDILutType& out_lut );
 
276
  };
 
277
 
 
278
#endif //TEPDICONTRAST_HPP