OTB  10.0.0
Orfeo Toolbox
otbWaveletOperatorBase.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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"
26 #include "itkNeighborhoodOperator.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  FORWARD = 0,
39  INVERSE = 1
40 };
41 }
42 
75 template <Wavelet::Wavelet TMotherWaveletOperator, class TPixel, unsigned int VDimension, class TAllocator = itk::NeighborhoodAllocator<TPixel>>
76 class ITK_EXPORT WaveletOperatorBase : public itk::NeighborhoodOperator<TPixel, VDimension, TAllocator>
77 {
78 public:
79 
82  typedef itk::NeighborhoodOperator<TPixel, VDimension, TAllocator> Superclass;
83 
84  itkTypeMacro(WaveletOperatorBase, NeighborhoodOperator);
85 
86  typedef typename Superclass::SizeType SizeType;
88  itkStaticConstMacro(MotherWaveletOperator, MotherWaveletOperatorEnumType, TMotherWaveletOperator);
89 
92  m_UpSampleFactor(0),
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  m_WaveletGenerator(WaveletGeneratorType::New())
101  {}
102 
104  {
105  }
106 
108  Self& operator=(const Self& other)
109  {
110  Superclass::operator=(other);
111  m_UpSampleFactor = other.GetUpSampleFactor();
112  return *this;
113  }
115 
119  unsigned int GetUpSampleFactor() const
120  {
121  return this->m_UpSampleFactor;
122  }
123 
127  void SetUpSampleFactor(unsigned int upSampleFactor)
128  {
129  this->m_UpSampleFactor = upSampleFactor;
130  }
131 
135  virtual const char* GetWaveletName() const
136  {
137  return this->m_WaveletGenerator->GetWaveletName();
138  }
139 
140 protected:
144  void PrintSelf(std::ostream& os, itk::Indent i) const override;
145 
148 
153  typedef typename Superclass::CoefficientVector CoefficientVector;
154  typedef typename Superclass::PixelType PixelType;
155 
160  void UpSamplingCoefficients(CoefficientVector& coeff);
161 
165  void RevertFilter(CoefficientVector& coeff);
166 
177  void GenerateInverseHighPassFilterFromLowPassFilter(CoefficientVector& coeff);
178 
185  void GenerateInverseLowPassFilterFromHighPassFilter(CoefficientVector& coeff);
186 
190  void ReduceFilterLength(CoefficientVector& coeff);
191 
193  void Fill(const CoefficientVector& coeff) override
194  {
195  this->FillCenteredDirectional(coeff);
196  }
197 
198 #if 0
204  void GetHighPassFilterFromQuadratureLowPassFilter(CoefficientVector& coeff)
205  {
206  unsigned int length = coeff.size();
207 
208  CoefficientVector highPassCoeff (length);
209  int medianPosition = static_cast<int>(length) / 2;
210 
211  highPassCoeff[medianPosition] = -coeff[medianPosition];
212 
213  double sign = 1.;
214  for (int i = 1; i <= medianPosition; ++i)
215  {
216  highPassCoeff[medianPosition + i] = sign * coeff[medianPosition - i];
217  highPassCoeff[medianPosition - i] = sign * coeff[medianPosition + i];
218  sign *= -1.;
219  }
220 
221  coeff = highPassCoeff;
222  }
223 
229  void GetInverseHighPassFilterFromForwardLowPassFilter(CoefficientVector& coeff)
230  {
231  unsigned long length = static_cast<unsigned long>(coeff.size());
232  unsigned long medianPosition = length / 2;
234 
235  // Wavelet coefficients are always of add size, so that 2*medianPosition < length
236  coeff[medianPosition] *= -1.;
237  for (unsigned int i = 2; i <= medianPosition; i += 2)
238  {
239  coeff[medianPosition + i] *= -1.;
240  coeff[medianPosition - i] *= -1.;
241  }
242  }
243 
250  void GetInverseLowPassFilterFromForwardHighPassFilter(CoefficientVector& coeff)
251  {
252  unsigned long length = static_cast<unsigned long>(coeff.size());
253  unsigned long medianPosition = length / 2;
255 
256  // Wavelet coefficients are always of add size, so that 2*medianPosition < length
257  for (unsigned int i = 1; i <= medianPosition; i += 2)
258  {
259  coeff[medianPosition + i] *= -1.;
260  coeff[medianPosition - i] *= -1.;
261  }
262  }
263 
271  void GetForwardHighPassFilterFromInverseLowPassFilter(CoefficientVector& coeff)
272  {
273  GetInverseLowPassFilterFromForwardHighPassFilter(coeff);
274  }
275 #endif
277 
278  unsigned int m_UpSampleFactor;
280 };
281 
282 } // end of namespace otb
283 
284 #ifndef OTB_MANUAL_INSTANTIATION
286 #endif
287 
288 #endif
Wavelet coefficient definition.
itk::SmartPointer< Self > Pointer
A NeighborhoodOperator wavelet base class.
Superclass::CoefficientVector CoefficientVector
Wavelet::Wavelet MotherWaveletOperatorEnumType
Superclass::SizeType SizeType
itk::NeighborhoodOperator< TPixel, VDimension, TAllocator > Superclass
unsigned int GetUpSampleFactor() const
WaveletGeneratorPointerType m_WaveletGenerator
void Fill(const CoefficientVector &coeff) override
WaveletGenerator< TMotherWaveletOperator > WaveletGeneratorType
Self & operator=(const Self &other)
WaveletGeneratorType::Pointer WaveletGeneratorPointerType
WaveletOperatorBase(const Self &other)
Superclass::PixelType PixelType
void SetUpSampleFactor(unsigned int upSampleFactor)
virtual const char * GetWaveletName() const
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.