OTB  9.0.0
Orfeo Toolbox
otbSEMClassifier.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  * Copyright (C) 2007-2012 Institut Mines Telecom / Telecom Bretagne
4  *
5  * This file is part of Orfeo Toolbox
6  *
7  * https://www.orfeo-toolbox.org/
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 #ifndef otbSEMClassifier_h
23 #define otbSEMClassifier_h
24 
25 #include "itkListSample.h"
26 #include "itkSampleClassifierFilter.h"
27 
28 
30 
31 namespace otb
32 {
33 
63 template <class TInputImage, class TOutputImage>
64 class ITK_EXPORT SEMClassifier : public itk::Statistics::SampleClassifierFilter<typename itk::Statistics::ListSample<typename TInputImage::PixelType>>
65 {
66 public:
69  typedef itk::Statistics::SampleClassifierFilter<typename itk::Statistics::ListSample<typename TInputImage::PixelType>> Superclass;
70  typedef itk::SmartPointer<Self> Pointer;
71  typedef itk::SmartPointer<const Self> ConstPointer;
72 
74  itkTypeMacro(SEMClassifier, itk::Object);
75  itkNewMacro(Self);
77 
79  typedef typename itk::Statistics::ListSample<typename TInputImage::PixelType> SampleType;
80  typedef typename itk::Statistics::Subsample<SampleType> ClassSampleType;
81 
82  typedef typename SampleType::MeasurementType MeasurementType;
83  typedef typename SampleType::MeasurementVectorType MeasurementVectorType;
84 
86  typedef unsigned int ClassLabelType;
87  typedef std::vector<ClassLabelType> ClassLabelVectorType;
88 
90  typedef itk::Statistics::MembershipSample<SampleType> OutputType;
91 
98 
100  typedef std::vector<ComponentPointerType> ComponentVectorType;
101 
103  typedef itk::Array<double> ParameterType;
104 
106  typedef std::vector<ParameterType> ParameterVectorType;
107 
109  typedef std::vector<double> ProportionVectorType;
110  typedef std::vector<double> ProbaVectorType;
111 
113  typedef std::vector<ProbaVectorType> ProbaByClassVectorType;
114 
116  void SetSample(const TInputImage* sample);
117 
119  const TInputImage* GetSample() const;
120  SampleType* GetSampleList() const;
122 
127  void SetInitialProportions(ProportionVectorType& proportions);
128  itkGetConstReferenceMacro(InitialProportions, ProportionVectorType);
130 
132  itkGetConstReferenceMacro(Proportions, ProportionVectorType);
133 
136  void SetClassLabels(OutputType* labels);
137  void SetClassLabels(TOutputImage* imgLabels);
138  ClassLabelVectorType& GetClassLabels();
140 
145  itkSetMacro(MaximumIteration, int);
146  itkGetMacro(MaximumIteration, int);
148 
151  void SetNeighborhood(int neighborhood);
152  int GetNeighborhood();
154 
156  int GetCurrentIteration();
157 
159  int AddComponent(int id, ComponentType* component);
160 
162  void Update() override;
163 
165  typedef enum { CONVERGED = 0, NOT_CONVERGED = 1 } TerminationCodeType;
166 
170  itkSetMacro(TerminationThreshold, double);
171  itkGetMacro(TerminationThreshold, double);
173 
175  itkGetMacro(TerminationCode, TerminationCodeType);
176 
177  /* Return the classification result (as a standard classification result) */
178  OutputType* GetOutput();
179 
180  /* Return the classification result (as an image) */
181  TOutputImage* GetOutputImage();
182 
183  void Modified() const override;
184 
185 protected:
186  SEMClassifier();
187  ~SEMClassifier() override
188  {
189  }
190  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
191 
194  void InitParameters();
195 
197  void PerformStochasticProcess();
198 
200  void PerformExpectationProcess();
201 
205  void PerformMaximizationProcess();
206 
208  void GetMaximumAposterioriLabels();
209 
210 private:
212  const TInputImage* m_Sample;
214  typename SampleType::Pointer m_SampleList;
215 
221 
228 
230  mutable int m_ComponentDeclared;
231 
232  typename TOutputImage::Pointer m_OutputImage;
233  typename OutputType::Pointer m_Output;
234 }; // end of class
235 
236 } // end of namespace
237 
238 #ifndef OTB_MANUAL_INSTANTIATION
239 #include "otbSEMClassifier.hxx"
240 #endif
241 
242 #endif
otb::SEMClassifier::Superclass
itk::Statistics::SampleClassifierFilter< typename itk::Statistics::ListSample< typename TInputImage::PixelType > > Superclass
Definition: otbSEMClassifier.h:69
otb::SEMClassifier::TerminationCodeType
TerminationCodeType
Definition: otbSEMClassifier.h:165
otb::SEMClassifier::ComponentType
otb::Statistics::ModelComponentBase< ClassSampleType > ComponentType
Definition: otbSEMClassifier.h:95
otb::SEMClassifier::m_ExternalLabels
int m_ExternalLabels
Definition: otbSEMClassifier.h:229
otb::Statistics::ModelComponentBase
base class for distribution representation that supports analytical way to update the distribution pa...
Definition: otbModelComponentBase.h:65
otb::SEMClassifier::MeasurementType
SampleType::MeasurementType MeasurementType
Definition: otbSEMClassifier.h:82
otb::SEMClassifier::m_TerminationCode
TerminationCodeType m_TerminationCode
Definition: otbSEMClassifier.h:222
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::SEMClassifier::~SEMClassifier
~SEMClassifier() override
Definition: otbSEMClassifier.h:187
otb::SEMClassifier::m_Neighborhood
int m_Neighborhood
Definition: otbSEMClassifier.h:220
otb::SEMClassifier::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbSEMClassifier.h:71
otb::SEMClassifier::m_Proba
ProbaByClassVectorType m_Proba
Definition: otbSEMClassifier.h:226
otb::SEMClassifier::m_ComponentDeclared
int m_ComponentDeclared
Definition: otbSEMClassifier.h:230
otb::SEMClassifier::m_SampleList
SampleType::Pointer m_SampleList
Definition: otbSEMClassifier.h:214
otb::SEMClassifier::ComponentVectorType
std::vector< ComponentPointerType > ComponentVectorType
Definition: otbSEMClassifier.h:100
otb::SEMClassifier::ClassLabelVectorType
std::vector< ClassLabelType > ClassLabelVectorType
Definition: otbSEMClassifier.h:87
otb::SEMClassifier::m_NbChange
int m_NbChange
Definition: otbSEMClassifier.h:218
otbSEMClassifier.hxx
otb::SEMClassifier::ClassSampleType
itk::Statistics::Subsample< SampleType > ClassSampleType
Definition: otbSEMClassifier.h:80
otb::SEMClassifier::ParameterType
itk::Array< double > ParameterType
Definition: otbSEMClassifier.h:103
otbGaussianModelComponent.h
otb::SEMClassifier::m_TerminationThreshold
double m_TerminationThreshold
Definition: otbSEMClassifier.h:219
otb::SEMClassifier::ComponentPointerType
ComponentType::Pointer ComponentPointerType
Definition: otbSEMClassifier.h:96
otb::SEMClassifier::m_Proportions
ProportionVectorType m_Proportions
Definition: otbSEMClassifier.h:225
otb::SEMClassifier::m_ComponentVector
ComponentVectorType m_ComponentVector
Definition: otbSEMClassifier.h:223
otb::SEMClassifier::m_Sample
const TInputImage * m_Sample
Definition: otbSEMClassifier.h:212
otb::SEMClassifier::ParameterVectorType
std::vector< ParameterType > ParameterVectorType
Definition: otbSEMClassifier.h:106
otb::SEMClassifier::m_OutputImage
TOutputImage::Pointer m_OutputImage
Definition: otbSEMClassifier.h:232
otb::SEMClassifier::m_Output
OutputType::Pointer m_Output
Definition: otbSEMClassifier.h:233
otb::SEMClassifier::ProbaVectorType
std::vector< double > ProbaVectorType
Definition: otbSEMClassifier.h:110
otb::SEMClassifier::m_CurrentIteration
int m_CurrentIteration
Definition: otbSEMClassifier.h:217
otb::SEMClassifier::m_InitialProportions
ProportionVectorType m_InitialProportions
Definition: otbSEMClassifier.h:224
otb::SEMClassifier::OutputType
itk::Statistics::MembershipSample< SampleType > OutputType
Definition: otbSEMClassifier.h:90
otb::SEMClassifier::SampleType
itk::Statistics::ListSample< typename TInputImage::PixelType > SampleType
Definition: otbSEMClassifier.h:75
otb::SEMClassifier::ProportionVectorType
std::vector< double > ProportionVectorType
Definition: otbSEMClassifier.h:109
otb::Statistics::ModelComponentBase::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbModelComponentBase.h:71
otb::SEMClassifier::Self
SEMClassifier Self
Definition: otbSEMClassifier.h:68
otb::SEMClassifier::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbSEMClassifier.h:70
otb::SEMClassifier::m_NbSamples
int m_NbSamples
Definition: otbSEMClassifier.h:213
otb::SEMClassifier::ClassLabelType
unsigned int ClassLabelType
Definition: otbSEMClassifier.h:86
otb::SEMClassifier::ProbaByClassVectorType
std::vector< ProbaVectorType > ProbaByClassVectorType
Definition: otbSEMClassifier.h:113
otb::SEMClassifier::m_MaximumIteration
int m_MaximumIteration
Definition: otbSEMClassifier.h:216
otb::SEMClassifier
This class implements the Stochastic Expectation Maximization algorithm to perform an estimation of a...
Definition: otbSEMClassifier.h:64
otb::SEMClassifier::m_ClassLabels
ClassLabelVectorType m_ClassLabels
Definition: otbSEMClassifier.h:227
otb::SEMClassifier::MeasurementVectorType
SampleType::MeasurementVectorType MeasurementVectorType
Definition: otbSEMClassifier.h:83