21 #ifndef otbNormalizeInnerProductPCAImageFilter_hxx
22 #define otbNormalizeInnerProductPCAImageFilter_hxx
25 #include "itkImageRegionIterator.h"
26 #include "itkNumericTraits.h"
34 template <
class TInputImage,
class TOutputImage>
37 this->SetNumberOfRequiredInputs(1);
38 this->SetNumberOfRequiredOutputs(1);
40 this->DynamicMultiThreadingOn();
41 m_UseUnbiasedEstimator =
true;
48 template <
class TInputImage,
class TOutputImage>
51 Superclass::GenerateOutputInformation();
57 template <
class TInputImage,
class TOutputImage>
63 stats->SetUseUnbiasedEstimator(m_UseUnbiasedEstimator);
70 double NbPixels =
static_cast<double>(this->GetInput()->GetLargestPossibleRegion().GetSize()[0] * this->GetInput()->GetLargestPossibleRegion().GetSize()[1]);
71 if ((cov.Rows() != means.Size()) || (cov.Cols() != means.Size()))
73 itkExceptionMacro(<<
"Covariance matrix with size (" << cov.Rows() <<
"," << cov.Cols() <<
") is incompatible with mean vector with size" << means.Size());
75 m_CoefNorm.SetSize(means.Size());
76 for (
unsigned int i = 0; i < m_CoefNorm.Size(); ++i)
78 m_CoefNorm[i] = (1. / std::sqrt(NbPixels * (cov[i][i] + means[i] * means[i])));
84 template <
class TInputImage,
class TOutputImage>
87 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
88 typename Superclass::InputImageConstPointer inputPtr = this->GetInput();
92 itk::ImageRegionConstIterator<InputImageType> inputIt(inputPtr, outputRegionForThread);
93 itk::ImageRegionIterator<OutputImageType> outputIt(outputPtr, outputRegionForThread);
100 nullPixel.SetSize(inputPtr->GetNumberOfComponentsPerPixel());
101 nullPixel.Fill(itk::NumericTraits<OutputInternalPixelType>::Zero);
102 while (!inputIt.IsAtEnd())
106 outPixel.SetSize(inputPtr->GetNumberOfComponentsPerPixel());
107 outPixel.Fill(itk::NumericTraits<OutputInternalPixelType>::Zero);
109 for (
unsigned int j = 0; j < inputPtr->GetNumberOfComponentsPerPixel(); ++j)
114 outputIt.Set(outPixel);
120 template <
class TInputImage,
class TOutputImage>
123 this->Superclass::PrintSelf(os, indent);
void GenerateOutputInformation() override
StreamingStatisticsVectorImageFilterType::RealPixelType RealPixelType
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) override
InputImageType::PixelType InputPixelType
OutputImageType::InternalPixelType OutputInternalPixelType
NormalizeInnerProductPCAImageFilter()
OutputImageType::RegionType OutputImageRegionType
TInputImage InputImageType
OutputImageType::PixelType OutputPixelType
void BeforeThreadedGenerateData() override
void PrintSelf(std::ostream &os, itk::Indent indent) const override
StreamingStatisticsVectorImageFilterType::MatrixType MatrixType
StreamingStatisticsVectorImageFilterType::Pointer StreamingStatisticsVectorImageFilterPointer
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.