Orfeo ToolBox  4.2
Orfeo ToolBox is not a black box
otbMRFEnergyFisherClassification.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12  This code is from a Jan Wegner contribution.
13 
14 
15  This software is distributed WITHOUT ANY WARRANTY; without even
16  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17  PURPOSE. See the above copyright notices for more information.
18 
19 =========================================================================*/
20 #ifndef __otbMRFEnergyFisherClassification_h
21 #define __otbMRFEnergyFisherClassification_h
22 
23 #include "otbMRFEnergy.h"
24 #include "otbMath.h"
25 #include <boost/math/special_functions/gamma.hpp>
26 
27 namespace otb
28 {
29 
41 template< class TInput1, class TInput2>
42 class ITK_EXPORT MRFEnergyFisherClassification: public MRFEnergy< TInput1, TInput2>
43 {
44 public:
49 
50  typedef TInput1 InputImageType;
51  typedef TInput2 LabelledImageType;
52  typedef typename InputImageType::PixelType InputImagePixelType;
53  typedef typename LabelledImageType::PixelType LabelledImagePixelType;
55 
56  itkNewMacro(Self);
58 
59  void SetNumberOfParameters(const unsigned int nParameters)
60  {
61  Superclass::SetNumberOfParameters(nParameters);
62  this->m_Parameters.SetSize(nParameters);
63  this->Modified();
64  }
65 
66  double GetSingleValue(const InputImagePixelType & value1, const LabelledImagePixelType & value2)
67  {
68  if ((unsigned int)value2 >= this->GetNumberOfParameters()/3)
69  {
70  itkExceptionMacro(<<"Number of parameters does not correspond to number of classes" );
71  }
72  double val1 = static_cast<double>(value1);
73  double mu = this->m_Parameters[3*value2];
74  double l = this->m_Parameters[3*value2+1];
75  double m = this->m_Parameters[3*value2+2];
76 
77  double result = -vcl_log((boost::math::tgamma(l+m)/(boost::math::tgamma(l)*boost::math::tgamma(m)))
78  * (2/(mu)) * (vcl_sqrt(l/m)) *
79  ((vcl_pow((vcl_sqrt(l/m)*(val1/mu)), ((2*l)-1))) /
80  (vcl_pow(1+(vcl_sqrt(l/m)*(val1/mu)*vcl_sqrt(l/m)*(val1/mu)), (l+m)))));
81 
82  return result;
83  }
84 
85 protected:
86  // The constructor and destructor.
89 };
90 }
91 #endif
double GetSingleValue(const InputImagePixelType &value1, const LabelledImagePixelType &value2)
Fisher model for Markov classification.
InputImageType::PixelType InputImagePixelType
Definition: otbMRFEnergy.h:48
void SetNumberOfParameters(const unsigned int nParameters)
This is the base class for energy function used in the MRF framework.
Definition: otbMRFEnergy.h:38
LabelledImageType::PixelType LabelledImagePixelType
Definition: otbMRFEnergy.h:49