OTB  9.0.0
Orfeo Toolbox
otbWaveletOperatorBase.hxx
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 
23 #ifndef otbWaveletOperatorBase_hxx
24 #define otbWaveletOperatorBase_hxx
25 
26 #include "otbWaveletOperatorBase.h"
27 
28 #include <cassert>
29 
30 namespace otb
31 {
32 
33 template <Wavelet::Wavelet TMotherWaveletOperator, class TPixel, unsigned int VDimension, class TAllocator>
35 {
36  os << i << "Wavelet kind : " << GetWaveletName() << "\n";
37  os << i << "Up-Sampling factor " << GetUpSampleFactor() << "\n";
38  Superclass::PrintSelf(os, i.GetNextIndent());
39  os << i << "Wavelet coeff: [ ";
40  for (typename Superclass::ConstIterator iter = Superclass::Begin(); iter != Superclass::End(); ++iter)
41  {
42  os << *iter << ' ';
43  }
44  os << "]\n";
45 }
46 
47 template <Wavelet::Wavelet TMotherWaveletOperator, class TPixel, unsigned int VDimension, class TAllocator>
49 {
50  if (m_UpSampleFactor <= 1)
51  return;
52 
53  unsigned long radius = static_cast<unsigned long>(coeff.size()) >> 1;
54  unsigned long upSampleRadius = radius * m_UpSampleFactor;
55 
56  CoefficientVector upSampledCoeff(2 * upSampleRadius + 1);
57  upSampledCoeff.assign(2 * upSampleRadius + 1, 0.);
58  upSampledCoeff[upSampleRadius] = coeff[radius];
59 
60  for (unsigned int i = 1; i <= radius; ++i)
61  {
62  upSampledCoeff[upSampleRadius + m_UpSampleFactor * i] = coeff[radius + i];
63  upSampledCoeff[upSampleRadius - m_UpSampleFactor * i] = coeff[radius - i];
64  }
65  coeff = upSampledCoeff;
66 }
67 
68 template <Wavelet::Wavelet TMotherWaveletOperator, class TPixel, unsigned int VDimension, class TAllocator>
70 {
71  const unsigned int length = coeff.size();
72  const unsigned int medianPosition = length / 2;
73 
74  CoefficientVector newCoeff(length);
75  newCoeff[medianPosition] = coeff[medianPosition];
76  for (unsigned int i = 1; i <= medianPosition; ++i)
77  {
78  newCoeff[medianPosition + i] = coeff[medianPosition - i];
79  newCoeff[medianPosition - i] = coeff[medianPosition + i];
80  }
81 
82  coeff = newCoeff;
83 }
84 
85 template <Wavelet::Wavelet TMotherWaveletOperator, class TPixel, unsigned int VDimension, class TAllocator>
87 {
88  const unsigned int length = coeff.size();
89 
90  CoefficientVector highPassCoeff(length + 2);
91 
92  double sign = -1;
93  for (unsigned int i = 0; i < length; ++i)
94  {
95  highPassCoeff[i] = sign * coeff[i];
96  sign *= -1.;
97  }
98  highPassCoeff[length] = 0.;
99  highPassCoeff[length + 1] = 0.;
100 
101  coeff = highPassCoeff;
102 
103  // Note that the 0.0 value is obtained by affectation and not by
104  // computation. It is fine to do an == comparison
105  while ((coeff[0] == coeff[coeff.size() - 1]) && (coeff[0] == 0.0))
106  {
107  ReduceFilterLength(coeff);
108  }
109 }
110 
111 template <Wavelet::Wavelet TMotherWaveletOperator, class TPixel, unsigned int VDimension, class TAllocator>
113 {
114  const unsigned int length = coeff.size();
115 
116  CoefficientVector highPassCoeff(length + 2);
117 
118  double sign = 1;
119  for (unsigned int i = 0; i < length; ++i)
120  {
121  highPassCoeff[i] = sign * coeff[i];
122  sign *= -1.;
123  }
124  highPassCoeff[length] = 0.;
125  highPassCoeff[length + 1] = 0.;
126 
127  coeff = highPassCoeff;
128 
129  // Note that the 0.0 value is obtained by affectation and not by
130  // computation. It is fine to do an == comparison
131  while ((coeff[0] == coeff[coeff.size() - 1]) && (coeff[0] == 0.0))
132  {
133  assert(coeff.size() > 1);
134  ReduceFilterLength(coeff);
135  }
136 }
137 
138 template <Wavelet::Wavelet TMotherWaveletOperator, class TPixel, unsigned int VDimension, class TAllocator>
140 {
141  assert(coeff.size() >= 2);
142  coeff.pop_back();
143  coeff.erase(coeff.begin());
144 }
145 
146 } // end of namespace otb
147 
148 #endif
otbWaveletOperatorBase.h
otb::WaveletOperatorBase::RevertFilter
void RevertFilter(CoefficientVector &coeff)
Definition: otbWaveletOperatorBase.hxx:69
otb::WaveletOperatorBase::GenerateInverseHighPassFilterFromLowPassFilter
void GenerateInverseHighPassFilterFromLowPassFilter(CoefficientVector &coeff)
Definition: otbWaveletOperatorBase.hxx:86
otb::WaveletOperatorBase::UpSamplingCoefficients
void UpSamplingCoefficients(CoefficientVector &coeff)
Definition: otbWaveletOperatorBase.hxx:48
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::WaveletOperatorBase::GenerateInverseLowPassFilterFromHighPassFilter
void GenerateInverseLowPassFilterFromHighPassFilter(CoefficientVector &coeff)
Definition: otbWaveletOperatorBase.hxx:112
otb::WaveletOperatorBase::ReduceFilterLength
void ReduceFilterLength(CoefficientVector &coeff)
Definition: otbWaveletOperatorBase.hxx:139
otb::WaveletOperatorBase< TMotherWaveletOperator, TPixel, VDimension, itk::NeighborhoodAllocator< TPixel > >::CoefficientVector
Superclass::CoefficientVector CoefficientVector
Definition: otbWaveletOperatorBase.h:153
otb::WaveletOperatorBase::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent i) const override
Definition: otbWaveletOperatorBase.hxx:34