OTB  9.0.0
Orfeo Toolbox
otbMRFEnergyGaussianClassification.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 otbMRFEnergyGaussianClassification_h
22 #define otbMRFEnergyGaussianClassification_h
23 
24 #include "otbMRFEnergy.h"
25 #include "otbMath.h"
26 
27 namespace otb
28 {
48 template <class TInput1, class TInput2>
49 class ITK_EXPORT MRFEnergyGaussianClassification : public MRFEnergy<TInput1, TInput2>
50 {
51 public:
54  typedef itk::SmartPointer<Self> Pointer;
55  typedef itk::SmartPointer<const Self> ConstPointer;
56 
57  typedef TInput1 InputImageType;
58  typedef TInput2 LabelledImageType;
59  typedef typename InputImageType::PixelType InputImagePixelType;
60  typedef typename LabelledImageType::PixelType LabelledImagePixelType;
61  typedef itk::Array<double> ParametersType;
62 
63  itkNewMacro(Self);
64 
66 
67  void SetNumberOfParameters(const unsigned int nParameters) override
68  {
69  Superclass::SetNumberOfParameters(nParameters);
70  this->m_Parameters.SetSize(nParameters);
71  this->Modified();
72  }
73 
74  double GetSingleValue(const InputImagePixelType& value1, const LabelledImagePixelType& value2) override
75  {
76  if ((unsigned int)value2 >= this->GetNumberOfParameters() / 2)
77  {
78  itkExceptionMacro(<< "Number of parameters does not correspond to number of classes");
79  }
80  double val1 = static_cast<double>(value1);
81 
82  double result =
83  vnl_math_sqr(val1 - this->m_Parameters[2 * static_cast<int>(value2)]) / (2 * vnl_math_sqr(this->m_Parameters[2 * static_cast<int>(value2) + 1])) +
84  std::log(std::sqrt(CONST_2PI) * this->m_Parameters[2 * static_cast<int>(value2) + 1]);
85 
86  return static_cast<double>(result);
87  }
88 
89 protected:
90  // The constructor and destructor.
93  {
94  }
95 };
96 }
97 
98 #endif
otb::MRFEnergyGaussianClassification::MRFEnergyGaussianClassification
MRFEnergyGaussianClassification()
Definition: otbMRFEnergyGaussianClassification.h:91
otb::MRFEnergyGaussianClassification::~MRFEnergyGaussianClassification
~MRFEnergyGaussianClassification() override
Definition: otbMRFEnergyGaussianClassification.h:92
otb::MRFEnergyGaussianClassification::InputImageType
TInput1 InputImageType
Definition: otbMRFEnergyGaussianClassification.h:57
otb::MRFEnergyGaussianClassification::SetNumberOfParameters
void SetNumberOfParameters(const unsigned int nParameters) override
Definition: otbMRFEnergyGaussianClassification.h:67
otbMath.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::MRFEnergyGaussianClassification::Self
MRFEnergyGaussianClassification Self
Definition: otbMRFEnergyGaussianClassification.h:52
otbMRFEnergy.h
otb::MRFEnergyGaussianClassification
This is the implementation of the Gaussian model for Markov classification.
Definition: otbMRFEnergyGaussianClassification.h:49
otb::CONST_2PI
constexpr double CONST_2PI
Definition: otbMath.h:55
otb::MRFEnergyGaussianClassification::Superclass
MRFEnergy< TInput1, TInput2 > Superclass
Definition: otbMRFEnergyGaussianClassification.h:53
otb::MRFEnergyGaussianClassification::InputImagePixelType
InputImageType::PixelType InputImagePixelType
Definition: otbMRFEnergyGaussianClassification.h:59
otb::MRFEnergyGaussianClassification::LabelledImagePixelType
LabelledImageType::PixelType LabelledImagePixelType
Definition: otbMRFEnergyGaussianClassification.h:60
otb::MRFEnergyGaussianClassification::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbMRFEnergyGaussianClassification.h:55
otb::MRFEnergy::LabelledImagePixelType
LabelledImageType::PixelType LabelledImagePixelType
Definition: otbMRFEnergy.h:54
otb::MRFEnergyGaussianClassification::GetSingleValue
double GetSingleValue(const InputImagePixelType &value1, const LabelledImagePixelType &value2) override
Definition: otbMRFEnergyGaussianClassification.h:74
otb::MRFEnergy::InputImagePixelType
InputImageType::PixelType InputImagePixelType
Definition: otbMRFEnergy.h:53
otb::MRFEnergyGaussianClassification::LabelledImageType
TInput2 LabelledImageType
Definition: otbMRFEnergyGaussianClassification.h:58
otb::MRFEnergyGaussianClassification::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbMRFEnergyGaussianClassification.h:54
otb::MRFEnergyGaussianClassification::ParametersType
itk::Array< double > ParametersType
Definition: otbMRFEnergyGaussianClassification.h:61
otb::MRFEnergy
This is the base class for energy function used in the MRF framework.
Definition: otbMRFEnergy.h:43