18 #ifndef __otbNormalizeInnerProductPCAImageFilter_txx
19 #define __otbNormalizeInnerProductPCAImageFilter_txx
25 #include "itkNumericTraits.h"
33 template <
class TInputImage,
class TOutputImage>
37 this->SetNumberOfRequiredInputs(1);
38 this->SetNumberOfRequiredOutputs(1);
41 m_UseUnbiasedEstimator =
true;
47 template<
class TInputImage,
class TOutputImage>
52 Superclass::GenerateOutputInformation();
58 template <
class TInputImage,
class TOutputImage>
64 stats->SetInput(const_cast<InputImageType*>(this->GetInput()));
66 stats->SetUseUnbiasedEstimator(m_UseUnbiasedEstimator);
72 double NbPixels =
static_cast<double>(
73 this->GetInput()->GetLargestPossibleRegion().GetSize()[0] *
74 this->GetInput()->GetLargestPossibleRegion().GetSize()[1]);
75 if ((cov.Rows() != means.
Size()) || (cov.Cols() != means.
Size()))
77 itkExceptionMacro(<<
"Covariance matrix with size (" << cov.Rows() <<
"," <<
78 cov.Cols() <<
") is incompatible with mean vector with size" << means.
Size());
80 m_CoefNorm.SetSize(means.
Size());
81 for (
unsigned int i = 0; i < m_CoefNorm.Size(); ++i)
83 m_CoefNorm[i] = (1. / vcl_sqrt(NbPixels * (cov[i][i] + means[i] * means[i])));
89 template <
class TInputImage,
class TOutputImage>
108 nullPixel.SetSize(inputPtr->GetNumberOfComponentsPerPixel());
109 nullPixel.Fill(itk::NumericTraits<OutputInternalPixelType>::Zero);
114 outPixel.SetSize(inputPtr->GetNumberOfComponentsPerPixel());
115 outPixel.Fill(itk::NumericTraits<OutputInternalPixelType>::Zero);
117 for (
unsigned int j = 0; j < inputPtr->GetNumberOfComponentsPerPixel(); ++j)
122 outputIt.
Set(outPixel);
125 progress.CompletedPixel();
129 template <
class TInputImage,
class TOutputImage>
134 this->Superclass::PrintSelf(os, indent);