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