OTB  6.7.0
Orfeo Toolbox
otbWaveletOperatorBase.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3  * Copyright (C) 2007-2012 Institut Mines Telecom / Telecom Bretagne
4  *
5  * This file is part of Orfeo Toolbox
6  *
7  * https://www.orfeo-toolbox.org/
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 #ifndef otbWaveletOperatorBase_h
23 #define otbWaveletOperatorBase_h
24 
25 #include "itkMacro.h"
27 
28 // This include is needed here to define MotherWaveletOperatorEnum...
29 #include "otbWaveletGenerator.h"
30 
31 namespace otb
32 {
33 
34 namespace Wavelet
35 {
37 }
38 
71 template <Wavelet::Wavelet TMotherWaveletOperator,
72  class TPixel, unsigned int VDimension,
73  class TAllocator = itk::NeighborhoodAllocator<TPixel> >
74 class ITK_EXPORT WaveletOperatorBase
75  : public itk::NeighborhoodOperator<TPixel, VDimension, TAllocator>
76 {
77 public:
78 
82 
83  itkTypeMacro(WaveletOperatorBase, NeighborhoodOperator);
84 
85  typedef typename Superclass::SizeType SizeType;
87  itkStaticConstMacro(MotherWaveletOperator, MotherWaveletOperatorEnumType, TMotherWaveletOperator);
88 
91  m_UpSampleFactor(0)
92  {
93  m_WaveletGenerator = WaveletGeneratorType::New();
94  }
95 
97  WaveletOperatorBase(const Self &other)
98  : itk::NeighborhoodOperator<TPixel, VDimension, TAllocator> (other),
99  m_UpSampleFactor(other.GetUpSampleFactor())
100  {
101  m_WaveletGenerator = WaveletGeneratorType::New();
102  }
103 
104  ~WaveletOperatorBase() override {}
105 
107  Self & operator =(const Self& other)
108  {
109  Superclass::operator =(other);
110  m_UpSampleFactor = other.GetUpSampleFactor();
111  return *this;
112  }
114 
118  unsigned int GetUpSampleFactor() const
119  {
120  return this->m_UpSampleFactor;
121  }
122 
126  void SetUpSampleFactor(unsigned int upSampleFactor)
127  {
128  this->m_UpSampleFactor = upSampleFactor;
129  }
130 
134  virtual const char * GetWaveletName() const
135  {
136  return this->m_WaveletGenerator->GetWaveletName();
137  }
138 
139 protected:
143  void PrintSelf(std::ostream& os, itk::Indent i) const override;
144 
147 
152  typedef typename Superclass::CoefficientVector CoefficientVector;
154 
159  void UpSamplingCoefficients(CoefficientVector& coeff);
160 
164  void RevertFilter(CoefficientVector& coeff);
165 
176  void GenerateInverseHighPassFilterFromLowPassFilter(CoefficientVector& coeff);
177 
184  void GenerateInverseLowPassFilterFromHighPassFilter(CoefficientVector& coeff);
185 
189  void ReduceFilterLength(CoefficientVector& coeff);
190 
192  void Fill(const CoefficientVector& coeff) override
193  {
194  this->FillCenteredDirectional(coeff);
195  }
196 
197 #if 0
198 
203  void GetHighPassFilterFromQuadratureLowPassFilter(CoefficientVector& coeff)
204  {
205  unsigned int length = coeff.size();
206 
207  CoefficientVector highPassCoeff (length);
208  int medianPosition = static_cast<int>(length) / 2;
209 
210  highPassCoeff[medianPosition] = -coeff[medianPosition];
211 
212  double sign = 1.;
213  for (int i = 1; i <= medianPosition; ++i)
214  {
215  highPassCoeff[medianPosition + i] = sign * coeff[medianPosition - i];
216  highPassCoeff[medianPosition - i] = sign * coeff[medianPosition + i];
217  sign *= -1.;
218  }
219 
220  coeff = highPassCoeff;
221  }
222 
228  void GetInverseHighPassFilterFromForwardLowPassFilter(CoefficientVector& coeff)
229  {
230  unsigned long length = static_cast<unsigned long>(coeff.size());
231  unsigned long medianPosition = length / 2;
233 
234  // Wavelet coefficients are always of add size, so that 2*medianPosition < length
235  coeff[medianPosition] *= -1.;
236  for (unsigned int i = 2; i <= medianPosition; i += 2)
237  {
238  coeff[medianPosition + i] *= -1.;
239  coeff[medianPosition - i] *= -1.;
240  }
241  }
242 
249  void GetInverseLowPassFilterFromForwardHighPassFilter(CoefficientVector& coeff)
250  {
251  unsigned long length = static_cast<unsigned long>(coeff.size());
252  unsigned long medianPosition = length / 2;
254 
255  // Wavelet coefficients are always of add size, so that 2*medianPosition < length
256  for (unsigned int i = 1; i <= medianPosition; i += 2)
257  {
258  coeff[medianPosition + i] *= -1.;
259  coeff[medianPosition - i] *= -1.;
260  }
261  }
262 
270  void GetForwardHighPassFilterFromInverseLowPassFilter(CoefficientVector& coeff)
271  {
272  GetInverseLowPassFilterFromForwardHighPassFilter(coeff);
273  }
274 #endif
275 
276 
277  unsigned int m_UpSampleFactor;
279 };
280 
281 } // end of namespace otb
282 
283 #ifndef OTB_MANUAL_INSTANTIATION
285 #endif
286 
287 #endif
itk::Size< Monteverdi_DIMENSION > SizeType
Definition: mvdTypes.h:137
Wavelet::Wavelet MotherWaveletOperatorEnumType
itk::NeighborhoodOperator< TPixel, VDimension, TAllocator > Superclass
WaveletGeneratorType::Pointer WaveletGeneratorPointerType
A NeighborhoodOperator wavelet base class.
WaveletGeneratorPointerType m_WaveletGenerator
std::vector< PixelRealType > CoefficientVector
Superclass::PixelType PixelType
void Fill(const CoefficientVector &coeff) override
Wavelet coefficient definition.
WaveletOperatorBase(const Self &other)
Superclass::SizeType SizeType
virtual const char * GetWaveletName() const
unsigned int GetUpSampleFactor() const
Superclass::CoefficientVector CoefficientVector
WaveletGenerator< TMotherWaveletOperator > WaveletGeneratorType
void SetUpSampleFactor(unsigned int upSampleFactor)