21 #ifndef otbNAPCAImageFilter_hxx
22 #define otbNAPCAImageFilter_hxx
27 #include <vnl/vnl_matrix.h>
28 #include <vnl/algo/vnl_matrix_inverse.h>
29 #include <vnl/algo/vnl_symmetric_eigensystem.h>
30 #include <vnl/algo/vnl_generalized_eigensystem.h>
35 template <
class TInputImage,
class TOutputImage,
class TNoiseImageFilter, Transform::TransformDirection TDirectionOfTransformation>
40 vnl_vector<double> vectValPn;
41 vnl_symmetric_eigensystem_compute(An, Fn, vectValPn);
45 for (
unsigned int i = 0; i < valPn.rows(); ++i)
47 if (vectValPn[i] > 0.)
49 valPn(i, i) = 1. / std::sqrt(vectValPn[i]);
51 else if (vectValPn[i] < 0.)
53 otbMsgDebugMacro(<<
"ValPn(" << i <<
") neg : " << vectValPn[i] <<
" taking abs value");
54 valPn(i, i) = 1. / std::sqrt(std::abs(vectValPn[i]));
58 throw itk::ExceptionObject(__FILE__, __LINE__,
"Null Eigen value !!", ITK_LOCATION);
63 InternalMatrixType Ax = vnl_matrix_inverse<MatrixElementType>(this->GetCovarianceMatrix().GetVnlMatrix());
67 vnl_vector<double> vectValPadj;
68 vnl_symmetric_eigensystem_compute(Aadj, Fadj, vectValPadj);
71 transf.inplace_transpose();
73 if (this->GetNumberOfPrincipalComponentsRequired() != this->GetInput()->GetNumberOfComponentsPerPixel())
74 this->m_TransformationMatrix = transf.get_n_rows(0, this->GetNumberOfPrincipalComponentsRequired());
76 this->m_TransformationMatrix = transf;
78 this->m_EigenValues.SetSize(this->GetNumberOfPrincipalComponentsRequired());
79 for (
unsigned int i = 0; i < this->GetNumberOfPrincipalComponentsRequired(); ++i)
80 this->m_EigenValues[this->GetNumberOfPrincipalComponentsRequired() - 1 - i] =
static_cast<RealType>(vectValPadj[i]);