diff --git a/Code/Markov/otbMRFEnergyFisherClassification.h b/Code/Markov/otbMRFEnergyFisherClassification.h index babdf3762c44fe38f88eed2679499b36f9086620..8f702e63f18a15f68fd08d215590647528923875 100644 --- a/Code/Markov/otbMRFEnergyFisherClassification.h +++ b/Code/Markov/otbMRFEnergyFisherClassification.h @@ -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 diff --git a/Testing/Code/Common/otbGammaTest.cxx b/Testing/Code/Common/otbGammaTest.cxx index 9b197b12c3ff2b3092d7ff31bd1a21d98b2caafb..9fba84aa07988539ada57420c0bcf95d2abf7894 100644 --- a/Testing/Code/Common/otbGammaTest.cxx +++ b/Testing/Code/Common/otbGammaTest.cxx @@ -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; }