OTB  9.0.0
Orfeo Toolbox
otbHooverInstanceFilter.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 
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
otb::HooverInstanceFilter::ATTRIBUTE_RM
@ ATTRIBUTE_RM
Definition: otbHooverInstanceFilter.h:147
otb::HooverInstanceFilter::m_NumberOfRegionsGT
unsigned long m_NumberOfRegionsGT
Definition: otbHooverInstanceFilter.h:263
otb::HooverInstanceFilter::ATTRIBUTE_M
@ ATTRIBUTE_M
Definition: otbHooverInstanceFilter.h:142
otb::HooverInstanceFilter::ATTRIBUTE_RA
@ ATTRIBUTE_RA
Definition: otbHooverInstanceFilter.h:146
otb::HooverInstanceFilter::ATTRIBUTE_RC
@ ATTRIBUTE_RC
Definition: otbHooverInstanceFilter.h:144
otb::HooverInstanceFilter::ImageRegionType
LabelMapType::RegionType ImageRegionType
Definition: otbHooverInstanceFilter.h:98
otbHooverInstanceFilter.hxx
otb::HooverInstanceFilter::CoefficientType
unsigned long CoefficientType
Definition: otbHooverInstanceFilter.h:104
otb::HooverInstanceFilter::ATTRIBUTE_N
@ ATTRIBUTE_N
Definition: otbHooverInstanceFilter.h:143
otb::HooverInstanceFilter::ConstIteratorType
LabelMapType::ConstIterator ConstIteratorType
Definition: otbHooverInstanceFilter.h:92
otb::HooverInstanceFilter::RegionSetType
std::set< CoefficientType > RegionSetType
Definition: otbHooverInstanceFilter.h:108
otb::HooverInstanceFilter::AttributeType
LabelObjectType::AttributeType AttributeType
Definition: otbHooverInstanceFilter.h:95
otb::HooverInstanceFilter::m_MeanRN
AttributesValueType m_MeanRN
Definition: otbHooverInstanceFilter.h:299
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::HooverInstanceFilter::Superclass
itk::InPlaceLabelMapFilter< TLabelMap > Superclass
Definition: otbHooverInstanceFilter.h:79
otb::HooverInstanceFilter::m_HooverMatrix
MatrixType m_HooverMatrix
Definition: otbHooverInstanceFilter.h:272
otb::HooverInstanceFilter::IteratorType
LabelMapType::Iterator IteratorType
Definition: otbHooverInstanceFilter.h:93
otb::HooverInstanceFilter::m_LabelsGT
LabelVectorType m_LabelsGT
Definition: otbHooverInstanceFilter.h:269
otb::HooverInstanceFilter::IndexType
LabelObjectType::IndexType IndexType
Definition: otbHooverInstanceFilter.h:101
otb::HooverInstanceFilter::m_CardRegMS
CardinalVector m_CardRegMS
Definition: otbHooverInstanceFilter.h:278
otb::HooverInstanceFilter::m_MeanRF
AttributesValueType m_MeanRF
Definition: otbHooverInstanceFilter.h:290
otb::HooverInstanceFilter::ATTRIBUTE_OS
@ ATTRIBUTE_OS
Definition: otbHooverInstanceFilter.h:140
otb::HooverInstanceFilter::m_MeanRA
AttributesValueType m_MeanRA
Definition: otbHooverInstanceFilter.h:293
otb::HooverInstanceFilter::m_UseExtendedAttributes
bool m_UseExtendedAttributes
Definition: otbHooverInstanceFilter.h:284
otb::HooverInstanceFilter::LabelObjectType
LabelMapType::LabelObjectType LabelObjectType
Definition: otbHooverInstanceFilter.h:94
otb::HooverInstanceFilter::m_Threshold
double m_Threshold
Definition: otbHooverInstanceFilter.h:281
otb::HooverInstanceFilter::m_MeanRC
AttributesValueType m_MeanRC
Definition: otbHooverInstanceFilter.h:287
otb::HooverInstanceFilter::MatrixType
itk::VariableSizeMatrix< CoefficientType > MatrixType
Definition: otbHooverInstanceFilter.h:105
otb::HooverInstanceFilter::CardinalVector
itk::VariableLengthVector< CoefficientType > CardinalVector
Definition: otbHooverInstanceFilter.h:107
otb::HooverInstanceFilter::LabelMapPointer
LabelMapType::Pointer LabelMapPointer
Definition: otbHooverInstanceFilter.h:91
otb::HooverInstanceFilter::ObjectVectorType
std::vector< LabelObjectType * > ObjectVectorType
Definition: otbHooverInstanceFilter.h:109
otb::HooverInstanceFilter::m_NumberOfRegionsMS
unsigned long m_NumberOfRegionsMS
Definition: otbHooverInstanceFilter.h:266
otb::HooverInstanceFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbHooverInstanceFilter.h:81
otb::HooverInstanceFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbHooverInstanceFilter.h:80
otb::HooverInstanceFilter::ATTRIBUTE_US
@ ATTRIBUTE_US
Definition: otbHooverInstanceFilter.h:141
otb::HooverInstanceFilter::GetNameFromAttribute
static std::string GetNameFromAttribute(const AttributeType &a)
Definition: otbHooverInstanceFilter.h:151
otb::HooverInstanceFilter::AttributeTypes
AttributeTypes
Definition: otbHooverInstanceFilter.h:137
otb::HooverInstanceFilter::~HooverInstanceFilter
~HooverInstanceFilter() override
Definition: otbHooverInstanceFilter.h:236
otb::HooverInstanceFilter::LabelVectorType
LabelMapType::LabelVectorType LabelVectorType
Definition: otbHooverInstanceFilter.h:97
otb::HooverInstanceFilter::m_MeanRM
AttributesValueType m_MeanRM
Definition: otbHooverInstanceFilter.h:296
otb::HooverInstanceFilter::AttributesValueType
LabelObjectType::AttributesValueType AttributesValueType
Definition: otbHooverInstanceFilter.h:96
otb::HooverInstanceFilter::ATTRIBUTE_RF
@ ATTRIBUTE_RF
Definition: otbHooverInstanceFilter.h:145
otb::HooverInstanceFilter::m_CardRegGT
CardinalVector m_CardRegGT
Definition: otbHooverInstanceFilter.h:275
otb::HooverInstanceFilter::Self
HooverInstanceFilter Self
Definition: otbHooverInstanceFilter.h:78
otb::HooverInstanceFilter::GetAttributeFromName
static AttributeType GetAttributeFromName(const std::string &name)
Definition: otbHooverInstanceFilter.h:190
otb::HooverInstanceFilter::LabelMapType
TLabelMap LabelMapType
Definition: otbHooverInstanceFilter.h:87
otb::HooverInstanceFilter::LabelType
LabelObjectType::LabelType LabelType
Definition: otbHooverInstanceFilter.h:102
otb::HooverInstanceFilter
This class computes the Hoover instances.
Definition: otbHooverInstanceFilter.h:74