OTB  10.0.0
Orfeo Toolbox
otbHooverInstanceFilter.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 
22 #ifndef otbHooverInstanceFilter_h
23 #define otbHooverInstanceFilter_h
24 
25 #include <set>
26 #include "itkInPlaceLabelMapFilter.h"
27 #include "itkVariableSizeMatrix.h"
28 #include "itkVariableLengthVector.h"
29 #include <string>
30 
31 namespace otb
32 {
73 template <class TLabelMap>
74 class ITK_EXPORT HooverInstanceFilter : public itk::InPlaceLabelMapFilter<TLabelMap>
75 {
76 public:
79  typedef itk::InPlaceLabelMapFilter<TLabelMap> Superclass;
80  typedef itk::SmartPointer<Self> Pointer;
81  typedef itk::SmartPointer<const Self> ConstPointer;
82 
84  itkNewMacro(Self);
85 
87  itkTypeMacro(HooverInstanceFilter, InPlaceLabelMapFilter);
88 
90  typedef TLabelMap LabelMapType;
91  typedef typename LabelMapType::Pointer LabelMapPointer;
92  typedef typename LabelMapType::ConstIterator ConstIteratorType;
93  typedef typename LabelMapType::Iterator IteratorType;
94  typedef typename LabelMapType::LabelObjectType LabelObjectType;
95  typedef typename LabelObjectType::AttributeType AttributeType;
96  typedef typename LabelObjectType::AttributesValueType AttributesValueType;
97  typedef typename LabelMapType::LabelVectorType LabelVectorType;
98  typedef typename LabelMapType::RegionType ImageRegionType;
99 
100  // typedef typename LabelObjectType::LineContainerType LineContainerType;
101  typedef typename LabelObjectType::IndexType IndexType;
102  typedef typename LabelObjectType::LabelType LabelType;
103 
104  typedef unsigned long CoefficientType;
105  typedef itk::VariableSizeMatrix<CoefficientType> MatrixType;
106 
107  typedef itk::VariableLengthVector<CoefficientType> CardinalVector;
108  typedef std::set<CoefficientType> RegionSetType;
109  typedef std::vector<LabelObjectType*> ObjectVectorType;
110 
111  void SetGroundTruthLabelMap(const LabelMapType* gt);
112  void SetMachineSegmentationLabelMap(const LabelMapType* ms);
113 
114  const LabelMapType* GetGroundTruthLabelMap();
115  LabelMapType* GetMachineSegmentationLabelMap();
116 
117  LabelMapType* GetOutputGroundTruthLabelMap();
118  LabelMapType* GetOutputMachineSegmentationLabelMap();
119 
120  itkSetMacro(HooverMatrix, MatrixType);
121  itkGetMacro(HooverMatrix, MatrixType);
122 
123  itkSetMacro(Threshold, double);
124  itkGetMacro(Threshold, double);
125 
126  itkSetMacro(UseExtendedAttributes, bool);
127  itkGetMacro(UseExtendedAttributes, bool);
128 
130  itkGetMacro(MeanRC, AttributesValueType);
131  itkGetMacro(MeanRF, AttributesValueType);
132  itkGetMacro(MeanRA, AttributesValueType);
133  itkGetMacro(MeanRM, AttributesValueType);
134  itkGetMacro(MeanRN, AttributesValueType);
136 
138  {
139  ATTRIBUTE_CD = 100,
148  ATTRIBUTE_RN
149  };
150 
151  static std::string GetNameFromAttribute(const AttributeType& a)
152  {
153  std::string name;
154  switch (a)
155  {
156  case ATTRIBUTE_CD:
157  name = "HooverInstance_Ext_CD";
158  break;
159  case ATTRIBUTE_OS:
160  name = "HooverInstance_Ext_OS";
161  break;
162  case ATTRIBUTE_US:
163  name = "HooverInstance_Ext_US";
164  break;
165  case ATTRIBUTE_M:
166  name = "HooverInstance_Ext_M";
167  break;
168  case ATTRIBUTE_N:
169  name = "HooverInstance_Ext_N";
170  break;
171  case ATTRIBUTE_RC:
172  name = "HooverInstance_RC";
173  break;
174  case ATTRIBUTE_RF:
175  name = "HooverInstance_RF";
176  break;
177  case ATTRIBUTE_RA:
178  name = "HooverInstance_RA";
179  break;
180  case ATTRIBUTE_RM:
181  name = "HooverInstance_RM";
182  break;
183  case ATTRIBUTE_RN:
184  name = "HooverInstance_RN";
185  break;
186  }
187  return name;
188  }
189 
190  static AttributeType GetAttributeFromName(const std::string& name)
191  {
192  if (name == "HooverInstance_Ext_CD")
193  {
194  return ATTRIBUTE_CD;
195  }
196  else if (name == "HooverInstance_Ext_OS")
197  {
198  return ATTRIBUTE_OS;
199  }
200  else if (name == "HooverInstance_Ext_US")
201  {
202  return ATTRIBUTE_US;
203  }
204  else if (name == "HooverInstance_Ext_M")
205  {
206  return ATTRIBUTE_M;
207  }
208  else if (name == "HooverInstance_Ext_N")
209  {
210  return ATTRIBUTE_N;
211  }
212  else if (name == "HooverInstance_RC")
213  {
214  return ATTRIBUTE_RC;
215  }
216  else if (name == "HooverInstance_RF")
217  {
218  return ATTRIBUTE_RF;
219  }
220  else if (name == "HooverInstance_RA")
221  {
222  return ATTRIBUTE_RA;
223  }
224  else if (name == "HooverInstance_RM")
225  {
226  return ATTRIBUTE_RM;
227  }
228  else if (name == "HooverInstance_RN")
229  {
230  return ATTRIBUTE_RN;
231  }
232  }
233 
234 protected:
236  ~HooverInstanceFilter() override{};
237 
239  void AllocateOutputs() override;
240 
242  void ReleaseInputs() override;
243 
247  void ThreadedProcessLabelObject(LabelObjectType* labelObject) override;
248 
254  void BeforeThreadedGenerateData() override;
255 
259  void AfterThreadedGenerateData() override;
260 
261 private:
263  unsigned long m_NumberOfRegionsGT;
264 
266  unsigned long m_NumberOfRegionsMS;
267 
270 
273 
276 
279 
281  double m_Threshold;
282 
285 
288 
291 
294 
297 
300 };
301 }
302 
303 #ifndef OTB_MANUAL_INSTANTIATION
305 #endif
306 
307 #endif
This class computes the Hoover instances.
itk::VariableSizeMatrix< CoefficientType > MatrixType
LabelMapType::LabelObjectType LabelObjectType
static std::string GetNameFromAttribute(const AttributeType &a)
itk::InPlaceLabelMapFilter< TLabelMap > Superclass
LabelObjectType::LabelType LabelType
LabelObjectType::AttributeType AttributeType
LabelMapType::Pointer LabelMapPointer
LabelMapType::LabelVectorType LabelVectorType
LabelMapType::RegionType ImageRegionType
itk::SmartPointer< Self > Pointer
static AttributeType GetAttributeFromName(const std::string &name)
LabelObjectType::IndexType IndexType
itk::VariableLengthVector< CoefficientType > CardinalVector
LabelMapType::Iterator IteratorType
std::set< CoefficientType > RegionSetType
std::vector< LabelObjectType * > ObjectVectorType
LabelObjectType::AttributesValueType AttributesValueType
LabelMapType::ConstIterator ConstIteratorType
itk::SmartPointer< const Self > ConstPointer
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.