OTB  6.7.0
Orfeo Toolbox
otbInnerProductPCAImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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>
34 {
35  this->SetNumberOfRequiredOutputs(1);
36  this->SetNthOutput(0, OutputImageType::New());
37  m_EstimatePCAFilter = EstimatePCAFilterType::New();
38  m_NormalizePCAFilter = NormalizePCAFilterType::New();
39  m_NumberOfPrincipalComponentsRequired = 1;
40  m_CenterData = true;
41  m_GenerateMeanComponent = false;
42  m_MeanFilter = MeanFilterType::New();
43  m_CastFilter = CastFilterType::New();
44  m_ConcatenateFilter = ConcatenateFilterType::New();
45 }
46 
50 template<class TInputImage, class TOutputImage>
51 void
54 {
55  Superclass::GenerateOutputInformation();
56  if (m_GenerateMeanComponent == false)
57  this->GetOutput()->SetNumberOfComponentsPerPixel(
58  m_NumberOfPrincipalComponentsRequired);
59  else this->GetOutput()->SetNumberOfComponentsPerPixel(m_NumberOfPrincipalComponentsRequired + 1);
60 }
62 
66 template <class TInputImage, class TOutputImage>
67 void
70 {
71  m_EstimatePCAFilter->SetInput(this->GetInput());
72  m_EstimatePCAFilter->SetNumberOfPrincipalComponentsRequired(m_NumberOfPrincipalComponentsRequired);
73  m_EstimatePCAFilter->SetCenterData(m_CenterData);
75 
76  m_NormalizePCAFilter->SetInput(m_EstimatePCAFilter->GetOutput());
77 
78  if ((m_CenterData == false) || ((m_CenterData == true) && (m_GenerateMeanComponent == false)))
79  {
80  m_NormalizePCAFilter->GraftOutput(this->GetOutput());
81  m_NormalizePCAFilter->Update();
82  this->GraftOutput(m_NormalizePCAFilter->GetOutput());
83  }
84  else
85  {
86  m_MeanFilter->SetInput(this->GetInput());
87  m_CastFilter->SetInput(m_MeanFilter->GetOutput());
88 
89  m_ConcatenateFilter->SetInput1(m_NormalizePCAFilter->GetOutput());
90  m_ConcatenateFilter->SetInput2(m_CastFilter->GetOutput());
91 
92  m_ConcatenateFilter->GraftOutput(this->GetOutput());
93  m_ConcatenateFilter->Update();
94  this->GraftOutput(m_ConcatenateFilter->GetOutput());
95  }
96 }
97 
101 template <class TInputImage, class TOutputImage>
102 void
104 ::PrintSelf(std::ostream& os, itk::Indent indent) const
105 {
106  Superclass::PrintSelf(os, indent);
107 }
108 
109 } // End namespace otb
110 
111 #endif
void PrintSelf(std::ostream &os, itk::Indent indent) const override