OTB  6.7.0
Orfeo Toolbox
otbLabelImageSmallRegionMergingFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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>
52  : public PersistentImageFilter<TInputLabelImage, TInputLabelImage>
53 {
54 public:
60 
64  itkNewMacro(Self);
66 
69  typedef TInputLabelImage InputImageType;
70  typedef typename InputImageType::Pointer InputImagePointerType;
71  typedef typename InputImageType::PixelType InputLabelType;
74  typedef typename InputImageType::RegionType RegionType;
75 
77 
78  typedef std::unordered_map<InputLabelType, std::set<InputLabelType> >
80 
81  typedef std::unordered_map<InputLabelType , RealVectorPixelType >
83  typedef std::unordered_map<InputLabelType , double>
85  typedef std::unordered_map<InputLabelType , InputLabelType> LUTType;
86 
88  itkGetMacro(Size , unsigned int);
89  itkSetMacro(Size , unsigned int);
91 
93  void SetLabelPopulation( LabelPopulationType const & labelPopulation );
94 
96  LabelPopulationType const & GetLabelPopulation() const;
97 
99  void SetLabelStatistic( LabelStatisticType const & labelStatistic );
100 
102  LabelStatisticType const & GetLabelStatistic() const;
103 
105  LUTType const & GetLUT() const;
106 
107  virtual void Reset(void) override;
108  virtual void Synthetize(void) override;
109 
110 protected:
113  void GenerateInputRequestedRegion() override;
114 
117  void ThreadedGenerateData(const RegionType&
118  outputRegionForThread, itk::ThreadIdType threadId) override;
119 
120 
123  InputLabelType FindCorrespondingLabel( InputLabelType label);
124 
127 
129  ~PersistentLabelImageSmallRegionMergingFilter() override = default;
130 
132  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
133 
134 private:
136  void operator =(const Self&) = delete;
137 
139  unsigned int m_Size;
140 
143 
146 
148  std::vector <NeigboursMapType > m_NeighboursMapsTmp;
149 
153 };
154 
170 template <class TInputLabelImage>
172  : public itk::ProcessObject
173 {
174 public:
180 
182  itkNewMacro(Self);
183 
186 
187  // Small region merging filter typedefs
193 
196 
199 
202 
203 
205  itkGetMacro(MinSize , unsigned int);
206  itkSetMacro(MinSize , unsigned int);
208 
210  void SetInputLabelImage( const TInputLabelImage * labelImage );
211 
213  void SetLabelPopulation( LabelPopulationType const & labelPopulation );
214 
216  LabelPopulationType const & GetLabelPopulation() const;
217 
219  void SetLabelStatistic( LabelStatisticType const & labelStatistic );
220 
222  LabelStatisticType const & GetLabelStatistic() const;
223 
225  LUTType const & GetLUT() const;
226 
228  void Update() override;
229 
230 protected:
233 
235  ~LabelImageSmallRegionMergingFilter() override = default;
236 
239  void GenerateData() override;
240 
241 private:
242  LabelImageSmallRegionMergingFilter(const Self &) = delete;
243  void operator =(const Self&) = delete;
244 
245  // Filter used recursively to build the equivalence table
246  typename
248 
249  // All segments with size < m_MinSize will be merged to bigger segments.
250  unsigned int m_MinSize;
251 };
252 
253 } // end namespace otb
254 
255 #ifndef OTB_MANUAL_INSTANTIATION
257 #endif
258 
259 #endif
itk::Size< Monteverdi_DIMENSION > SizeType
Definition: mvdTypes.h:137
PersistentLabelImageSmallRegionMergingFilterType::LabelPopulationType LabelPopulationType
PersistentImageFilter< TInputLabelImage, TInputLabelImage > Superclass
PersistentLabelImageSmallRegionMergingFilter< TInputLabelImage > PersistentLabelImageSmallRegionMergingFilterType
std::unordered_map< InputLabelType, InputLabelType > LUTType
PersistentFilterStreamingDecorator< PersistentLabelImageSmallRegionMergingFilterType > LabelImageSmallRegionMergingFilterType
unsigned int ThreadIdType
LabelImageSmallRegionMergingFilterType::Pointer m_SmallRegionMergingFilter
std::unordered_map< InputLabelType, RealVectorPixelType > LabelStatisticType
std::unordered_map< InputLabelType, double > LabelPopulationType
PersistentLabelImageSmallRegionMergingFilterType::LUTType LUTType
PersistentLabelImageSmallRegionMergingFilterType::LabelStatisticType LabelStatisticType
VectorImageType::PointType PointType
Definition: mvdTypes.h:189
std::unordered_map< InputLabelType, std::set< InputLabelType > > NeigboursMapType
This filter is the base class for all filter persisting data through multiple update. For instance, a filter computing global statistics on an image with streaming capabilities will have to keep the temporary results for each streamed piece of the image in order to synthesize the global statistics at the end. This filter is an itk::ImageToImageFilter, providing two additional methods. The first one, Synthetize(), allows the user to synthesize temporary data produced by the multiple updates on different pieces of the image to the global result. The second one, Reset(), allows the user to reset the temporary data for a new input image for instance.
This filter link a persistent filter with a StreamingImageVirtualWriter.