21 #ifndef otbOpeningClosingMorphologicalFilter_hxx
22 #define otbOpeningClosingMorphologicalFilter_hxx
25 #include "itkGrayscaleMorphologicalOpeningImageFilter.h"
26 #include "itkGrayscaleMorphologicalClosingImageFilter.h"
27 #include "itkProgressAccumulator.h"
34 template <
class TInputImage,
class TOutputImage,
class TKernel>
37 m_Kernel.SetRadius(1);
38 m_Kernel.CreateStructuringElement();
45 template <
class TInputImage,
class TOutputImage,
class TKernel>
49 typedef itk::GrayscaleMorphologicalOpeningImageFilter<InputImageType, OutputImageType, KernelType> OpenFilterType;
50 typedef itk::GrayscaleMorphologicalClosingImageFilter<InputImageType, OutputImageType, KernelType> CloseFilterType;
52 typename OpenFilterType::Pointer opening = OpenFilterType::New();
53 typename CloseFilterType::Pointer closing = CloseFilterType::New();
55 opening->SetKernel(this->GetKernel());
56 closing->SetKernel(this->GetKernel());
58 itk::ProgressAccumulator::Pointer progress = itk::ProgressAccumulator::New();
59 progress->SetMiniPipelineFilter(
this);
60 progress->RegisterInternalFilter(opening, .5f);
61 progress->RegisterInternalFilter(closing, .5f);
63 closing->SetInput(this->GetInput());
64 opening->SetInput(closing->GetOutput());
66 opening->GraftOutput(this->GetOutput());
68 this->GraftOutput(opening->GetOutput());