OTB  9.0.0
Orfeo Toolbox
otbLabelImageSmallRegionMergingFilter.h
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 otbLabelImageSmallRegionMergingFilter_h
22 #define otbLabelImageSmallRegionMergingFilter_h
23 
26 
27 #include <unordered_map>
28 
29 namespace otb
30 {
31 
50 template <class TInputLabelImage>
51 class ITK_EXPORT PersistentLabelImageSmallRegionMergingFilter : public PersistentImageFilter<TInputLabelImage, TInputLabelImage>
52 {
53 public:
57  typedef itk::SmartPointer<Self> Pointer;
58  typedef itk::SmartPointer<const Self> ConstPointer;
59 
62  itkNewMacro(Self);
64 
67  typedef TInputLabelImage InputImageType;
68  typedef typename InputImageType::Pointer InputImagePointerType;
69  typedef typename InputImageType::PixelType InputLabelType;
70  typedef typename InputImageType::SizeType InputSizeType;
71  typedef typename InputImageType::PointType PointType;
72  typedef typename InputImageType::RegionType RegionType;
73 
74  typedef itk::VariableLengthVector<double> RealVectorPixelType;
75 
76  typedef std::unordered_map<InputLabelType, std::set<InputLabelType>> NeighboursMapType;
77 
78  typedef std::unordered_map<InputLabelType, RealVectorPixelType> LabelStatisticType;
79  typedef std::unordered_map<InputLabelType, double> LabelPopulationType;
80  typedef std::unordered_map<InputLabelType, InputLabelType> LUTType;
81 
83  itkGetMacro(Size, unsigned int);
84  itkSetMacro(Size, unsigned int);
86 
88  void SetLabelPopulation(LabelPopulationType const& labelPopulation);
89 
91  LabelPopulationType const& GetLabelPopulation() const;
92 
94  void SetLabelStatistic(LabelStatisticType const& labelStatistic);
95 
97  LabelStatisticType const& GetLabelStatistic() const;
98 
100  LUTType const& GetLUT() const;
101 
102  virtual void Reset(void) override;
103  virtual void Synthetize(void) override;
104 
105 protected:
108  void GenerateInputRequestedRegion() override;
109 
112  void ThreadedGenerateData(const RegionType& outputRegionForThread, itk::ThreadIdType threadId) override;
113 
114 
117  InputLabelType FindCorrespondingLabel(InputLabelType label);
118 
121 
123  ~PersistentLabelImageSmallRegionMergingFilter() override = default;
124 
126  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
127 
128 private:
130  void operator=(const Self&) = delete;
131 
133  unsigned int m_Size;
134 
137 
140 
142  std::vector<NeighboursMapType> m_NeighboursMapsTmp;
143 
147 };
148 
164 template <class TInputLabelImage>
165 class ITK_EXPORT LabelImageSmallRegionMergingFilter : public itk::ProcessObject
166 {
167 public:
170  typedef itk::ProcessObject Superclass;
171  typedef itk::SmartPointer<Self> Pointer;
172  typedef itk::SmartPointer<const Self> ConstPointer;
173 
175  itkNewMacro(Self);
176 
178  itkTypeMacro(LabelImageSmallRegionMergingFilter, itk::ProcessObject);
179 
180  // Small region merging filter typedefs
183 
185 
187 
189 
190 
192  itkGetMacro(MinSize, unsigned int);
193  itkSetMacro(MinSize, unsigned int);
195 
197  void SetInputLabelImage(const TInputLabelImage* labelImage);
198 
200  void SetLabelPopulation(LabelPopulationType const& labelPopulation);
201 
203  LabelPopulationType const& GetLabelPopulation() const;
204 
206  void SetLabelStatistic(LabelStatisticType const& labelStatistic);
207 
209  LabelStatisticType const& GetLabelStatistic() const;
210 
212  LUTType const& GetLUT() const;
213 
215  void Update() override;
216 
217 protected:
220 
222  ~LabelImageSmallRegionMergingFilter() override = default;
223 
226  void GenerateData() override;
227 
228 private:
229  LabelImageSmallRegionMergingFilter(const Self&) = delete;
230  void operator=(const Self&) = delete;
231 
232  // Filter used recursively to build the equivalence table
234 
235  // All segments with size < m_MinSize will be merged to bigger segments.
236  unsigned int m_MinSize;
237 };
238 
239 } // end namespace otb
240 
241 #ifndef OTB_MANUAL_INSTANTIATION
243 #endif
244 
245 #endif
otb::LabelImageSmallRegionMergingFilter::Superclass
itk::ProcessObject Superclass
Definition: otbLabelImageSmallRegionMergingFilter.h:170
otbPersistentImageFilter.h
otb::PersistentLabelImageSmallRegionMergingFilter::NeighboursMapType
std::unordered_map< InputLabelType, std::set< InputLabelType > > NeighboursMapType
Definition: otbLabelImageSmallRegionMergingFilter.h:76
otb::LabelImageSmallRegionMergingFilter::LabelPopulationType
PersistentLabelImageSmallRegionMergingFilterType::LabelPopulationType LabelPopulationType
Definition: otbLabelImageSmallRegionMergingFilter.h:184
otb::LabelImageSmallRegionMergingFilter::LUTType
PersistentLabelImageSmallRegionMergingFilterType::LUTType LUTType
Definition: otbLabelImageSmallRegionMergingFilter.h:188
otb::LabelImageSmallRegionMergingFilter::LabelStatisticType
PersistentLabelImageSmallRegionMergingFilterType::LabelStatisticType LabelStatisticType
Definition: otbLabelImageSmallRegionMergingFilter.h:186
otb::PersistentImageFilter
This filter is the base class for all filter persisting data through multiple update....
Definition: otbPersistentImageFilter.h:47
otb::PersistentFilterStreamingDecorator::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbPersistentFilterStreamingDecorator.h:53
otb::PersistentLabelImageSmallRegionMergingFilter::LUTType
std::unordered_map< InputLabelType, InputLabelType > LUTType
Definition: otbLabelImageSmallRegionMergingFilter.h:80
otb::PersistentLabelImageSmallRegionMergingFilter::m_LabelStatistic
LabelStatisticType m_LabelStatistic
Definition: otbLabelImageSmallRegionMergingFilter.h:139
otb::PersistentLabelImageSmallRegionMergingFilter::PointType
InputImageType::PointType PointType
Definition: otbLabelImageSmallRegionMergingFilter.h:71
otbPersistentFilterStreamingDecorator.h
otb::PersistentLabelImageSmallRegionMergingFilter::Self
PersistentLabelImageSmallRegionMergingFilter Self
Definition: otbLabelImageSmallRegionMergingFilter.h:55
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::LabelImageSmallRegionMergingFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbLabelImageSmallRegionMergingFilter.h:171
otb::PersistentLabelImageSmallRegionMergingFilter::InputImagePointerType
InputImageType::Pointer InputImagePointerType
Definition: otbLabelImageSmallRegionMergingFilter.h:68
otb::PersistentLabelImageSmallRegionMergingFilter::m_LUT
LUTType m_LUT
Definition: otbLabelImageSmallRegionMergingFilter.h:146
otb::LabelImageSmallRegionMergingFilter::m_SmallRegionMergingFilter
LabelImageSmallRegionMergingFilterType::Pointer m_SmallRegionMergingFilter
Definition: otbLabelImageSmallRegionMergingFilter.h:233
otb::PersistentLabelImageSmallRegionMergingFilter::Superclass
PersistentImageFilter< TInputLabelImage, TInputLabelImage > Superclass
Definition: otbLabelImageSmallRegionMergingFilter.h:56
otb::PersistentLabelImageSmallRegionMergingFilter::RealVectorPixelType
itk::VariableLengthVector< double > RealVectorPixelType
Definition: otbLabelImageSmallRegionMergingFilter.h:74
otb::PersistentLabelImageSmallRegionMergingFilter::RegionType
InputImageType::RegionType RegionType
Definition: otbLabelImageSmallRegionMergingFilter.h:72
otb::PersistentLabelImageSmallRegionMergingFilter
Definition: otbLabelImageSmallRegionMergingFilter.h:51
otb::PersistentLabelImageSmallRegionMergingFilter::m_Size
unsigned int m_Size
Definition: otbLabelImageSmallRegionMergingFilter.h:133
otb::LabelImageSmallRegionMergingFilter
Definition: otbLabelImageSmallRegionMergingFilter.h:165
otb::PersistentLabelImageSmallRegionMergingFilter::InputLabelType
InputImageType::PixelType InputLabelType
Definition: otbLabelImageSmallRegionMergingFilter.h:69
otb::PersistentLabelImageSmallRegionMergingFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbLabelImageSmallRegionMergingFilter.h:58
otb::PersistentFilterStreamingDecorator
This filter link a persistent filter with a StreamingImageVirtualWriter.
Definition: otbPersistentFilterStreamingDecorator.h:47
otb::LabelImageSmallRegionMergingFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbLabelImageSmallRegionMergingFilter.h:172
otb::LabelImageSmallRegionMergingFilter::Self
LabelImageSmallRegionMergingFilter Self
Definition: otbLabelImageSmallRegionMergingFilter.h:169
otbLabelImageSmallRegionMergingFilter.hxx
otb::PersistentLabelImageSmallRegionMergingFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbLabelImageSmallRegionMergingFilter.h:57
otb::PersistentLabelImageSmallRegionMergingFilter::InputImageType
TInputLabelImage InputImageType
Definition: otbLabelImageSmallRegionMergingFilter.h:62
otb::PersistentLabelImageSmallRegionMergingFilter::LabelPopulationType
std::unordered_map< InputLabelType, double > LabelPopulationType
Definition: otbLabelImageSmallRegionMergingFilter.h:79
otb::PersistentLabelImageSmallRegionMergingFilter::m_NeighboursMapsTmp
std::vector< NeighboursMapType > m_NeighboursMapsTmp
Definition: otbLabelImageSmallRegionMergingFilter.h:142
otb::LabelImageSmallRegionMergingFilter::PersistentLabelImageSmallRegionMergingFilterType
PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage > PersistentLabelImageSmallRegionMergingFilterType
Definition: otbLabelImageSmallRegionMergingFilter.h:178
otb::PersistentLabelImageSmallRegionMergingFilter::InputSizeType
InputImageType::SizeType InputSizeType
Definition: otbLabelImageSmallRegionMergingFilter.h:70
otb::PersistentLabelImageSmallRegionMergingFilter::LabelStatisticType
std::unordered_map< InputLabelType, RealVectorPixelType > LabelStatisticType
Definition: otbLabelImageSmallRegionMergingFilter.h:78
otb::LabelImageSmallRegionMergingFilter::m_MinSize
unsigned int m_MinSize
Definition: otbLabelImageSmallRegionMergingFilter.h:236
otb::LabelImageSmallRegionMergingFilter::LabelImageSmallRegionMergingFilterType
PersistentFilterStreamingDecorator< PersistentLabelImageSmallRegionMergingFilterType > LabelImageSmallRegionMergingFilterType
Definition: otbLabelImageSmallRegionMergingFilter.h:182
otb::PersistentLabelImageSmallRegionMergingFilter::m_LabelPopulation
LabelPopulationType m_LabelPopulation
Definition: otbLabelImageSmallRegionMergingFilter.h:136