OTB  10.0.0
Orfeo Toolbox
otbSEMClassifier.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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
This class implements the Stochastic Expectation Maximization algorithm to perform an estimation of a...
SEMClassifier Self
std::vector< double > ProportionVectorType
itk::SmartPointer< Self > Pointer
ComponentType::Pointer ComponentPointerType
TerminationCodeType m_TerminationCode
std::vector< double > ProbaVectorType
SampleType::MeasurementVectorType MeasurementVectorType
OutputType::Pointer m_Output
ClassLabelVectorType m_ClassLabels
SampleType::MeasurementType MeasurementType
unsigned int ClassLabelType
std::vector< ComponentPointerType > ComponentVectorType
ProportionVectorType m_Proportions
itk::Statistics::ListSample< typename TInputImage::PixelType > SampleType
std::vector< ParameterType > ParameterVectorType
TOutputImage::Pointer m_OutputImage
ProportionVectorType m_InitialProportions
std::vector< ProbaVectorType > ProbaByClassVectorType
itk::SmartPointer< const Self > ConstPointer
std::vector< ClassLabelType > ClassLabelVectorType
itk::Statistics::SampleClassifierFilter< typename itk::Statistics::ListSample< typename TInputImage::PixelType > > Superclass
ComponentVectorType m_ComponentVector
itk::Statistics::MembershipSample< SampleType > OutputType
otb::Statistics::ModelComponentBase< ClassSampleType > ComponentType
itk::Statistics::Subsample< SampleType > ClassSampleType
itk::Array< double > ParameterType
const TInputImage * m_Sample
ProbaByClassVectorType m_Proba
SampleType::Pointer m_SampleList
base class for distribution representation that supports analytical way to update the distribution pa...
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.