OTB  9.0.0
Orfeo Toolbox
otbGeodesicMorphologyIterativeDecompositionImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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 otbGeodesicMorphologyIterativeDecompositionImageFilter_hxx
22 #define otbGeodesicMorphologyIterativeDecompositionImageFilter_hxx
23 
25 
26 #include "itkProgressAccumulator.h"
27 #include "otbMacro.h"
28 
29 namespace otb
30 {
34 template <class TImage, class TStructuringElement>
36 {
37  // Create a process accumulator for tracking the progress of minipipeline
38  m_Progress = itk::ProgressAccumulator::New();
39  m_Progress->SetMiniPipelineFilter(this);
41 
42  this->SetNumberOfRequiredInputs(1);
43  this->SetNumberOfRequiredOutputs(3);
44  m_NumberOfIterations = 2;
45  m_InitialValue = 1;
46  m_Step = 1;
47  OutputImageListPointerType convList = OutputImageListType::New();
48  this->SetNthOutput(0, convList.GetPointer());
49  OutputImageListPointerType concList = OutputImageListType::New();
50  this->SetNthOutput(1, concList.GetPointer());
51  OutputImageListPointerType outputList = OutputImageListType::New();
52  this->SetNthOutput(2, outputList.GetPointer());
53 }
54 
55 template <class TImage, class TStructuringElement>
58 {
59  return dynamic_cast<OutputImageListType*>(this->itk::ProcessObject::GetOutput(2));
60 }
61 
62 template <class TImage, class TStructuringElement>
65 {
66  return dynamic_cast<OutputImageListType*>(this->itk::ProcessObject::GetOutput(0));
67 }
68 
69 template <class TImage, class TStructuringElement>
72 {
73  return dynamic_cast<OutputImageListType*>(this->itk::ProcessObject::GetOutput(1));
74 }
75 
76 template <class TImage, class TStructuringElement>
78 {
79  // Retrieving input/output pointers
80  InputImagePointerType inputPtr = this->GetInput();
81  OutputImageListPointerType outputPtr = this->GetOutput();
82  OutputImageListPointerType convOutputPtr = this->GetConvexOutput();
83  OutputImageListPointerType concOutputPtr = this->GetConcaveOutput();
84  if (outputPtr)
85  {
86  if (outputPtr->Size() != m_NumberOfIterations)
87  {
88  // in this case, clear the list
89  outputPtr->Clear();
90  for (unsigned int i = 0; i < m_NumberOfIterations; ++i)
91  {
92  // Create the output image
93  outputPtr->PushBack(OutputImageType::New());
94  }
95  }
96  // For each output image
97  typename OutputImageListType::Iterator outputListIt = outputPtr->Begin();
98  while (outputListIt != outputPtr->End())
99  {
100  // Set the image information
101  outputListIt.Get()->CopyInformation(this->GetInput());
102  outputListIt.Get()->SetRequestedRegion(this->GetInput()->GetLargestPossibleRegion());
103  ++outputListIt;
104  }
105  }
106  if (convOutputPtr)
107  {
108  if (convOutputPtr->Size() != m_NumberOfIterations)
109  {
110  // in this case, clear the list
111  convOutputPtr->Clear();
112  for (unsigned int i = 0; i < m_NumberOfIterations; ++i)
113  {
114  // Create the output image
115  convOutputPtr->PushBack(OutputImageType::New());
116  }
117  }
118  // For each output image
119  typename OutputImageListType::Iterator outputListIt = convOutputPtr->Begin();
120  while (outputListIt != convOutputPtr->End())
121  {
122  // Set the image information
123  outputListIt.Get()->CopyInformation(this->GetInput());
124  outputListIt.Get()->SetRequestedRegion(this->GetInput()->GetLargestPossibleRegion());
125  ++outputListIt;
126  }
127  }
128  if (concOutputPtr)
129  {
130  if (concOutputPtr->Size() != m_NumberOfIterations)
131  {
132  // in this case, clear the list
133  concOutputPtr->Clear();
134  for (unsigned int i = 0; i < m_NumberOfIterations; ++i)
135  {
136  // Create the output image
137  concOutputPtr->PushBack(OutputImageType::New());
138  }
139  }
140  // For each output image
141  typename OutputImageListType::Iterator outputListIt = concOutputPtr->Begin();
142  while (outputListIt != concOutputPtr->End())
143  {
144  // Set the image information
145  outputListIt.Get()->CopyInformation(this->GetInput());
146  outputListIt.Get()->SetRequestedRegion(this->GetInput()->GetLargestPossibleRegion());
147  ++outputListIt;
148  }
149  }
150 }
151 
152 template <class TImage, class TStructuringElement>
154 {
155  // Retrieving input/output pointers
156  InputImagePointerType inputPtr = this->GetInput();
157  OutputImageListPointerType outputPtr = this->GetOutput();
158 
159  // For each output image
160  typename OutputImageListType::Iterator outputListIt = outputPtr->Begin();
161  inputPtr->SetRequestedRegion(outputListIt.Get()->GetRequestedRegion());
162 }
163 
167 template <class TImage, class TStructuringElement>
169 {
170  // Input image pointer
171  InputImagePointerType current = this->GetInput();
172  OutputImageListPointerType outputPtr = this->GetOutput();
173  OutputImageListPointerType convOutputPtr = this->GetConvexOutput();
174  OutputImageListPointerType concOutputPtr = this->GetConcaveOutput();
176 
177  unsigned int i = 0;
178 
179  DecompositionFilterPointerType filter;
180 
181  while (i < m_NumberOfIterations)
182  {
183  filter = DecompositionFilterType::New();
184 
185  // Register Internal Filter for progress
186  m_Progress->RegisterInternalFilter(filter, 1. / m_NumberOfIterations);
187 
188  typename StructuringElementType::RadiusType radius;
189  radius.Fill(m_InitialValue + i * m_Step);
190  filter->SetRadius(radius);
191  filter->SetInput(current);
192  filter->GetOutput()->UpdateOutputInformation();
193  filter->GetOutput()->SetRequestedRegion(outputPtr->GetNthElement(i)->GetRequestedRegion());
194  filter->GetOutput()->PropagateRequestedRegion();
195  filter->GetOutput()->UpdateOutputData();
196 
197  outputPtr->SetNthElement(i, filter->GetOutput());
198  concOutputPtr->SetNthElement(i, filter->GetConcaveMap());
199  convOutputPtr->SetNthElement(i, filter->GetConvexMap());
200 
201  current = filter->GetOutput();
202 
203  ++i;
204  }
205 }
otb::GeodesicMorphologyIterativeDecompositionImageFilter::GenerateData
void GenerateData() override
otb::GeodesicMorphologyIterativeDecompositionImageFilter::OutputImageListType
Superclass::OutputImageListType OutputImageListType
Definition: otbGeodesicMorphologyIterativeDecompositionImageFilter.h:89
otbGeodesicMorphologyIterativeDecompositionImageFilter.h
otb::GeodesicMorphologyIterativeDecompositionImageFilter::GenerateInputRequestedRegion
void GenerateInputRequestedRegion() override
otb::GeodesicMorphologyIterativeDecompositionImageFilter::GenerateOutputInformation
void GenerateOutputInformation() override
otb::GeodesicMorphologyIterativeDecompositionImageFilter::GeodesicMorphologyIterativeDecompositionImageFilter
GeodesicMorphologyIterativeDecompositionImageFilter()
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbMacro.h
otb::GeodesicMorphologyIterativeDecompositionImageFilter::GetOutput
OutputImageListType * GetOutput(void) override
otb::GeodesicMorphologyIterativeDecompositionImageFilter::GetConcaveOutput
OutputImageListType * GetConcaveOutput(void)
otb::GeodesicMorphologyIterativeDecompositionImageFilter::GetConvexOutput
OutputImageListType * GetConvexOutput(void)