OTB  9.0.0
Orfeo Toolbox
otbWaveletTransform.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 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 {
33 
38 template <class TInputImage, class TOutputImage, class TFilter>
39 WaveletTransform<TInputImage, TOutputImage, TFilter, Wavelet::FORWARD>::WaveletTransform() : m_NumberOfDecompositions(1), m_SubsampleImageFactor(2)
40 {
41  this->SetNumberOfRequiredInputs(1);
42  this->SetNumberOfRequiredInputs(1);
43  this->SetNumberOfRequiredOutputs(1);
44  this->SetNthOutput(0, OutputImageListType::New());
45 
46  m_FilterList = FilterListType::New();
47 }
48 
49 template <class TInputImage, class TOutputImage, class TFilter>
51 {
52  itk::ProgressAccumulator::Pointer progress = itk::ProgressAccumulator::New();
53  progress->SetMiniPipelineFilter(this);
54 
55  GetFilterList()->Resize(GetNumberOfDecompositions());
56 
57  this->GetFilterList()->SetNthElement(0, FilterType::New());
58  FilterPointerType filter = this->GetFilterList()->GetNthElement(0); // GetNthFilter( 0 );
59  filter->SetInput(this->GetInput());
60  filter->SetSubsampleImageFactor(GetSubsampleImageFactor());
61 
62  otbMsgDevMacro(<< "Allocating " << (1 + GetNumberOfDecompositions() * (filter->GetNumberOfOutputs() - 1)) << " output\n");
63  this->GetOutput()->Resize(1 + GetNumberOfDecompositions() * (filter->GetNumberOfOutputs() - 1));
64 
65  otbMsgDevMacro(<< "Using " << this->GetOutput()->Size() << " outputs...");
66  for (unsigned int idx = 0; idx < this->GetOutput()->Size(); ++idx)
67  {
68  this->GetOutput()->SetNthElement(idx, OutputImageType::New());
69  }
70 
71  progress->RegisterInternalFilter(filter, 1.f / static_cast<float>(GetNumberOfDecompositions()));
72 
73  filter->Update();
74 
75  for (unsigned int idx = 1; idx < filter->GetNumberOfOutputs(); ++idx)
76  {
77  this->GetOutput()->SetNthElement(this->GetOutput()->Size() - filter->GetNumberOfOutputs() + idx, filter->GetOutput(idx));
78  }
79 
80  for (unsigned int nbDecomp = 1; nbDecomp < GetNumberOfDecompositions(); nbDecomp++)
81  {
82  this->GetFilterList()->SetNthElement(nbDecomp, FilterType::New());
83  filter = this->GetFilterList()->GetNthElement(nbDecomp); // this->GetNthFilter( nbDecomp );
84  filter->SetInput(this->GetNthFilter(nbDecomp - 1)->GetOutput(0));
85  filter->SetSubsampleImageFactor(GetSubsampleImageFactor());
86  if (GetSubsampleImageFactor() == 1)
87  filter->SetUpSampleFilterFactor(nbDecomp + 1);
88 
89  progress->RegisterInternalFilter(filter, 1.f / static_cast<float>(GetNumberOfDecompositions()));
90  filter->Update();
91 
92  for (unsigned int idx = 1; idx < filter->GetNumberOfOutputs(); ++idx)
93  {
94  this->GetOutput()->SetNthElement(this->GetOutput()->Size() - 1 - (nbDecomp + 1) * (filter->GetNumberOfOutputs() - 1) + idx, filter->GetOutput(idx));
95  }
96  }
97 
98  this->GetOutput()->SetNthElement(0, filter->GetOutput(0));
99 }
100 
105 template <class TInputImage, class TOutputImage, class TFilter>
107 {
108  this->SetNumberOfRequiredInputs(1);
109  this->SetNumberOfRequiredInputs(1);
110  this->SetNumberOfRequiredOutputs(1);
111  this->SetNthOutput(0, OutputImageType::New());
112 
113  m_FilterList = FilterListType::New();
114 }
115 
116 template <class TInputImage, class TOutputImage, class TFilter>
118 {
119  this->GetOutput()->CopyInformation(this->GetInput()->GetNthElement(0));
120 
121  if (GetSubsampleImageFactor() != 1)
122  {
123  InputImageRegionType inputRegion = this->GetInput()->GetNthElement(0)->GetLargestPossibleRegion();
124  SizeType inputSize = inputRegion.GetSize();
125  IndexType inputIndex = inputRegion.GetIndex();
126 
127  OutputImageSizeType outputSize;
128  OutputImageIndexType outputIndex;
129 
130  for (unsigned int i = 0; i < InputImageDimension; ++i)
131  {
132  outputIndex[i] = inputIndex[i] * GetSubsampleImageFactor() * GetNumberOfDecompositions();
133  outputSize[i] = inputSize[i] * GetSubsampleImageFactor() * GetNumberOfDecompositions();
134  }
135 
136  OutputImageRegionType outputRegion;
137  outputRegion.SetIndex(outputIndex);
138  outputRegion.SetSize(outputSize);
139 
140  this->GetOutput()->SetRegions(outputRegion);
141  }
142 }
143 
144 template <class TInputImage, class TOutputImage, class TFilter>
146 {
147  FilterPointerType filter = FilterType::New();
148 
149  const unsigned int filterbankInputSize = 1 << InputImageDimension;
150 
151  m_NumberOfDecompositions = (this->GetInput()->Size() - 1) / (filterbankInputSize - 1);
152 
153  otbMsgDevMacro(<< "Found " << m_NumberOfDecompositions << " decompositions");
154 
155  itk::ProgressAccumulator::Pointer progress = itk::ProgressAccumulator::New();
156  progress->SetMiniPipelineFilter(this);
157 
158  this->GetFilterList()->Resize(GetNumberOfDecompositions());
159 
160  InputImageIterator inputIterator = this->GetInput()->Begin();
161 
162  this->GetFilterList()->SetNthElement(0, FilterType::New());
163  filter = this->GetNthFilter(0);
164  for (unsigned int i = 0; i < filterbankInputSize; ++i)
165  {
166  filter->SetInput(i, inputIterator.Get());
167  ++inputIterator;
168  }
169 
170  filter->SetSubsampleImageFactor(GetSubsampleImageFactor());
171  if (GetSubsampleImageFactor() == 1)
172  {
173  filter->SetUpSampleFilterFactor(GetNumberOfDecompositions());
174  }
175 
176  progress->RegisterInternalFilter(filter, 1.f / static_cast<float>(GetNumberOfDecompositions()));
177  filter->Update();
178 
179  for (unsigned int idx = 1; idx < GetNumberOfDecompositions(); ++idx)
180  {
181  this->GetFilterList()->SetNthElement(idx, FilterType::New());
182  filter = this->GetNthFilter(idx);
183  filter->SetInput(0, this->GetNthFilter(idx - 1)->GetOutput());
184 
185  for (unsigned int i = 1; i < filterbankInputSize; ++i)
186  {
187  filter->SetInput(i, inputIterator.Get());
188  ++inputIterator;
189  }
190 
191  filter->SetSubsampleImageFactor(GetSubsampleImageFactor());
192  if (GetSubsampleImageFactor() == 1)
193  {
194  filter->SetUpSampleFilterFactor(GetNumberOfDecompositions() - idx);
195  }
196 
197  progress->RegisterInternalFilter(filter, 1.f / static_cast<float>(GetNumberOfDecompositions()));
198  filter->Update();
199  }
200 
201  // This step is necessary to transtype output image to the wanted format
202  this->GetOutput()->CopyInformation(filter->GetOutput());
203  this->GetOutput()->SetRegions(filter->GetOutput()->GetLargestPossibleRegion());
204  this->GetOutput()->Allocate();
205  this->GetOutput()->FillBuffer(0);
206 
207  itk::ImageRegionIterator<OutputImageType> outputIter(this->GetOutput(), this->GetOutput()->GetLargestPossibleRegion());
208  itk::ImageRegionConstIterator<typename FilterType::OutputImageType> outFltIter(filter->GetOutput(), filter->GetOutput()->GetLargestPossibleRegion());
209 
210  for (outputIter.GoToBegin(), outFltIter.GoToBegin(); !outputIter.IsAtEnd(); ++outputIter, ++outFltIter)
211  {
212  outputIter.Set(static_cast<OutputValueType>(outFltIter.Get()));
213  }
214 }
215 
216 } // end of namespace otb
217 
218 #endif
otbWaveletTransform.h
otb::WaveletTransform< TInputImage, TOutputImage, TFilter, Wavelet::INVERSE >::IndexType
InputImageType::IndexType IndexType
Definition: otbWaveletTransform.h:257
otb::WaveletTransform< TInputImage, TOutputImage, TFilter, Wavelet::INVERSE >::OutputImageIndexType
OutputImageType::IndexType OutputImageIndexType
Definition: otbWaveletTransform.h:268
otb::WaveletTransform
Wavelet transformation framework.
Definition: otbWaveletTransform.h:58
otb::WaveletTransform< TInputImage, TOutputImage, TFilter, Wavelet::INVERSE >::OutputValueType
OutputImageType::ValueType OutputValueType
Definition: otbWaveletTransform.h:269
otb::WaveletTransform< TInputImage, TOutputImage, TFilter, Wavelet::FORWARD >::FilterPointerType
FilterType::Pointer FilterPointerType
Definition: otbWaveletTransform.h:139
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbMacro.h
otb::WaveletTransform::WaveletTransform
WaveletTransform()
otb::ImageListToImageFilter::InputImageRegionType
InputImageType::RegionType InputImageRegionType
Definition: otbImageListToImageFilter.h:58
otb::ImageListToImageFilter::SizeType
InputImageType::SizeType SizeType
Definition: otbImageListToImageFilter.h:60
otb::WaveletTransform< TInputImage, TOutputImage, TFilter, Wavelet::INVERSE >::OutputImageSizeType
OutputImageType::SizeType OutputImageSizeType
Definition: otbWaveletTransform.h:267
otb::WaveletTransform< TInputImage, TOutputImage, TFilter, Wavelet::INVERSE >::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbWaveletTransform.h:266
otb::WaveletTransform< TInputImage, TOutputImage, TFilter, Wavelet::INVERSE >::FilterPointerType
FilterType::Pointer FilterPointerType
Definition: otbWaveletTransform.h:272
otbMsgDevMacro
#define otbMsgDevMacro(x)
Definition: otbMacro.h:64
otb::WaveletTransform< TInputImage, TOutputImage, TFilter, Wavelet::INVERSE >::InputImageIterator
InputImageListType::Iterator InputImageIterator
Definition: otbWaveletTransform.h:262