OTB  9.0.0
Orfeo Toolbox
otbImageToLabelMapWithAttributesFilter.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 otbImageToLabelMapWithAttributesFilter_hxx
22 #define otbImageToLabelMapWithAttributesFilter_hxx
23 
25 #include "itkProcessObject.h"
26 
27 namespace otb
28 {
29 template <class TInputImage, class TLabeledImage, class TOutputLabel, class TObjectLabel>
31 {
32  m_Output = LabelMapType::New();
33  this->itk::ProcessObject::SetNumberOfRequiredInputs(2);
34 }
35 
36 template <class TInputImage, class TLabeledImage, class TOutputLabel, class TObjectLabel>
38 {
39  // call the superclass' implementation of this method
40  Superclass::GenerateInputRequestedRegion();
41 
42  // We need all the input.
43  typename InputImageType::Pointer input = const_cast<InputImageType*>(this->GetInput());
44 
45  if (!input)
46  {
47  return;
48  }
49 
50  input->SetRequestedRegion(input->GetLargestPossibleRegion());
51 }
52 
53 template <class TInputImage, class TLabeledImage, class TOutputLabel, class TObjectLabel>
55 {
56  // Process object is not const-correct so the const_cast is required here
57  this->itk::ProcessObject::SetNthInput(0, const_cast<InputImageType*>(image));
58 }
59 
60 template <class TInputImage, class TLabeledImage, class TOutputLabel, class TObjectLabel>
62 {
63  // Process object is not const-correct so the const_cast is required here
64  this->itk::ProcessObject::SetNthInput(1, const_cast<LabeledImageType*>(image));
65 }
66 
67 template <class TInputImage, class TLabeledImage, class TOutputLabel, class TObjectLabel>
70 {
71  if (this->GetNumberOfInputs() < 2)
72  {
73  return nullptr;
74  }
75 
76  return static_cast<const InputImageType*>(this->itk::ProcessObject::GetInput(0));
77 }
78 
79 template <class TInputImage, class TLabeledImage, class TOutputLabel, class TObjectLabel>
82 {
83  if (this->GetNumberOfInputs() < 2)
84  {
85  return nullptr;
86  }
87 
88  return static_cast<const LabeledImageType*>(this->itk::ProcessObject::GetInput(1));
89 }
90 
91 
92 template <class TInputImage, class TLabeledImage, class TOutputLabel, class TObjectLabel>
95 {
96  return dynamic_cast<LabelMapType*>(this->Superclass::GetOutput(0));
97 }
98 
99 
100 template <class TInputImage, class TLabeledImage, class TOutputLabel, class TObjectLabel>
102 {
103  typename InputImageType::Pointer inputImage = const_cast<InputImageType*>(this->GetInput());
104  typename LabeledImageType::Pointer labeldImage = const_cast<LabeledImageType*>(this->GetLabeledImage());
105 
106  // Convert to label map
107  typename LabelMapFilterType::Pointer lfilter = LabelMapFilterType::New();
108  lfilter->SetBackgroundValue(itk::NumericTraits<LabelType>::max());
109  lfilter->SetInput(labeldImage);
110 
111  // Compute shape attributes
112  typename ShapeLabelMapFilterType::Pointer shapeLabelMapFilter = ShapeLabelMapFilterType::New();
113  shapeLabelMapFilter->SetInput(lfilter->GetOutput());
114 
115  // Compute radiometric attributes
116  typename BandStatisticsLabelMapFilterType::Pointer bandStatsLabelMapFilter = BandStatisticsLabelMapFilterType::New();
117  bandStatsLabelMapFilter->SetInput(shapeLabelMapFilter->GetOutput());
118  bandStatsLabelMapFilter->SetFeatureImage(inputImage);
119 
120  // Get the label map
121  bandStatsLabelMapFilter->GetOutput()->SetAdjacencyMap(lfilter->GetOutput()->GetAdjacencyMap());
122  bandStatsLabelMapFilter->GraftOutput(this->GetOutput());
123 
124  // execute the mini-pipeline
125  bandStatsLabelMapFilter->Update();
126 
127  // graft the mini-pipeline output back onto this filter's output.
128  this->GraftOutput(bandStatsLabelMapFilter->GetOutput());
129 }
130 }
131 
132 #endif
otb::ImageToLabelMapWithAttributesFilter::LabeledImageType
TLabeledImage LabeledImageType
Definition: otbImageToLabelMapWithAttributesFilter.h:65
otb::BandsStatisticsAttributesLabelMapFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbBandsStatisticsAttributesLabelMapFilter.h:159
otb::ImageToLabelMapWithAttributesFilter::GenerateInputRequestedRegion
void GenerateInputRequestedRegion() override
Definition: otbImageToLabelMapWithAttributesFilter.hxx:37
otb::LabelImageToLabelMapWithAdjacencyFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbLabelImageToLabelMapWithAdjacencyFilter.h:45
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbImageToLabelMapWithAttributesFilter.h
otb::ImageToLabelMapWithAttributesFilter::GetInput
const InputImageType * GetInput(void)
Definition: otbImageToLabelMapWithAttributesFilter.hxx:69
otb::ImageToLabelMapWithAttributesFilter::InputImageType
TInputImage InputImageType
Definition: otbImageToLabelMapWithAttributesFilter.h:62
otb::ImageToLabelMapWithAttributesFilter::SetLabeledImage
virtual void SetLabeledImage(const LabeledImageType *image)
Definition: otbImageToLabelMapWithAttributesFilter.hxx:61
otb::ImageToLabelMapWithAttributesFilter::GetOutput
virtual LabelMapType * GetOutput()
Definition: otbImageToLabelMapWithAttributesFilter.hxx:94
otb::ImageToLabelMapWithAttributesFilter::GetLabeledImage
const LabeledImageType * GetLabeledImage()
Definition: otbImageToLabelMapWithAttributesFilter.hxx:81
otb::LabelMapWithAdjacency
This class is a LabelMap with additional adjacency information.
Definition: otbLabelMapWithAdjacency.h:41
otb::ShapeAttributesLabelMapFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbShapeAttributesLabelMapFilter.h:226
otb::ImageToLabelMapWithAttributesFilter::GenerateData
void GenerateData() override
Definition: otbImageToLabelMapWithAttributesFilter.hxx:101
otb::ImageToLabelMapWithAttributesFilter::SetInput
void SetInput(const InputImageType *image) override
Definition: otbImageToLabelMapWithAttributesFilter.hxx:54
otb::ImageToLabelMapWithAttributesFilter::ImageToLabelMapWithAttributesFilter
ImageToLabelMapWithAttributesFilter()
Definition: otbImageToLabelMapWithAttributesFilter.hxx:30