23 #ifndef otbWaveletPacketTransform_hxx
24 #define otbWaveletPacketTransform_hxx
35 template <
class TInputImage,
class TOutputImage,
class TFilter,
class TCost>
37 : m_SubsampleImageFactor(2), m_NumberOfFilters(0), m_DepthOfDecomposition(0)
39 this->SetNumberOfRequiredInputs(1);
40 this->SetNumberOfRequiredOutputs(1);
41 this->SetNthOutput(0, OutputImageListType::New());
43 m_FilterList = FilterListType::New();
44 m_Cost = CostType::New();
47 template <
class TInputImage,
class TOutputImage,
class TFilter,
class TCost>
54 m_WaveletPacketRule.clear();
56 m_NumberOfFilters = 0;
57 m_DepthOfDecomposition = 0;
59 itk::ProgressAccumulator::Pointer progress = itk::ProgressAccumulator::New();
60 progress->SetMiniPipelineFilter(
this);
62 GenerateData(0, this->GetInput(), progress);
65 template <
class TInputImage,
class TOutputImage,
class TFilter,
class TCost>
67 itk::ProgressAccumulator* progress)
71 static float accumulatorWeight = 1.;
73 if (this->GetCost()->Evaluate(depth, outputPtr))
75 if (m_DepthOfDecomposition < depth)
76 m_DepthOfDecomposition = depth;
78 m_WaveletPacketRule.push_back(
true);
80 this->GetFilterList()->PushBack(FilterType::New());
81 FilterPointerType filter = this->GetFilterList()->GetNthElement(m_NumberOfFilters);
85 filter->SetSubsampleImageFactor(GetSubsampleImageFactor());
86 if (GetSubsampleImageFactor() == 1)
87 filter->SetUpSampleFilterFactor(depth);
89 accumulatorWeight /= 2.;
90 progress->RegisterInternalFilter(filter, accumulatorWeight);
91 filter->SetInput(outputPtr);
95 for (
unsigned int idx = 0; idx < filter->GetNumberOfOutputs(); ++idx)
97 GenerateData(depth + 1, filter->GetOutput(idx), progress);
102 m_WaveletPacketRule.push_back(
false);
103 this->GetOutput()->PushBack(outputPtr);
111 template <
class TInputImage,
class TOutputImage,
class TFilter>
113 : m_SubsampleImageFactor(2), m_NumberOfFilters(0), m_DepthOfDecomposition(0)
115 this->SetNumberOfRequiredInputs(1);
116 this->SetNumberOfRequiredOutputs(1);
117 this->SetNthOutput(0, OutputImageType::New());
119 m_FilterList = FilterListType::New();
122 template <
class TInputImage,
class TOutputImage,
class TFilter>
125 if (m_NumberOfFilters == 0)
128 this->GetOutput()->CopyInformation(this->GetInput()->GetNthElement(0));
130 InputImageRegionType inputRegion = this->GetInput()->GetNthElement(0)->GetLargestPossibleRegion();
131 SizeType inputSize = inputRegion.GetSize();
132 IndexType inputIndex = inputRegion.GetIndex();
137 for (
unsigned int i = 0; i < InputImageDimension; ++i)
139 outputIndex[i] = inputIndex[i] * GetSubsampleImageFactor() * GetDepthOfDecomposition();
140 outputSize[i] = inputSize[i] * GetSubsampleImageFactor() * GetDepthOfDecomposition();
143 otbMsgDevMacro(<<
"Output Size [" << outputSize[0] <<
"," << outputSize[1] <<
"]");
146 outputRegion.SetIndex(outputIndex);
147 outputRegion.SetSize(outputSize);
148 this->GetOutput()->SetRegions(outputRegion);
151 template <
class TInputImage,
class TOutputImage,
class TFilter>
154 if (m_WaveletPacketRule[0] !=
true)
156 throw itk::ExceptionObject(__FILE__, __LINE__,
"No decomposition to perform in Generic data... Check WaveletPacketRule tab", ITK_LOCATION);
159 if (m_NumberOfFilters == 0)
166 if (m_NumberOfFilters == 0)
168 throw itk::ExceptionObject(__FILE__, __LINE__,
"No filter found in the decomposition tree... Check WaveletPacketRule tab", ITK_LOCATION);
173 unsigned int pos = 1;
174 SetInputFilters(pos, inputIterator, 0);
176 if (pos != m_WaveletPacketRule.size() || inputIterator != this->GetInput()->End())
178 throw itk::ExceptionObject(__FILE__, __LINE__,
"Bad decomposition tree implementation...", ITK_LOCATION);
181 m_FilterList->GetNthElement(0)->GraftOutput(this->GetOutput());
183 itk::ProgressAccumulator::Pointer progress = itk::ProgressAccumulator::New();
184 progress->SetMiniPipelineFilter(
this);
186 for (pos = m_NumberOfFilters; pos > 0; pos--)
189 progress->RegisterInternalFilter(filter, 1.f /
static_cast<float>(m_NumberOfFilters));
193 this->GraftOutput(m_FilterList->GetNthElement(0)->GetOutput());
196 template <
class TInputImage,
class TOutputImage,
class TFilter>
200 unsigned int nextFilterID = filterID + 1;
202 if (ruleID == m_WaveletPacketRule.size())
203 return m_FilterList->Size();
205 const unsigned int filterBankInputSize = 1 << InputImageDimension;
207 for (
unsigned int i = 0; i < filterBankInputSize; ++i)
209 if (m_WaveletPacketRule[ruleID++] ==
true)
211 m_FilterList->GetNthElement(filterID)->SetInput(i, m_FilterList->GetNthElement(nextFilterID)->GetOutput());
212 nextFilterID = SetInputFilters(ruleID, imgIt, nextFilterID);
216 m_FilterList->GetNthElement(filterID)->SetInput(i, imgIt.Get());
224 template <
class TInputImage,
class TOutputImage,
class TFilter>
227 if (m_FilterList && m_FilterList->Size() != 0)
229 if (m_NumberOfFilters != 0)
230 itkExceptionMacro(<<
"Incoherency between member value");
233 m_NumberOfFilters = 0;
234 m_DepthOfDecomposition = 0;
236 for (
unsigned int posRule = 0; posRule < m_WaveletPacketRule.size(); posRule++)
237 InterpretRule(posRule, 0);
240 template <
class TInputImage,
class TOutputImage,
class TFilter>
242 unsigned int& ruleID,
unsigned int curDepth)
244 if (curDepth > m_DepthOfDecomposition)
245 m_DepthOfDecomposition = curDepth;
247 if (m_WaveletPacketRule[ruleID] ==
true)
249 m_FilterList->PushBack(FilterType::New());
252 filter->SetSubsampleImageFactor(GetSubsampleImageFactor());
253 if (GetSubsampleImageFactor() == 1)
254 filter->SetUpSampleFilterFactor(curDepth);
258 const unsigned int filterBankInputSize = 1 << InputImageDimension;
260 for (
unsigned int i = 0; i < filterBankInputSize; ++i)
263 InterpretRule(ruleID, curDepth + 1);