21 #ifndef otbNormalizeInnerProductPCAImageFilter_hxx
22 #define otbNormalizeInnerProductPCAImageFilter_hxx
25 #include "itkImageRegionIterator.h"
26 #include "itkProgressReporter.h"
27 #include "itkNumericTraits.h"
35 template <
class TInputImage,
class TOutputImage>
38 this->SetNumberOfRequiredInputs(1);
39 this->SetNumberOfRequiredOutputs(1);
43 m_UseUnbiasedEstimator =
true;
49 template <
class TInputImage,
class TOutputImage>
52 Superclass::GenerateOutputInformation();
58 template <
class TInputImage,
class TOutputImage>
64 stats->SetUseUnbiasedEstimator(m_UseUnbiasedEstimator);
71 double NbPixels =
static_cast<double>(this->GetInput()->GetLargestPossibleRegion().GetSize()[0] * this->GetInput()->GetLargestPossibleRegion().GetSize()[1]);
72 if ((cov.Rows() != means.Size()) || (cov.Cols() != means.Size()))
74 itkExceptionMacro(<<
"Covariance matrix with size (" << cov.Rows() <<
"," << cov.Cols() <<
") is incompatible with mean vector with size" << means.Size());
76 m_CoefNorm.SetSize(means.Size());
77 for (
unsigned int i = 0; i < m_CoefNorm.Size(); ++i)
79 m_CoefNorm[i] = (1. / std::sqrt(NbPixels * (cov[i][i] + means[i] * means[i])));
85 template <
class TInputImage,
class TOutputImage>
87 itk::ThreadIdType threadId)
89 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
90 typename Superclass::InputImageConstPointer inputPtr = this->GetInput();
94 itk::ImageRegionConstIterator<InputImageType> inputIt(inputPtr, outputRegionForThread);
95 itk::ImageRegionIterator<OutputImageType> outputIt(outputPtr, outputRegionForThread);
97 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
100 outputIt.GoToBegin();
104 nullPixel.SetSize(inputPtr->GetNumberOfComponentsPerPixel());
105 nullPixel.Fill(itk::NumericTraits<OutputInternalPixelType>::Zero);
106 while (!inputIt.IsAtEnd())
110 outPixel.SetSize(inputPtr->GetNumberOfComponentsPerPixel());
111 outPixel.Fill(itk::NumericTraits<OutputInternalPixelType>::Zero);
113 for (
unsigned int j = 0; j < inputPtr->GetNumberOfComponentsPerPixel(); ++j)
118 outputIt.Set(outPixel);
121 progress.CompletedPixel();
125 template <
class TInputImage,
class TOutputImage>
128 this->Superclass::PrintSelf(os, indent);