OTB  6.7.0
Orfeo Toolbox
otbWaveletTransform.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 otbWaveletTransform_hxx
24 #define otbWaveletTransform_hxx
25 #include "otbWaveletTransform.h"
26 
27 #include "itkImageRegionIterator.h"
28 #include "itkProgressAccumulator.h"
29 #include "otbMacro.h"
30 
31 namespace otb {
32 
37 template <class TInputImage, class TOutputImage, class TFilter>
40  : m_NumberOfDecompositions(1), m_SubsampleImageFactor(2)
41 {
45  this->SetNthOutput(0, OutputImageListType::New());
46 
47  m_FilterList = FilterListType::New();
48 }
49 
50 template <class TInputImage, class TOutputImage, class TFilter>
51 void
54 {
56  progress->SetMiniPipelineFilter(this);
57 
58  GetFilterList()->Resize(GetNumberOfDecompositions());
59 
60  this->GetFilterList()->SetNthElement(0, FilterType::New());
61  FilterPointerType filter = this->GetFilterList()->GetNthElement(0); //GetNthFilter( 0 );
62  filter->SetInput(this->GetInput());
63  filter->SetSubsampleImageFactor(GetSubsampleImageFactor());
64 
65  otbMsgDevMacro(<<"Allocating " << (1 + GetNumberOfDecompositions() * (filter->GetNumberOfOutputs() - 1)) << " output\n");
66  this->GetOutput()->Resize(
67  1 + GetNumberOfDecompositions() * (filter->GetNumberOfOutputs() - 1));
68 
69  otbMsgDevMacro(<<"Using " << this->GetOutput()->Size() << " outputs...");
70  for (unsigned int idx = 0; idx < this->GetOutput()->Size(); ++idx)
71  {
72  this->GetOutput()->SetNthElement(idx, OutputImageType::New());
73  }
74 
75  progress->RegisterInternalFilter(filter,
76  1.f / static_cast<float>(GetNumberOfDecompositions()));
77 
78  filter->Update();
79 
80  for (unsigned int idx = 1; idx < filter->GetNumberOfOutputs(); ++idx)
81  {
82  this->GetOutput()->SetNthElement(
83  this->GetOutput()->Size() - filter->GetNumberOfOutputs() + idx,
84  filter->GetOutput(idx));
85  }
86 
87  for (unsigned int nbDecomp = 1; nbDecomp < GetNumberOfDecompositions(); nbDecomp++)
88  {
89  this->GetFilterList()->SetNthElement(nbDecomp, FilterType::New());
90  filter = this->GetFilterList()->GetNthElement(nbDecomp); //this->GetNthFilter( nbDecomp );
91  filter->SetInput(this->GetNthFilter(nbDecomp - 1)->GetOutput(0));
92  filter->SetSubsampleImageFactor(GetSubsampleImageFactor());
93  if (GetSubsampleImageFactor() == 1) filter->SetUpSampleFilterFactor(nbDecomp + 1);
94 
95  progress->RegisterInternalFilter(filter,
96  1.f / static_cast<float>(GetNumberOfDecompositions()));
97  filter->Update();
98 
99  for (unsigned int idx = 1; idx < filter->GetNumberOfOutputs(); ++idx)
100  {
101  this->GetOutput()->SetNthElement(
102  this->GetOutput()->Size() - 1 - (nbDecomp + 1) * (filter->GetNumberOfOutputs() - 1) + idx,
103  filter->GetOutput(idx));
104  }
105  }
106 
107  this->GetOutput()->SetNthElement(0, filter->GetOutput(0));
108 }
109 
114 template <class TInputImage, class TOutputImage, class TFilter>
117  : m_NumberOfDecompositions(1), m_SubsampleImageFactor(2)
118 {
119  this->SetNumberOfRequiredInputs(1);
120  this->SetNumberOfRequiredInputs(1);
122  this->SetNthOutput(0, OutputImageType::New());
123 
124  m_FilterList = FilterListType::New();
125 }
126 
127 template <class TInputImage, class TOutputImage, class TFilter>
128 void
131 {
132  this->GetOutput()->CopyInformation(this->GetInput()->GetNthElement(0));
133 
134  if (GetSubsampleImageFactor() != 1)
135  {
136  InputImageRegionType inputRegion = this->GetInput()->GetNthElement(0)->GetLargestPossibleRegion();
137  SizeType inputSize = inputRegion.GetSize();
138  IndexType inputIndex = inputRegion.GetIndex();
139 
140  OutputImageSizeType outputSize;
141  OutputImageIndexType outputIndex;
142 
143  for (unsigned int i = 0; i < InputImageDimension; ++i)
144  {
145  outputIndex[i] = inputIndex[i] * GetSubsampleImageFactor() * GetNumberOfDecompositions();
146  outputSize[i] = inputSize[i] * GetSubsampleImageFactor() * GetNumberOfDecompositions();
147  }
148 
149  OutputImageRegionType outputRegion;
150  outputRegion.SetIndex(outputIndex);
151  outputRegion.SetSize(outputSize);
152 
153  this->GetOutput()->SetRegions(outputRegion);
154  }
155 }
156 
157 template <class TInputImage, class TOutputImage, class TFilter>
158 void
161 {
162  FilterPointerType filter = FilterType::New();
163 
164  const unsigned int filterbankInputSize = 1 << InputImageDimension;
165 
166  m_NumberOfDecompositions = (this->GetInput()->Size() - 1)/(filterbankInputSize - 1);
167 
168  otbMsgDevMacro(<< "Found " << m_NumberOfDecompositions << " decompositions");
169 
171  progress->SetMiniPipelineFilter(this);
172 
173  this->GetFilterList()->Resize(GetNumberOfDecompositions());
174 
175  InputImageIterator inputIterator = this->GetInput()->Begin();
176 
177  this->GetFilterList()->SetNthElement(0, FilterType::New());
178  filter = this->GetNthFilter(0);
179  for (unsigned int i = 0; i < filterbankInputSize; ++i)
180  {
181  filter->SetInput(i, inputIterator.Get());
182  ++inputIterator;
183  }
184 
185  filter->SetSubsampleImageFactor(GetSubsampleImageFactor());
186  if (GetSubsampleImageFactor() == 1)
187  {
188  filter->SetUpSampleFilterFactor(GetNumberOfDecompositions());
189  }
190 
191  progress->RegisterInternalFilter(filter,
192  1.f / static_cast<float>(GetNumberOfDecompositions()));
193  filter->Update();
194 
195  for (unsigned int idx = 1; idx < GetNumberOfDecompositions(); ++idx)
196  {
197  this->GetFilterList()->SetNthElement(idx, FilterType::New());
198  filter = this->GetNthFilter(idx);
199  filter->SetInput(0, this->GetNthFilter(idx - 1)->GetOutput());
200 
201  for (unsigned int i = 1; i < filterbankInputSize; ++i)
202  {
203  filter->SetInput(i, inputIterator.Get());
204  ++inputIterator;
205  }
206 
207  filter->SetSubsampleImageFactor(GetSubsampleImageFactor());
208  if (GetSubsampleImageFactor() == 1)
209  {
210  filter->SetUpSampleFilterFactor(GetNumberOfDecompositions() - idx);
211  }
212 
213  progress->RegisterInternalFilter(filter,
214  1.f / static_cast<float>(GetNumberOfDecompositions()));
215  filter->Update();
216  }
217 
218  // This step is necessary to transtype output image to the wanted format
219  this->GetOutput()->CopyInformation(filter->GetOutput());
220  this->GetOutput()->SetRegions(filter->GetOutput()->GetLargestPossibleRegion());
221  this->GetOutput()->Allocate();
222  this->GetOutput()->FillBuffer(0);
223 
225  (this->GetOutput(), this->GetOutput()->GetLargestPossibleRegion());
227  (filter->GetOutput(), filter->GetOutput()->GetLargestPossibleRegion());
228 
229  for (outputIter.GoToBegin(), outFltIter.GoToBegin(); !outputIter.IsAtEnd(); ++outputIter, ++outFltIter)
230  {
231  outputIter.Set(static_cast<OutputValueType>(outFltIter.Get()));
232  }
233 }
234 
235 } // end of namespace otb
236 
237 #endif
virtual void SetNumberOfRequiredInputs(DataObjectPointerArraySizeType)
virtual void SetNumberOfRequiredOutputs(DataObjectPointerArraySizeType _arg)
void Set(const PixelType &value) const
virtual void GenerateData() override
static Pointer New()
InputImageType::SizeType SizeType
virtual void GenerateOutputInformation()
OutputImageType::RegionType OutputImageRegionType
bool IsAtEnd(void) const
virtual void SetNthOutput(DataObjectPointerArraySizeType num, DataObject *output)
InputImageType::RegionType InputImageRegionType
#define otbMsgDevMacro(x)
Definition: otbMacro.h:66