OTB  6.7.0
Orfeo Toolbox
otbGeodesicMorphologyDecompositionImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbGeodesicMorphologyDecompositionImageFilter_hxx
22 #define otbGeodesicMorphologyDecompositionImageFilter_hxx
23 
25 
26 namespace otb
27 {
31 template <class TInputImage, class TOutputImage, class TStructuringElement>
34 {
35  this->SetNumberOfRequiredOutputs(3);
36  this->SetNthOutput(0, OutputImageType::New());
37  this->SetNthOutput(1, OutputImageType::New());
38  this->SetNthOutput(2, OutputImageType::New());
40 
41  m_Radius.Fill(1);
42 
43  // Create a process accumulator for tracking the progress of minipipeline
44  m_Progress = itk::ProgressAccumulator::New();
45  m_Progress->SetMiniPipelineFilter(this);
46 
47  m_OpeningFilter = OpeningFilterType::New();
48  m_ClosingFilter = ClosingFilterType::New();
49  m_LevelingFilter = LevelingFilterType::New();
50  m_ConvexFilter = ConvexFilterType::New();
51  m_ConcaveFilter = ConcaveFilterType::New();
52 
53  // Register Internal Filter for progress
54  m_Progress->RegisterInternalFilter(m_OpeningFilter, 0.2);
55  m_Progress->RegisterInternalFilter(m_ClosingFilter, 0.2);
56  m_Progress->RegisterInternalFilter(m_LevelingFilter, 0.2);
57  m_Progress->RegisterInternalFilter(m_ConvexFilter, 0.2);
58  m_Progress->RegisterInternalFilter(m_ConcaveFilter, 0.2);
59 
60 
61  m_FullyConnected = true;
62  m_PreserveIntensities = true;
63 }
67 template <class TInputImage, class TOutputImage, class TStructuringElement>
68 void
71 {
72  StructuringElementType se;
73  se.SetRadius(m_Radius);
74  se.CreateStructuringElement();
76 
77  m_OpeningFilter->SetInput(this->GetInput());
78  m_OpeningFilter->SetKernel(se);
79  m_OpeningFilter->SetPreserveIntensities(m_PreserveIntensities);
80  m_OpeningFilter->SetFullyConnected(m_FullyConnected);
81 
82  m_ClosingFilter->SetInput(this->GetInput());
83  m_ClosingFilter->SetKernel(se);
84  m_ClosingFilter->SetPreserveIntensities(m_PreserveIntensities);
85  m_ClosingFilter->SetFullyConnected(m_FullyConnected);
86 
87  m_ConvexFilter->SetInput1(this->GetInput());
88  m_ConvexFilter->SetInput2(m_OpeningFilter->GetOutput());
89 
90  m_ConcaveFilter->SetInput1(m_ClosingFilter->GetOutput());
91  m_ConcaveFilter->SetInput2(this->GetInput());
92 
93  using namespace otb::Functor::LevelingFunctor_tags;
94  // Template keyword mandatory to avoid parsing error when using
95  // template methods within template code
96  m_LevelingFilter->template SetInput<pixel>(this->GetInput());
97  m_LevelingFilter->template SetInput<convex_pixel>(m_ConvexFilter->GetOutput());
98  m_LevelingFilter->template SetInput<concave_pixel>(m_ConcaveFilter->GetOutput());
99 
100  m_ConvexFilter->GraftOutput(this->GetConvexMap());
101  m_ConvexFilter->Update();
102  this->GraftNthOutput(1, m_ConvexFilter->GetOutput());
103 
104  m_ConcaveFilter->GraftOutput(this->GetConcaveMap());
105  m_ConcaveFilter->Update();
106  this->GraftNthOutput(2, m_ConcaveFilter->GetOutput());
107 
108  m_LevelingFilter->GraftOutput(this->GetOutput());
109  m_LevelingFilter->Update();
110  this->GraftOutput(m_LevelingFilter->GetOutput());
111 }
112 
116 template <class TInputImage, class TOutputImage, class TStructuringElement>
117 TOutputImage *
120 {
121  if (this->GetNumberOfOutputs() < 2)
122  {
123  return nullptr;
124  }
125  return static_cast<OutputImageType *>
127 }
129 
133 template <class TInputImage, class TOutputImage, class TStructuringElement>
134 TOutputImage *
137 {
138  if (this->GetNumberOfOutputs() < 3)
139  {
140  return nullptr;
141  }
142  return static_cast<OutputImageType *>
144 }
146 
static Pointer New()
DataObject * GetOutput(const DataObjectIdentifierType &key)