OTB  5.4.0
Orfeo Toolbox
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"
26 
27 namespace otb
28 {
29 
43 template< class TInput1, class TInput2>
44 class ITK_EXPORT MRFEnergyFisherClassification: public MRFEnergy< TInput1, TInput2>
45 {
46 public:
51 
52  typedef TInput1 InputImageType;
53  typedef TInput2 LabelledImageType;
54  typedef typename InputImageType::PixelType InputImagePixelType;
55  typedef typename LabelledImageType::PixelType LabelledImagePixelType;
57 
58  itkNewMacro(Self);
60 
61  void SetNumberOfParameters(const unsigned int nParameters)
62  {
63  Superclass::SetNumberOfParameters(nParameters);
64  this->m_Parameters.SetSize(nParameters);
65  this->Modified();
66  }
67 
68  double GetSingleValue(const InputImagePixelType & value1, const LabelledImagePixelType & value2)
69  {
70  if ((unsigned int)value2 >= this->GetNumberOfParameters()/3)
71  {
72  itkExceptionMacro(<<"Number of parameters does not correspond to number of classes" );
73  }
74  double val1 = static_cast<double>(value1);
75  double mu = this->m_Parameters[3*value2];
76  double l = this->m_Parameters[3*value2+1];
77  double m = this->m_Parameters[3*value2+2];
78 
79  double result = -vcl_log((boost::math::tgamma(l+m)/(boost::math::tgamma(l)*boost::math::tgamma(m)))
80  * (2/(mu)) * (vcl_sqrt(l/m)) *
81  ((vcl_pow((vcl_sqrt(l/m)*(val1/mu)), ((2*l)-1))) /
82  (vcl_pow(1+(vcl_sqrt(l/m)*(val1/mu)*vcl_sqrt(l/m)*(val1/mu)), (l+m)))));
83 
84  return result;
85  }
86 
87 protected:
88  // The constructor and destructor.
91 };
92 }
93 #endif
double GetSingleValue(const InputImagePixelType &value1, const LabelledImagePixelType &value2)
Fisher model for Markov classification.
InputImageType::PixelType InputImagePixelType
Definition: otbMRFEnergy.h:50
void SetNumberOfParameters(const unsigned int nParameters)
This is the base class for energy function used in the MRF framework.
Definition: otbMRFEnergy.h:40
LabelledImageType::PixelType LabelledImagePixelType
Definition: otbMRFEnergy.h:51