23 #ifndef otbWaveletTransform_hxx
24 #define otbWaveletTransform_hxx
27 #include "itkImageRegionIterator.h"
28 #include "itkProgressAccumulator.h"
38 template <
class TInputImage,
class TOutputImage,
class TFilter>
41 this->SetNumberOfRequiredInputs(1);
42 this->SetNumberOfRequiredInputs(1);
43 this->SetNumberOfRequiredOutputs(1);
44 this->SetNthOutput(0, OutputImageListType::New());
46 m_FilterList = FilterListType::New();
49 template <
class TInputImage,
class TOutputImage,
class TFilter>
52 itk::ProgressAccumulator::Pointer progress = itk::ProgressAccumulator::New();
53 progress->SetMiniPipelineFilter(
this);
55 GetFilterList()->Resize(GetNumberOfDecompositions());
57 this->GetFilterList()->SetNthElement(0, FilterType::New());
59 filter->SetInput(this->GetInput());
60 filter->SetSubsampleImageFactor(GetSubsampleImageFactor());
62 otbMsgDevMacro(<<
"Allocating " << (1 + GetNumberOfDecompositions() * (filter->GetNumberOfOutputs() - 1)) <<
" output\n");
63 this->GetOutput()->Resize(1 + GetNumberOfDecompositions() * (filter->GetNumberOfOutputs() - 1));
65 otbMsgDevMacro(<<
"Using " << this->GetOutput()->Size() <<
" outputs...");
66 for (
unsigned int idx = 0; idx < this->GetOutput()->Size(); ++idx)
68 this->GetOutput()->SetNthElement(idx, OutputImageType::New());
71 progress->RegisterInternalFilter(filter, 1.f /
static_cast<float>(GetNumberOfDecompositions()));
75 for (
unsigned int idx = 1; idx < filter->GetNumberOfOutputs(); ++idx)
77 this->GetOutput()->SetNthElement(this->GetOutput()->Size() - filter->GetNumberOfOutputs() + idx, filter->GetOutput(idx));
80 for (
unsigned int nbDecomp = 1; nbDecomp < GetNumberOfDecompositions(); nbDecomp++)
82 this->GetFilterList()->SetNthElement(nbDecomp, FilterType::New());
83 filter = this->GetFilterList()->GetNthElement(nbDecomp);
84 filter->SetInput(this->GetNthFilter(nbDecomp - 1)->GetOutput(0));
85 filter->SetSubsampleImageFactor(GetSubsampleImageFactor());
86 if (GetSubsampleImageFactor() == 1)
87 filter->SetUpSampleFilterFactor(nbDecomp + 1);
89 progress->RegisterInternalFilter(filter, 1.f /
static_cast<float>(GetNumberOfDecompositions()));
92 for (
unsigned int idx = 1; idx < filter->GetNumberOfOutputs(); ++idx)
94 this->GetOutput()->SetNthElement(this->GetOutput()->Size() - 1 - (nbDecomp + 1) * (filter->GetNumberOfOutputs() - 1) + idx, filter->GetOutput(idx));
98 this->GetOutput()->SetNthElement(0, filter->GetOutput(0));
105 template <
class TInputImage,
class TOutputImage,
class TFilter>
108 this->SetNumberOfRequiredInputs(1);
109 this->SetNumberOfRequiredInputs(1);
110 this->SetNumberOfRequiredOutputs(1);
111 this->SetNthOutput(0, OutputImageType::New());
113 m_FilterList = FilterListType::New();
116 template <
class TInputImage,
class TOutputImage,
class TFilter>
119 this->GetOutput()->CopyInformation(this->GetInput()->GetNthElement(0));
121 if (GetSubsampleImageFactor() != 1)
123 InputImageRegionType inputRegion = this->GetInput()->GetNthElement(0)->GetLargestPossibleRegion();
124 SizeType inputSize = inputRegion.GetSize();
125 IndexType inputIndex = inputRegion.GetIndex();
130 for (
unsigned int i = 0; i < InputImageDimension; ++i)
132 outputIndex[i] = inputIndex[i] * GetSubsampleImageFactor() * GetNumberOfDecompositions();
133 outputSize[i] = inputSize[i] * GetSubsampleImageFactor() * GetNumberOfDecompositions();
137 outputRegion.SetIndex(outputIndex);
138 outputRegion.SetSize(outputSize);
140 this->GetOutput()->SetRegions(outputRegion);
144 template <
class TInputImage,
class TOutputImage,
class TFilter>
149 const unsigned int filterbankInputSize = 1 << InputImageDimension;
151 m_NumberOfDecompositions = (this->GetInput()->Size() - 1) / (filterbankInputSize - 1);
153 otbMsgDevMacro(<<
"Found " << m_NumberOfDecompositions <<
" decompositions");
155 itk::ProgressAccumulator::Pointer progress = itk::ProgressAccumulator::New();
156 progress->SetMiniPipelineFilter(
this);
158 this->GetFilterList()->Resize(GetNumberOfDecompositions());
162 this->GetFilterList()->SetNthElement(0, FilterType::New());
163 filter = this->GetNthFilter(0);
164 for (
unsigned int i = 0; i < filterbankInputSize; ++i)
166 filter->SetInput(i, inputIterator.Get());
170 filter->SetSubsampleImageFactor(GetSubsampleImageFactor());
171 if (GetSubsampleImageFactor() == 1)
173 filter->SetUpSampleFilterFactor(GetNumberOfDecompositions());
176 progress->RegisterInternalFilter(filter, 1.f /
static_cast<float>(GetNumberOfDecompositions()));
179 for (
unsigned int idx = 1; idx < GetNumberOfDecompositions(); ++idx)
181 this->GetFilterList()->SetNthElement(idx, FilterType::New());
182 filter = this->GetNthFilter(idx);
183 filter->SetInput(0, this->GetNthFilter(idx - 1)->GetOutput());
185 for (
unsigned int i = 1; i < filterbankInputSize; ++i)
187 filter->SetInput(i, inputIterator.Get());
191 filter->SetSubsampleImageFactor(GetSubsampleImageFactor());
192 if (GetSubsampleImageFactor() == 1)
194 filter->SetUpSampleFilterFactor(GetNumberOfDecompositions() - idx);
197 progress->RegisterInternalFilter(filter, 1.f /
static_cast<float>(GetNumberOfDecompositions()));
202 this->GetOutput()->CopyInformation(filter->GetOutput());
203 this->GetOutput()->SetRegions(filter->GetOutput()->GetLargestPossibleRegion());
204 this->GetOutput()->Allocate();
205 this->GetOutput()->FillBuffer(0);
207 itk::ImageRegionIterator<OutputImageType> outputIter(this->GetOutput(), this->GetOutput()->GetLargestPossibleRegion());
208 itk::ImageRegionConstIterator<typename FilterType::OutputImageType> outFltIter(filter->GetOutput(), filter->GetOutput()->GetLargestPossibleRegion());
210 for (outputIter.GoToBegin(), outFltIter.GoToBegin(); !outputIter.IsAtEnd(); ++outputIter, ++outFltIter)