22 #ifndef otbEigenvalueLikelihoodMaximisation_hxx
23 #define otbEigenvalueLikelihoodMaximisation_hxx
32 template <
class TPrecision>
37 template <
class TInputImage>
41 const unsigned int nbBands = m_Covariance.rows();
44 vnl_symmetric_eigensystem<PrecisionType> eigenK(m_Covariance);
45 VectorType eigenCovariance = eigenK.D.diagonal();
46 std::sort(eigenCovariance.begin(), eigenCovariance.end());
47 eigenCovariance.flip();
49 vnl_symmetric_eigensystem<PrecisionType> eigenR(m_Correlation);
50 VectorType eigenCorrelation = eigenR.D.diagonal();
51 std::sort(eigenCorrelation.begin(), eigenCorrelation.end());
52 eigenCorrelation.flip();
55 m_Likelihood.set_size(nbBands);
56 const double coef = 2.0 / m_NumberOfPixels;
58 for (
unsigned int i = 0; i < nbBands; ++i)
60 const unsigned int nl = nbBands - i;
63 for (
unsigned int j = 0; j < nl; ++j)
68 sigma[j] = coef * (r * r + k * k);
70 t[j] = (r - k) * (r - k) / sigma[j];
72 sigma[j] = std::log(sigma[j]);
74 m_Likelihood(i) = -0.5 * t.sum() - 0.5 * sigma.sum();
79 unsigned int iMax = 0;
80 for (
unsigned int i = 1; i < m_Likelihood.size() - 1; ++i)
82 if ((m_Likelihood[i] > m_Likelihood[i - 1]) && (m_Likelihood[i] > m_Likelihood[i + 1]))
89 m_NumberOfEndmembers = iMax;
92 template <
class TImage>
95 Superclass::PrintSelf(os, indent);
97 os << indent <<
"Covariance: " << m_Covariance << std::endl;
98 os << indent <<
"Correlation: " << m_Correlation << std::endl;
99 os << indent <<
"NumberOfEndmembers: " << m_NumberOfEndmembers << std::endl;
100 os << indent <<
"Likelihood: " << m_Likelihood << std::endl;