OTB  9.0.0
Orfeo Toolbox
otbLabelizeImageFilterBase.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 otbLabelizeImageFilterBase_hxx
22 #define otbLabelizeImageFilterBase_hxx
23 
25 
26 namespace otb
27 {
31 template <class TInputImage, class TOutputImage, class TFilter>
33 {
34  m_LowerThreshold = itk::NumericTraits<InputPixelType>::NonpositiveMin();
35  m_UpperThreshold = itk::NumericTraits<InputPixelType>::max();
37 
38  m_MultiplyFilter = MultiplyFilterType::New();
39  m_MultiplyFilter->SetCoef(0.0);
40 
41  m_ThresholdPointSetFilter = ThresholdFilterType::New();
42 
43  m_RegionGrowingFilter = RegionGrowingFilterType::New();
44 }
45 
49 template <class TInputImage, class TOutputImage, class TFilter>
51 {
52  // set input for region growing filter
53  m_RegionGrowingFilter->SetInput(this->GetInput());
54 
55  // create an empty image to store results computing
56  m_MultiplyFilter->SetInput(this->GetInput());
57  m_MultiplyFilter->Update();
58 
59  // Compute points set
60  m_ThresholdPointSetFilter->SetInput(0, this->GetInput());
61  m_ThresholdPointSetFilter->SetLowerThreshold(m_LowerThreshold);
62  m_ThresholdPointSetFilter->SetUpperThreshold(m_UpperThreshold);
63  m_ThresholdPointSetFilter->Update();
64  m_PointSet = m_ThresholdPointSetFilter->GetOutput();
65  m_ObjectCount = 0;
66 
67  // Iterate Point set
68  typedef typename PointSetType::PointsContainer ContainerType;
69  ContainerType* pointsContainer = m_PointSet->GetPoints();
70  typedef typename ContainerType::Iterator IteratorType;
71  IteratorType itList = pointsContainer->Begin();
72 
73  typename OutputImageType::Pointer outputImage = m_MultiplyFilter->GetOutput();
74 
75  while (itList != pointsContainer->End())
76  {
77  typename PointSetType::PointType pCoordinate = (itList.Value());
78  typename InputImageType::IndexType index;
79 
80  index[0] = static_cast<int>(pCoordinate[0]);
81  index[1] = static_cast<int>(pCoordinate[1]);
82  if (outputImage->GetPixel(index) == itk::NumericTraits<OutputPixelType>::ZeroValue())
83  {
84  this->RegionGrowing(index);
85 
86  AddImageFilterPointerType addImage = AddImageFilterType::New();
87  addImage->SetInput1(outputImage);
88  addImage->SetInput2(m_RegionGrowingFilter->GetOutput());
89  addImage->Update();
90  outputImage = addImage->GetOutput();
91  ++m_ObjectCount;
92  }
93  ++itList;
94  }
95 
96  this->GraftOutput(outputImage);
97 }
98 
102 template <class TInputImage, class TOutputImage, class TFilter>
103 void LabelizeImageFilterBase<TInputImage, TOutputImage, TFilter>::PrintSelf(std::ostream& os, itk::Indent indent) const
104 {
105  Superclass::PrintSelf(os, indent);
106 
107  os << indent << "Seeds lower threshold: " << m_LowerThreshold << std::endl;
108  os << indent << "Seeds upper threshold: " << m_UpperThreshold << std::endl;
109  os << indent << "ObjectCount: " << m_ObjectCount << std::endl;
110  os << indent << m_RegionGrowingFilter << std::endl;
111 }
112 } // end namespace otb
113 
114 #endif
otb::LabelizeImageFilterBase< TInputImage, TOutputImage, itk::ConfidenceConnectedImageFilter< TInputImage, TOutputImage > >::AddImageFilterPointerType
AddImageFilterType::Pointer AddImageFilterPointerType
Definition: otbLabelizeImageFilterBase.h:95
otb::LabelizeImageFilterBase::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbLabelizeImageFilterBase.hxx:103
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbLabelizeImageFilterBase.h
otb::LabelizeImageFilterBase::LabelizeImageFilterBase
LabelizeImageFilterBase()
Definition: otbLabelizeImageFilterBase.hxx:32
otb::LabelizeImageFilterBase::GenerateData
void GenerateData() override
Definition: otbLabelizeImageFilterBase.hxx:50