18 #ifndef __otbMorphologicalPyramidAnalysisFilter_txx
19 #define __otbMorphologicalPyramidAnalysisFilter_txx
35 template <
class TInputImage,
class TOutputImage,
class TMorphoFilter>
39 this->SetNumberOfRequiredOutputs(2);
40 m_DecimationRatio = 2.0;
45 this->SetNthOutput(1, infFilter.GetPointer());
47 this->SetNthOutput(2, outputList.GetPointer());
49 this->SetNthOutput(3, supDeci.GetPointer());
51 this->SetNthOutput(4, infDeci.GetPointer());
56 template <
class TInputImage,
class TOutputImage,
class TMorphoFilter>
63 template <
class TInputImage,
class TOutputImage,
class TMorphoFilter>
65 ::OutputImageListType*
75 template <
class TInputImage,
class TOutputImage,
class TMorphoFilter>
77 ::OutputImageListType*
87 template <
class TInputImage,
class TOutputImage,
class TMorphoFilter>
89 ::OutputImageListType*
99 template <
class TInputImage,
class TOutputImage,
class TMorphoFilter>
101 ::OutputImageListType*
111 template <
class TInputImage,
class TOutputImage,
class TMorphoFilter>
113 ::OutputImageListType*
122 template <
class TInputImage,
class TOutputImage,
class TMorphoFilter>
143 typename DuplicatorType::Pointer duplicator = DuplicatorType::New();
144 duplicator->SetInputImage(this->GetInput());
145 duplicator->Update();
146 typename InputImageType::Pointer currentImage = duplicator->GetOutput();
147 typename InputImageType::Pointer upsampled;
150 const int structElementDimension =
static_cast<int>(vcl_ceil(this->GetDecimationRatio() / 2.));
154 structuringElement.SetRadius(structElementDimension);
155 structuringElement.CreateStructuringElement();
158 typename MorphoFilterType::Pointer morphoFilter;
159 typename MaxFilterType::Pointer max;
160 typename SubtractFilterType::Pointer subtract1, subtract2, subtract3, subtract4;
161 typename ResamplerType::Pointer resampler1, resampler2;
164 typename InputImageType::SizeType size;
174 while (i < this->GetNumberOfLevels())
178 morphoFilter = MorphoFilterType::New();
179 morphoFilter->SetKernel(structuringElement);
180 morphoFilter->SetInput(currentImage);
181 morphoFilter->Update();
184 max = MaxFilterType::New();
185 max->SetInput1(morphoFilter->GetOutput());
186 max->SetInput2(currentImage);
190 subtract1 = SubtractFilterType::New();
191 subtract1->SetInput1(max->GetOutput());
192 subtract1->SetInput2(morphoFilter->GetOutput());
195 <<
"MorphologicalPyramidAnalysisFilter: subtract1 OK " <<
196 subtract1->GetOutput()->GetLargestPossibleRegion().GetSize());
197 supFilter->
PushBack(subtract1->GetOutput());
198 otbMsgDevMacro(
"MorphologicalPyramidAnalysisFilter: step " << i <<
" - Image appended to SupFilter");
201 subtract2 = SubtractFilterType::New();
202 subtract2->SetInput1(max->GetOutput());
203 subtract2->SetInput2(currentImage);
206 <<
"MorphologicalPyramidAnalysisFilter: subtract2 OK " <<
207 subtract2->GetOutput()->GetLargestPossibleRegion().GetSize());
208 infFilter->
PushBack(subtract2->GetOutput());
209 otbMsgDevMacro(
"MorphologicalPyramidAnalysisFilter: step " << i <<
" - Image appended to InfFilter");
212 size = morphoFilter->GetOutput()->GetLargestPossibleRegion().GetSize();
213 for (
int j = 0; j < InputImageType::ImageDimension; ++j)
217 size[j] =
static_cast<unsigned int>(vcl_ceil((static_cast<double>(sizeTmp) / this->GetDecimationRatio()) + 0.5));
223 resampler1 = ResamplerType::New();
224 resampler1->SetInput(morphoFilter->GetOutput());
225 resampler1->SetSize(size);
226 resampler1->Update();
227 currentImage = resampler1->GetOutput();
230 <<
"MorphologicalPyramidAnalysisFilter: DownSampling OK " << currentImage->GetLargestPossibleRegion().GetSize());
232 OutputImageList->
PushBack(currentImage);
235 resampler2 = ResamplerType::New();
236 resampler2->SetInput(resampler1->GetOutput());
237 resampler2->SetSize(morphoFilter->GetOutput()->GetLargestPossibleRegion().GetSize());
238 resampler2->Update();
241 <<
"MorphologicalPyramidAnalysisFilter: UpSampling OK " <<
242 resampler2->GetOutput()->GetLargestPossibleRegion().GetSize());
244 max = MaxFilterType::New();
245 max->SetInput1(morphoFilter->GetOutput());
246 max->SetInput2(resampler2->GetOutput());
249 <<
"MorphologicalPyramidAnalysisFilter: Max OK " << max->GetOutput()->GetLargestPossibleRegion().GetSize());
252 subtract4 = SubtractFilterType::New();
253 subtract4->SetInput1(max->GetOutput());
254 subtract4->SetInput2(morphoFilter->GetOutput());
257 <<
"MorphologicalPyramidAnalysisFilter: subtract4 OK " <<
258 subtract4->GetOutput()->GetLargestPossibleRegion().GetSize());
259 infDeci->
PushBack(subtract4->GetOutput());
260 otbMsgDevMacro(
"MorphologicalPyramidAnalysisFilter: step " << i <<
" - Image appended to InfDeci");
263 subtract3 = SubtractFilterType::New();
264 subtract3->SetInput1(max->GetOutput());
265 subtract3->SetInput2(resampler2->GetOutput());
268 <<
"MorphologicalPyramidAnalysisFilter: subtract3 OK " <<
269 subtract3->GetOutput()->GetLargestPossibleRegion().GetSize());
270 supDeci->
PushBack(subtract3->GetOutput());
271 otbMsgDevMacro(
"MorphologicalPyramidAnalysisFilter: step " << i <<
" - Image appended to SupDeci");
281 template <
class TInputImage,
class TOutputImage,
class TMorphoFilter>
286 Superclass::PrintSelf(os, indent);
287 os << indent <<
"DecimationRatio: " << m_DecimationRatio << std::endl;
288 os << indent <<
"NumberOfLevels: " << m_NumberOfLevels << std::endl;