OTB  9.0.0
Orfeo Toolbox
otbWaveletOperatorBase.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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 
147  typedef typename WaveletGeneratorType::Pointer WaveletGeneratorPointerType;
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
199 
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
276 
277 
278  unsigned int m_UpSampleFactor;
280 };
281 
282 } // end of namespace otb
283 
284 #ifndef OTB_MANUAL_INSTANTIATION
286 #endif
287 
288 #endif
otb::Wavelet::INVERSE
@ INVERSE
Definition: otbWaveletOperatorBase.h:39
otb::WaveletOperatorBase::Fill
void Fill(const CoefficientVector &coeff) override
Definition: otbWaveletOperatorBase.h:193
otb::WaveletOperatorBase::WaveletGeneratorType
WaveletGenerator< TMotherWaveletOperator > WaveletGeneratorType
Definition: otbWaveletOperatorBase.h:146
otb::WaveletOperatorBase::Self
WaveletOperatorBase Self
Definition: otbWaveletOperatorBase.h:81
otb::WaveletOperatorBase::Superclass
itk::NeighborhoodOperator< TPixel, VDimension, TAllocator > Superclass
Definition: otbWaveletOperatorBase.h:82
otb::WaveletOperatorBase::GetWaveletName
virtual const char * GetWaveletName() const
Definition: otbWaveletOperatorBase.h:135
otb::WaveletGenerator
Wavelet coefficient definition.
Definition: otbWaveletGenerator.h:70
otb::WaveletOperatorBase::PixelType
Superclass::PixelType PixelType
Definition: otbWaveletOperatorBase.h:154
otb::Wavelet::Wavelet
Wavelet
Definition: otbWaveletGenerator.h:35
otbWaveletGenerator.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::WaveletOperatorBase::WaveletGeneratorPointerType
WaveletGeneratorType::Pointer WaveletGeneratorPointerType
Definition: otbWaveletOperatorBase.h:147
otb::WaveletOperatorBase::SizeType
Superclass::SizeType SizeType
Definition: otbWaveletOperatorBase.h:84
otb::WaveletOperatorBase::operator=
Self & operator=(const Self &other)
Definition: otbWaveletOperatorBase.h:108
otb::WaveletOperatorBase::GetUpSampleFactor
unsigned int GetUpSampleFactor() const
Definition: otbWaveletOperatorBase.h:119
otbWaveletOperatorBase.hxx
otb::WaveletOperatorBase::SetUpSampleFactor
void SetUpSampleFactor(unsigned int upSampleFactor)
Definition: otbWaveletOperatorBase.h:127
otb::WaveletOperatorBase::WaveletOperatorBase
WaveletOperatorBase(const Self &other)
Definition: otbWaveletOperatorBase.h:97
otb::Wavelet::WaveletDirection
WaveletDirection
Definition: otbWaveletOperatorBase.h:36
otb::WaveletOperatorBase::m_WaveletGenerator
WaveletGeneratorPointerType m_WaveletGenerator
Definition: otbWaveletOperatorBase.h:279
otb::WaveletOperatorBase
A NeighborhoodOperator wavelet base class.
Definition: otbWaveletOperatorBase.h:76
itk
Definition: otbNoDataHelper.h:31
otb::Wavelet::FORWARD
@ FORWARD
Definition: otbWaveletOperatorBase.h:38
otb::WaveletOperatorBase::m_UpSampleFactor
unsigned int m_UpSampleFactor
Definition: otbWaveletOperatorBase.h:278
otb::WaveletOperatorBase::~WaveletOperatorBase
~WaveletOperatorBase() override
Definition: otbWaveletOperatorBase.h:103
otb::WaveletOperatorBase::CoefficientVector
Superclass::CoefficientVector CoefficientVector
Definition: otbWaveletOperatorBase.h:153
otb::WaveletOperatorBase::WaveletOperatorBase
WaveletOperatorBase()
Definition: otbWaveletOperatorBase.h:91
otb::WaveletOperatorBase::MotherWaveletOperatorEnumType
Wavelet::Wavelet MotherWaveletOperatorEnumType
Definition: otbWaveletOperatorBase.h:87