Skip to content
Snippets Groups Projects
Commit 8c71a0e7 authored by Emmanuel Christophe's avatar Emmanuel Christophe
Browse files

STYLE: and fix test for gamma

parent 99100bc7
Branches
Tags
No related merge requests found
......@@ -27,62 +27,65 @@
namespace otb
{
/*
\* class MRFEnergyFisherClassification
\* This is the implementation of the Fisher model for Markov classification
\* to be used for the fidelity (likelihood) term for the classification.
\*
\* This class is meant to be used in the MRF framework with the otb:: MarkovRandomFieldFilter
/**
* \class MRFEnergyFisherClassification
* \brief Fisher model for Markov classification
*
* This is the implementation of the Fisher model for Markov classification
* to be used for the fidelity (likelihood) term for the classification.
*
* This class is meant to be used in the MRF framework with the
* otb::MarkovRandomFieldFilter
*
*/
template< class TInput1, class TInput2>
class ITK_EXPORT MRFEnergyFisherClassification:public MRFEnergy< TInput1, TInput2>
class ITK_EXPORT MRFEnergyFisherClassification: public MRFEnergy< TInput1, TInput2>
{
public:
typedef MRFEnergyFisherClassification Self;
typedef MRFEnergy< TInput1, TInput2> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef TInput1 InputImageType;
typedef TInput2 LabelledImageType;
typedef typename InputImageType::PixelType InputImagePixelType;
typedef typename LabelledImageType::PixelType LabelledImagePixelType;
typedef itk::Array < double > ParametersType;
itkNewMacro(Self);
itkTypeMacro(MRFEnergyFisherClassification, MRFEnergy);
Gamma g;
void SetNumberOfParameters(const unsigned int nParameters)
{
Superclass::SetNumberOfParameters(nParameters);
this->m_Parameters.SetSize(nParameters);
this->Modified();
}
double GetSingleValue(const InputImagePixelType & value1, const LabelledImagePixelType & value2)
{
if ((unsigned int)value2 >= this->GetNumberOfParameters()/3)
{
itkExceptionMacro(<<"Number of parameters does not correspond to number of classes" );
}
double val1 = static_cast<double>(value1);
double mu = this->m_Parameters[3*static_cast<double>(value2)];
double l = this->m_Parameters[3*static_cast<double>(value2)+1];
double m = this->m_Parameters[3*static_cast<double>(value2)+2];
double result = -vcl_log((g.gamma(l+m)/(g.gamma(l)*g.gamma(m))) * (2/(mu)) * (vcl_sqrt(l/m)) *
((pow((vcl_sqrt(l/m)*(val1/mu)), ((2*l)-1))) /
(pow(1+(vcl_sqrt(l/m)*(val1/mu)*vcl_sqrt(l/m)*(val1/mu)), (l+m)))));
return static_cast<double>( result );
}
typedef MRFEnergyFisherClassification Self;
typedef MRFEnergy< TInput1, TInput2> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef TInput1 InputImageType;
typedef TInput2 LabelledImageType;
typedef typename InputImageType::PixelType InputImagePixelType;
typedef typename LabelledImageType::PixelType LabelledImagePixelType;
typedef itk::Array < double > ParametersType;
itkNewMacro(Self);
itkTypeMacro(MRFEnergyFisherClassification, MRFEnergy);
Gamma g;
void SetNumberOfParameters(const unsigned int nParameters)
{
Superclass::SetNumberOfParameters(nParameters);
this->m_Parameters.SetSize(nParameters);
this->Modified();
}
double GetSingleValue(const InputImagePixelType & value1, const LabelledImagePixelType & value2)
{
if ((unsigned int)value2 >= this->GetNumberOfParameters()/3)
{
itkExceptionMacro(<<"Number of parameters does not correspond to number of classes" );
}
double val1 = static_cast<double>(value1);
double mu = this->m_Parameters[3*static_cast<double>(value2)];
double l = this->m_Parameters[3*static_cast<double>(value2)+1];
double m = this->m_Parameters[3*static_cast<double>(value2)+2];
double result = -vcl_log((g.gamma(l+m)/(g.gamma(l)*g.gamma(m))) * (2/(mu)) * (vcl_sqrt(l/m)) *
((pow((vcl_sqrt(l/m)*(val1/mu)), ((2*l)-1))) /
(pow(1+(vcl_sqrt(l/m)*(val1/mu)*vcl_sqrt(l/m)*(val1/mu)), (l+m)))));
return static_cast<double>( result );
}
protected:
// The constructor and destructor.
MRFEnergyFisherClassification() {};
virtual ~MRFEnergyFisherClassification() {};
// The constructor and destructor.
MRFEnergyFisherClassification() {};
virtual ~MRFEnergyFisherClassification() {};
};
}
#endif
......@@ -28,10 +28,13 @@ int otbGammaTest(int argc, char * argv[])
//Instantiation
GammaFunctionType * gam = new GammaFunctionType();
const double epsilon = 0.0000000001;
int output = EXIT_SUCCESS;
if ( vcl_abs(gam->gamma(1) - 1) > epsilon ) return EXIT_FAILURE;
if ( vcl_abs(gam->gamma(0.5) - 1.77245385091) > epsilon ) return EXIT_FAILURE;
if ( vcl_abs(gam->gamma(4) - 6) > epsilon ) return EXIT_FAILURE;
if ( vcl_abs(gam->gamma(1) - 1) > epsilon ) output = EXIT_FAILURE;
if ( vcl_abs(gam->gamma(0.5) - 1.77245385091) > epsilon ) output = EXIT_FAILURE;
if ( vcl_abs(gam->gamma(4) - 6) > epsilon ) output = EXIT_FAILURE;
return EXIT_SUCCESS;
delete gam;
return output;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment