Orfeo Toolbox  4.0
otbWaveletOperatorBase.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12  Copyright (c) Institut Telecom / Telecom Bretagne. All rights reserved.
13  See ITCopyright.txt for details.
14 
15  This software is distributed WITHOUT ANY WARRANTY; without even
16  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17  PURPOSE. See the above copyright notices for more information.
18 
19 =========================================================================*/
20 
21 #ifndef __otbWaveletOperatorBase_txx
22 #define __otbWaveletOperatorBase_txx
23 
24 #include "otbWaveletOperatorBase.h"
25 
26 #include <cassert>
27 
28 namespace otb {
29 
30 template <Wavelet::Wavelet TMotherWaveletOperator,
31  class TPixel, unsigned int VDimension, class TAllocator>
32 void
34 ::PrintSelf(std::ostream& os, itk::Indent i) const
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();
41  iter != Superclass::End();
42  ++iter)
43  {
44  os << *iter << ' ';
45  }
46  os << "]\n";
47 }
48 
49 template <Wavelet::Wavelet TMotherWaveletOperator,
50  class TPixel, unsigned int VDimension, class TAllocator>
51 void
54 {
55  if (m_UpSampleFactor <= 1) return;
56 
57  unsigned long radius = static_cast<unsigned long>(coeff.size()) >> 1;
58  unsigned long upSampleRadius = radius * m_UpSampleFactor;
59 
60  CoefficientVector upSampledCoeff ( 2 * upSampleRadius + 1 );
61  upSampledCoeff.assign(2 * upSampleRadius + 1, 0.);
62  upSampledCoeff[upSampleRadius] = coeff[radius];
63 
64  for (unsigned int i = 1; i <= radius; ++i)
65  {
66  upSampledCoeff[upSampleRadius + m_UpSampleFactor * i] = coeff[radius + i];
67  upSampledCoeff[upSampleRadius - m_UpSampleFactor * i] = coeff[radius - i];
68  }
69  coeff = upSampledCoeff;
70 }
71 
72 template <Wavelet::Wavelet TMotherWaveletOperator,
73  class TPixel, unsigned int VDimension, class TAllocator>
74 void
77 {
78  const unsigned int length = coeff.size();
79  const unsigned int medianPosition = length / 2;
80 
81  CoefficientVector newCoeff(length);
82  newCoeff[medianPosition] = coeff[medianPosition];
83  for (unsigned int i = 1; i <= medianPosition; ++i)
84  {
85  newCoeff[medianPosition + i] = coeff[medianPosition - i];
86  newCoeff[medianPosition - i] = coeff[medianPosition + i];
87  }
88 
89  coeff = newCoeff;
90 }
91 
92 template <Wavelet::Wavelet TMotherWaveletOperator,
93  class TPixel, unsigned int VDimension, class TAllocator>
94 void
97 {
98  const unsigned int length = coeff.size();
99 
100  CoefficientVector highPassCoeff(length + 2);
101 
102  double sign = -1;
103  for (unsigned int i = 0; i < length; ++i)
104  {
105  highPassCoeff[i] = sign * coeff[i];
106  sign *= -1.;
107  }
108  highPassCoeff[length] = 0.;
109  highPassCoeff[length + 1] = 0.;
110 
111  coeff = highPassCoeff;
112 
113  // Note that the 0.0 value is obtained by affectation and not by
114  // computation. It is fine to do an == comparison
115  while ((coeff[0] == coeff[coeff.size() - 1]) && (coeff[0] == 0.0))
116  {
117  ReduceFilterLength(coeff);
118  }
119 }
120 
121 template <Wavelet::Wavelet TMotherWaveletOperator,
122  class TPixel, unsigned int VDimension, class TAllocator>
123 void
126 {
127  const unsigned int length = coeff.size();
128 
129  CoefficientVector highPassCoeff(length + 2);
130 
131  double sign = 1;
132  for (unsigned int i = 0; i < length; ++i)
133  {
134  highPassCoeff[i] = sign * coeff[i];
135  sign *= -1.;
136  }
137  highPassCoeff[length] = 0.;
138  highPassCoeff[length + 1] = 0.;
139 
140  coeff = highPassCoeff;
141 
142  // Note that the 0.0 value is obtained by affectation and not by
143  // computation. It is fine to do an == comparison
144  while ((coeff[0] == coeff[coeff.size() - 1]) && (coeff[0] == 0.0))
145  {
146  assert(coeff.size() > 1);
147  ReduceFilterLength(coeff);
148  }
149 }
150 
151 template <Wavelet::Wavelet TMotherWaveletOperator,
152  class TPixel, unsigned int VDimension, class TAllocator>
153 void
156 {
157  const unsigned int length = coeff.size();
158  assert(length >= 2);
159  CoefficientVector newFilter(length - 2);
160  for (unsigned int i = 0; i < newFilter.size(); ++i)
161  {
162  newFilter[i] = coeff[i + 1];
163  }
164  coeff = newFilter;
165 }
166 
167 } // end of namespace otb
168 
169 #endif

Generated at Sat Mar 8 2014 16:26:13 for Orfeo Toolbox with doxygen 1.8.3.1