21 #ifndef otbEstimateInnerProductPCAImageFilter_hxx
22 #define otbEstimateInnerProductPCAImageFilter_hxx
26 #include <vnl/algo/vnl_generalized_eigensystem.h>
27 #include <vnl/vnl_math.h>
35 template <
class TInputImage,
class TOutputImage>
37 : m_NumberOfPrincipalComponentsRequired(1), m_CenterData(true)
39 this->DynamicMultiThreadingOn();
45 template <
class TInputImage,
class TOutputImage>
48 this->Superclass::PrintSelf(os, indent);
54 template <
class TInputImage,
class TOutputImage>
57 Superclass::GenerateOutputInformation();
58 this->GetOutput()->SetNumberOfComponentsPerPixel(m_NumberOfPrincipalComponentsRequired);
65 template <
class TInputImage,
class TOutputImage>
70 streamingInnerProduct->SetInput(
const_cast<InputImageType*
>(this->GetInput()));
71 streamingInnerProduct->SetCenterData(m_CenterData);
72 streamingInnerProduct->Update();
73 m_InnerProduct = streamingInnerProduct->GetInnerProduct();
76 MatrixType identityMatrix(m_InnerProduct.rows(), m_InnerProduct.columns());
77 identityMatrix.set_identity();
78 vnl_generalized_eigensystem eigenVectors_eigenValues(m_InnerProduct, identityMatrix);
79 m_EigenVectorsOfInnerProductMatrix = eigenVectors_eigenValues.V;
82 template <
class TInputImage,
class TOutputImage>
85 typename InputImageType::ConstPointer inputPtr = this->GetInput();
86 typename OutputImageType::Pointer outputPtr = this->GetOutput();
91 unsigned int numberOfTrainingImages = inputPtr->GetNumberOfComponentsPerPixel();
94 this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread);
97 itk::ImageRegionConstIterator<TInputImage> inputIt(inputPtr, inputRegionForThread);
98 itk::ImageRegionIterator<TOutputImage> outputIt(outputPtr, outputRegionForThread);
101 outputIt.GoToBegin();
103 while (!inputIt.IsAtEnd())
107 outputPixel.SetSize(m_NumberOfPrincipalComponentsRequired);
110 for (
unsigned int img_number = 0; img_number < numberOfTrainingImages; ++img_number)
112 unsigned int indexNumberOfTrainingImages = numberOfTrainingImages - 1;
113 for (
unsigned int vec_number = 0; vec_number < m_NumberOfPrincipalComponentsRequired; ++vec_number, indexNumberOfTrainingImages--)
116 static_cast<double>(inputPixel[img_number]) *
static_cast<double>(m_EigenVectorsOfInnerProductMatrix[img_number][indexNumberOfTrainingImages]));
119 outputIt.Set(outputPixel);
OutputImageType::InternalPixelType OutputInternalPixelType
OutputImageType::RegionType OutputImageRegionType
InputImageType::RegionType InputImageRegionType
void BeforeThreadedGenerateData() override
OutputImageType::PixelType OutputPixelType
StreamingInnerProductType::Pointer StreamingInnerProductPointer
EstimateInnerProductPCAImageFilter()
void GenerateOutputInformation(void) override
InputImageType::PixelType InputPixelType
TInputImage InputImageType
void PrintSelf(std::ostream &os, itk::Indent indent) const override
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) override
StreamingInnerProductType::MatrixType MatrixType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.