OTB  10.0.0
Orfeo Toolbox
otbLabelImageSmallRegionMergingFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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 
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 
223 
226  void GenerateData() override;
227 
228 private:
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
void operator=(const Self &)=delete
PersistentLabelImageSmallRegionMergingFilterType::LabelPopulationType LabelPopulationType
PersistentFilterStreamingDecorator< PersistentLabelImageSmallRegionMergingFilterType > LabelImageSmallRegionMergingFilterType
LabelImageSmallRegionMergingFilter(const Self &)=delete
PersistentLabelImageSmallRegionMergingFilterType::LabelStatisticType LabelStatisticType
PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage > PersistentLabelImageSmallRegionMergingFilterType
LabelImageSmallRegionMergingFilterType::Pointer m_SmallRegionMergingFilter
PersistentLabelImageSmallRegionMergingFilterType::LUTType LUTType
~LabelImageSmallRegionMergingFilter() override=default
This filter link a persistent filter with a StreamingImageVirtualWriter.
This filter is the base class for all filter persisting data through multiple update....
std::unordered_map< InputLabelType, std::set< InputLabelType > > NeighboursMapType
PersistentLabelImageSmallRegionMergingFilter(const Self &)=delete
std::unordered_map< InputLabelType, RealVectorPixelType > LabelStatisticType
std::unordered_map< InputLabelType, double > LabelPopulationType
std::unordered_map< InputLabelType, InputLabelType > LUTType
PersistentImageFilter< TInputLabelImage, TInputLabelImage > Superclass
~PersistentLabelImageSmallRegionMergingFilter() override=default
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.