OTB  9.0.0
Orfeo Toolbox
otbSampleAugmentationFilter.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 otbSampleAugmentationFilter_h
22 #define otbSampleAugmentationFilter_h
23 
24 #include "itkProcessObject.h"
26 #include "otbSampleAugmentation.h"
27 #include "OTBSamplingExport.h"
28 #include <string>
29 
30 namespace otb
31 {
32 
33 
47 class OTBSampling_EXPORT SampleAugmentationFilter : public itk::ProcessObject
48 {
49 public:
52  typedef itk::ProcessObject Superclass;
53  typedef itk::SmartPointer<Self> Pointer;
54  typedef itk::SmartPointer<const Self> ConstPointer;
55 
57  itkNewMacro(Self);
58 
60  itkTypeMacro(SampleAugmentationFilter, ProcessObject);
61 
65 
66  typedef itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType;
67 
70 
71  enum class Strategy
72  {
73  Replicate,
74  Jitter,
75  Smote
76  };
77 
79  using Superclass::SetInput;
80  virtual void SetInput(const OGRDataSourceType* ds);
81  const OGRDataSourceType* GetInput(unsigned int idx);
83 
84  virtual void SetOutputSamples(ogr::DataSource* data);
85 
89  itkSetMacro(ClassFieldName, std::string);
90 
94  itkGetMacro(ClassFieldName, std::string);
95 
96 
97  itkSetMacro(Layer, size_t);
98  itkGetMacro(Layer, size_t);
99  itkSetMacro(Label, int);
100  itkGetMacro(Label, int);
102  {
103  m_Strategy = s;
104  }
106  {
107  return m_Strategy;
108  }
109  itkSetMacro(NumberOfSamples, int);
110  itkGetMacro(NumberOfSamples, int);
111  void SetExcludedFields(const std::vector<std::string>& ef)
112  {
113  m_ExcludedFields = ef;
114  }
115  std::vector<std::string> GetExcludedFields() const
116  {
117  return m_ExcludedFields;
118  }
119  itkSetMacro(StdFactor, double);
120  itkGetMacro(StdFactor, double);
121  itkSetMacro(SmoteNeighbors, size_t);
122  itkGetMacro(SmoteNeighbors, size_t);
123  itkSetMacro(Seed, int);
124  itkGetMacro(Seed, int);
128  const OGRDataSourceType* GetOutput();
129 
130 protected:
133  {
134  }
135 
137  void GenerateData() override;
138 
140  typedef itk::DataObject::Pointer DataObjectPointer;
141 
142  DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx) override;
143  using Superclass::MakeOutput;
144 
145 
146  SampleVectorType ExtractSamples(const ogr::DataSource::Pointer vectors, size_t layerName, const std::string& classField, const int label,
147  const std::vector<std::string>& excludedFields = {});
148 
149  void SampleToOGRFeatures(const ogr::DataSource::Pointer& vectors, ogr::DataSource* output, const SampleVectorType& samples, const size_t layerName,
150  const std::string& classField, int label, const std::vector<std::string>& excludedFields = {});
151 
152  std::set<size_t> GetExcludedFieldsIds(const std::vector<std::string>& excludedFields, const ogr::Layer& inputLayer);
153  bool IsNumericField(const ogr::Feature& feature, const int idx);
154 
155  ogr::Feature SelectTemplateFeature(const ogr::Layer& inputLayer, const std::string& classField, int label);
156 
157 private:
158  SampleAugmentationFilter(const Self&) = delete;
159  void operator=(const Self&) = delete;
160 
161  std::string m_ClassFieldName;
162  size_t m_Layer;
163  int m_Label;
164  std::vector<std::string> m_ExcludedFields;
167  double m_StdFactor;
169  int m_Seed;
170 };
171 
172 
173 } // end namespace otb
174 
175 #endif
otb::SampleAugmentationFilter::m_Layer
vcl_size_t m_Layer
Definition: otbSampleAugmentationFilter.h:162
otb::SampleAugmentationFilter::Strategy
Strategy
Definition: otbSampleAugmentationFilter.h:71
otb::SampleAugmentationFilter::OGRDataSourceType
ogr::DataSource OGRDataSourceType
Definition: otbSampleAugmentationFilter.h:60
otb::SampleAugmentationFilter::DataObjectPointer
itk::DataObject::Pointer DataObjectPointer
Definition: otbSampleAugmentationFilter.h:140
otb::sampleAugmentation::Smote
void Smote(const SampleVectorType &inSamples, const vcl_size_t nbSamples, SampleVectorType &newSamples, const int nbNeighbors, const int seed=std::time(nullptr))
Definition: otbSampleAugmentation.h:221
otb::SampleAugmentationFilter::Superclass
itk::ProcessObject Superclass
Definition: otbSampleAugmentationFilter.h:52
otb::SampleAugmentationFilter::m_NumberOfSamples
int m_NumberOfSamples
Definition: otbSampleAugmentationFilter.h:166
otb::SampleAugmentationFilter::SampleVectorType
sampleAugmentation::SampleVectorType SampleVectorType
Definition: otbSampleAugmentationFilter.h:69
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::ogr::DataSource
Collection of geometric objects.
Definition: otbOGRDataSourceWrapper.h:83
otb::SampleAugmentationFilter::Self
SampleAugmentationFilter Self
Definition: otbSampleAugmentationFilter.h:51
otb::SampleAugmentationFilter::DataObjectPointerArraySizeType
itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
Definition: otbSampleAugmentationFilter.h:66
otb::SampleAugmentationFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbSampleAugmentationFilter.h:54
otb::SampleAugmentationFilter
Filter to generate synthetic samples from existing ones.
Definition: otbSampleAugmentationFilter.h:47
otbSampleAugmentation.h
otb::SampleAugmentationFilter::GetExcludedFields
std::vector< std::string > GetExcludedFields() const
Definition: otbSampleAugmentationFilter.h:115
otb::SampleAugmentationFilter::m_Label
int m_Label
Definition: otbSampleAugmentationFilter.h:163
otb::SampleAugmentationFilter::m_Strategy
Strategy m_Strategy
Definition: otbSampleAugmentationFilter.h:165
otb::SampleAugmentationFilter::~SampleAugmentationFilter
~SampleAugmentationFilter() override
Definition: otbSampleAugmentationFilter.h:132
otb::SampleAugmentationFilter::m_SmoteNeighbors
vcl_size_t m_SmoteNeighbors
Definition: otbSampleAugmentationFilter.h:168
otb::SampleAugmentationFilter::SetExcludedFields
void SetExcludedFields(const std::vector< std::string > &ef)
Definition: otbSampleAugmentationFilter.h:111
otb::sampleAugmentation::SampleType
std::vector< double > SampleType
Definition: otbSampleAugmentation.h:41
otb::SampleAugmentationFilter::OGRLayerType
ogr::Layer OGRLayerType
Definition: otbSampleAugmentationFilter.h:64
otb::ogr::DataSource::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbOGRDataSourceWrapper.h:90
otb::SampleAugmentationFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbSampleAugmentationFilter.h:53
otb::SampleAugmentationFilter::m_ClassFieldName
std::string m_ClassFieldName
Definition: otbSampleAugmentationFilter.h:161
otb::sampleAugmentation::SampleVectorType
std::vector< SampleType > SampleVectorType
Definition: otbSampleAugmentation.h:42
otb::SampleAugmentationFilter::m_ExcludedFields
std::vector< std::string > m_ExcludedFields
Definition: otbSampleAugmentationFilter.h:164
otb::SampleAugmentationFilter::m_Seed
int m_Seed
Definition: otbSampleAugmentationFilter.h:169
otb::SampleAugmentationFilter::m_StdFactor
double m_StdFactor
Definition: otbSampleAugmentationFilter.h:167
otb::SampleAugmentationFilter::GetStrategy
Strategy GetStrategy() const
Definition: otbSampleAugmentationFilter.h:105
otb::ogr::Layer
Layer of geometric objects.
Definition: otbOGRLayerWrapper.h:80
otb::SampleAugmentationFilter::SampleType
sampleAugmentation::SampleType SampleType
Definition: otbSampleAugmentationFilter.h:68
otb::SampleAugmentationFilter::SetStrategy
void SetStrategy(Strategy s)
Definition: otbSampleAugmentationFilter.h:101
otbOGRDataSourceWrapper.h
otb::SampleAugmentationFilter::OGRDataSourcePointerType
OGRDataSourceType::Pointer OGRDataSourcePointerType
Definition: otbSampleAugmentationFilter.h:63