OTB  9.0.0
Orfeo Toolbox
otbMeanShiftSegmentationFilter.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 otbMeanShiftSegmentationFilter_hxx
22 #define otbMeanShiftSegmentationFilter_hxx
23 
25 
26 namespace otb
27 {
28 
29 template <class TInputImage, class TOutputLabelImage, class TOutputClusteredImage, class TKernel>
31 {
32  m_MeanShiftFilter = MeanShiftFilterType::New();
33  m_RegionMergingFilter = RegionMergingFilterType::New();
34  m_RegionPruningFilter = RegionPruningFilterType::New();
35  m_RelabelFilter = RelabelComponentFilterType::New();
36  this->SetMinRegionSize(100);
37  this->SetNumberOfRequiredOutputs(2);
38  this->SetNthOutput(0, TOutputLabelImage::New());
39  this->SetNthOutput(1, TOutputClusteredImage::New());
40  // default set MeanShiftFilter mode search to true because Merging and Pruning use LabelOutput
41  m_MeanShiftFilter->SetModeSearch(true);
42 }
43 
44 template <class TInputImage, class TOutputLabelImage, class TOutputClusteredImage, class TKernel>
46 {
47 }
48 
49 template <class TInputImage, class TOutputLabelImage, class TOutputClusteredImage, class TKernel>
51 {
52  return static_cast<OutputLabelImageType*>(this->itk::ProcessObject::GetOutput(0));
53 }
54 
55 template <class TInputImage, class TOutputLabelImage, class TOutputClusteredImage, class TKernel>
57 {
58  return static_cast<OutputLabelImageType*>(this->itk::ProcessObject::GetOutput(0));
59 }
60 
61 template <class TInputImage, class TOutputLabelImage, class TOutputClusteredImage, class TKernel>
64 {
65  return static_cast<OutputClusteredImageType*>(this->itk::ProcessObject::GetOutput(1));
66 }
67 
68 template <class TInputImage, class TOutputLabelImage, class TOutputClusteredImage, class TKernel>
71 {
72  return static_cast<OutputClusteredImageType*>(this->itk::ProcessObject::GetOutput(1));
73 }
74 
75 template <class TInputImage, class TOutputLabelImage, class TOutputClusteredImage, class TKernel>
77 {
78  this->m_MeanShiftFilter->SetInput(this->GetInput());
79 
80  // Relabel output to avoid same label assigned to discontinuous areas
81 
82  m_RelabelFilter->SetInput(this->m_MeanShiftFilter->GetLabelOutput());
83  this->m_RegionMergingFilter->SetInputLabelImage(this->m_RelabelFilter->GetOutput());
84 
85  this->m_RegionMergingFilter->SetInputSpectralImage(this->m_MeanShiftFilter->GetRangeOutput());
86  this->m_RegionMergingFilter->SetRangeBandwidth(this->GetRangeBandwidth());
87  if (this->GetMinRegionSize() == 0)
88  {
89 
90  m_RegionMergingFilter->GraftNthOutput(0, this->GetLabelOutput());
91  m_RegionMergingFilter->GraftNthOutput(1, this->GetClusteredOutput());
92  this->m_RegionMergingFilter->Update();
93  this->GraftNthOutput(0, m_RegionMergingFilter->GetLabelOutput());
94  this->GraftNthOutput(1, m_RegionMergingFilter->GetClusteredOutput());
95  }
96  else
97  {
98 
99  this->m_RegionPruningFilter->SetInputLabelImage(this->m_RegionMergingFilter->GetLabelOutput());
100  this->m_RegionPruningFilter->SetInputSpectralImage(this->m_RegionMergingFilter->GetClusteredOutput());
101  m_RegionPruningFilter->GraftNthOutput(0, this->GetLabelOutput());
102  m_RegionPruningFilter->GraftNthOutput(1, this->GetClusteredOutput());
103 
104  this->m_RegionPruningFilter->Update();
105  this->GraftNthOutput(0, m_RegionPruningFilter->GetLabelOutput());
106  this->GraftNthOutput(1, m_RegionPruningFilter->GetClusteredOutput());
107  }
108 }
109 
110 } // end namespace otb
111 #endif
otb::MeanShiftSegmentationFilter::GenerateData
void GenerateData() override
Definition: otbMeanShiftSegmentationFilter.hxx:76
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::MeanShiftSegmentationFilter::GetLabelOutput
const OutputLabelImageType * GetLabelOutput() const
Definition: otbMeanShiftSegmentationFilter.hxx:50
otb::MeanShiftSegmentationFilter::GetClusteredOutput
const OutputClusteredImageType * GetClusteredOutput() const
Definition: otbMeanShiftSegmentationFilter.hxx:63
otb::MeanShiftSegmentationFilter::~MeanShiftSegmentationFilter
~MeanShiftSegmentationFilter() override
Definition: otbMeanShiftSegmentationFilter.hxx:45
otb::MeanShiftSegmentationFilter::MeanShiftSegmentationFilter
MeanShiftSegmentationFilter()
Definition: otbMeanShiftSegmentationFilter.hxx:30
otb::MeanShiftSegmentationFilter::OutputLabelImageType
TOutputLabelImage OutputLabelImageType
Definition: otbMeanShiftSegmentationFilter.h:100
otbMeanShiftSegmentationFilter.h
otb::MeanShiftSegmentationFilter::OutputClusteredImageType
TOutputClusteredImage OutputClusteredImageType
Definition: otbMeanShiftSegmentationFilter.h:101