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