OTB  9.0.0
Orfeo Toolbox
otbInnerProductPCAImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbInnerProductPCAImageFilter_hxx
22 #define otbInnerProductPCAImageFilter_hxx
23 
25 
26 namespace otb
27 {
31 template <class TInputImage, class TOutputImage>
33 {
34  this->SetNumberOfRequiredOutputs(1);
35  this->SetNthOutput(0, OutputImageType::New());
36  m_EstimatePCAFilter = EstimatePCAFilterType::New();
37  m_NormalizePCAFilter = NormalizePCAFilterType::New();
38  m_NumberOfPrincipalComponentsRequired = 1;
39  m_CenterData = true;
40  m_GenerateMeanComponent = false;
41  m_MeanFilter = MeanFilterType::New();
42  m_CastFilter = CastFilterType::New();
43  m_ConcatenateFilter = ConcatenateFilterType::New();
44 }
45 
49 template <class TInputImage, class TOutputImage>
51 {
52  Superclass::GenerateOutputInformation();
53  if (m_GenerateMeanComponent == false)
54  this->GetOutput()->SetNumberOfComponentsPerPixel(m_NumberOfPrincipalComponentsRequired);
55  else
56  this->GetOutput()->SetNumberOfComponentsPerPixel(m_NumberOfPrincipalComponentsRequired + 1);
58 
59  // Band specific metadatas are not kept in the reduced space.
60  this->GetOutput()->SetBandImageMetadata(
61  ImageMetadata::ImageMetadataBandsType(this->GetOutput()->GetNumberOfComponentsPerPixel()));
62 }
63 
67 template <class TInputImage, class TOutputImage>
69 {
70  m_EstimatePCAFilter->SetInput(this->GetInput());
71  m_EstimatePCAFilter->SetNumberOfPrincipalComponentsRequired(m_NumberOfPrincipalComponentsRequired);
72  m_EstimatePCAFilter->SetCenterData(m_CenterData);
74 
75  m_NormalizePCAFilter->SetInput(m_EstimatePCAFilter->GetOutput());
76 
77  if ((m_CenterData == false) || ((m_CenterData == true) && (m_GenerateMeanComponent == false)))
78  {
79  m_NormalizePCAFilter->GraftOutput(this->GetOutput());
80  m_NormalizePCAFilter->Update();
81  this->GraftOutput(m_NormalizePCAFilter->GetOutput());
82  }
83  else
84  {
85  m_MeanFilter->SetInput(this->GetInput());
86  m_CastFilter->SetInput(m_MeanFilter->GetOutput());
87 
88  m_ConcatenateFilter->SetInput1(m_NormalizePCAFilter->GetOutput());
89  m_ConcatenateFilter->SetInput2(m_CastFilter->GetOutput());
90 
91  m_ConcatenateFilter->GraftOutput(this->GetOutput());
92  m_ConcatenateFilter->Update();
93  this->GraftOutput(m_ConcatenateFilter->GetOutput());
94  }
95 }
96 
100 template <class TInputImage, class TOutputImage>
101 void InnerProductPCAImageFilter<TInputImage, TOutputImage>::PrintSelf(std::ostream& os, itk::Indent indent) const
102 {
103  Superclass::PrintSelf(os, indent);
104 }
105 
106 } // End namespace otb
107 
108 #endif
otb::InnerProductPCAImageFilter::GenerateOutputInformation
void GenerateOutputInformation() override
Definition: otbInnerProductPCAImageFilter.hxx:50
otb::InnerProductPCAImageFilter::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbInnerProductPCAImageFilter.hxx:101
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbInnerProductPCAImageFilter.h
otb::InnerProductPCAImageFilter::GenerateData
void GenerateData(void) override
Definition: otbInnerProductPCAImageFilter.hxx:68
otb::InnerProductPCAImageFilter::InnerProductPCAImageFilter
InnerProductPCAImageFilter()
Definition: otbInnerProductPCAImageFilter.hxx:32
otb::ImageMetadata::ImageMetadataBandsType
std::vector< ImageMetadataBase > ImageMetadataBandsType
Definition: otbImageMetadata.h:277