OTB  9.0.0
Orfeo Toolbox
otbPCAImageFilter.h
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 otbPCAImageFilter_h
22 #define otbPCAImageFilter_h
23 
24 #include "otbMacro.h"
25 #include "otbMatrixImageFilter.h"
27 
28 
29 namespace otb
30 {
31 
32 namespace Transform
33 {
35 {
36  FORWARD = 0,
37  INVERSE = 1
38 };
39 }
40 
52 template <class TInputImage, class TOutputImage, Transform::TransformDirection TDirectionOfTransformation>
53 class ITK_EXPORT PCAImageFilter : public itk::ImageToImageFilter<TInputImage, TOutputImage>
54 {
55 public:
58  typedef itk::ImageToImageFilter<TInputImage, TOutputImage> Superclass;
59  typedef itk::SmartPointer<Self> Pointer;
60  typedef itk::SmartPointer<const Self> ConstPointer;
61 
63  itkNewMacro(Self);
64 
66  itkTypeMacro(PCAImageFilter, ImageToImageFilter);
67 
69  itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
70  itkStaticConstMacro(OutputImageDimension, unsigned int, TOutputImage::ImageDimension);
72 
74  itkStaticConstMacro(DirectionOfTransformation, TransformDirectionEnumType, TDirectionOfTransformation);
75 
77  typedef TInputImage InputImageType;
78  typedef TOutputImage OutputImageType;
79 
83 
87  typedef typename MatrixObjectType::ComponentType MatrixType;
88  typedef typename MatrixType::InternalMatrixType InternalMatrixType;
89  typedef typename InternalMatrixType::element_type MatrixElementType;
90 
93 
96 
102  itkSetMacro(NumberOfPrincipalComponentsRequired, unsigned int);
103  itkGetMacro(NumberOfPrincipalComponentsRequired, unsigned int);
105 
106  itkSetMacro(Whitening, bool);
107  itkGetMacro(Whitening, bool);
108 
109  itkGetMacro(CovarianceEstimator, CovarianceEstimatorFilterType*);
110  itkGetMacro(Transformer, TransformFilterType*);
111 
112  itkGetMacro(GivenCovarianceMatrix, bool);
114  {
115  if (m_GivenCovarianceMatrix)
116  return m_CovarianceMatrix;
117  else
118  return this->GetCovarianceEstimator()->GetCovariance();
119  }
120 
122  {
123  m_CovarianceMatrix = cov;
124  m_GivenCovarianceMatrix = true;
125  this->Modified();
126  }
127 
128  itkGetMacro(TransformationMatrix, MatrixType);
129  itkGetMacro(GivenTransformationMatrix, bool);
130  void SetTransformationMatrix(const MatrixType& transf, bool isForward = true)
131  {
132  m_TransformationMatrix = transf;
133  m_GivenTransformationMatrix = true;
134  m_IsTransformationMatrixForward = isForward;
135  this->Modified();
136  }
137 
138  itkGetConstMacro(EigenValues, VectorType);
139 
140  itkGetMacro(UseNormalization, bool);
141  void SetUseNormalization(bool norm)
142  {
143  m_UseNormalization = norm;
144  m_UseVarianceForNormalization = norm;
145  this->Modified();
146  }
147 
148  itkGetConstMacro(MeanValues, VectorType);
149  void SetMeanValues(const VectorType& data)
150  {
151  m_UseNormalization = true;
152  m_GivenMeanValues = true;
153  m_MeanValues = data;
154  this->Modified();
155  }
156 
157  itkGetConstMacro(UseVarianceForNormalization, bool);
158  itkSetMacro(UseVarianceForNormalization, bool);
159 
160  itkGetConstMacro(StdDevValues, VectorType);
161  void SetStdDevValues(const VectorType& vec)
162  {
163  m_UseNormalization = true;
164  m_UseVarianceForNormalization = true;
165  m_GivenStdDevValues = true;
166  m_StdDevValues = vec;
167  this->Modified();
168  }
169 
171  {
173  m_Normalizer->GetCovarianceEstimator()->SetUserIgnoredValue(value);
174  m_Normalizer->GetCovarianceEstimator()->SetIgnoreUserDefinedValue(true);
175 
177  m_CovarianceEstimator->SetUserIgnoredValue(value);
178  m_CovarianceEstimator->SetIgnoreUserDefinedValue(true);
179  }
181 
182 protected:
183  PCAImageFilter();
184  ~PCAImageFilter() override
185  {
186  }
187 
196  void GenerateOutputInformation() override;
197 
201  void GenerateData() override;
202 
203  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
204 
206  virtual void ForwardGenerateOutputInformation();
207  virtual void ReverseGenerateOutputInformation();
208  virtual void ForwardGenerateData();
209  virtual void ReverseGenerateData();
211 
212  void GenerateTransformationMatrix();
213 
224 
230 
234 
235 private:
236  PCAImageFilter(const Self&); // not implemented
237  void operator=(const Self&); // not implemented
238 };
239 
240 } // end of namespace otb
241 
242 #ifndef OTB_MANUAL_INSTANTIATION
243 #include "otbPCAImageFilter.hxx"
244 #endif
245 
246 #endif // otbPCAImageFilter_h
otb::PCAImageFilter::m_UseNormalization
bool m_UseNormalization
Definition: otbPCAImageFilter.h:216
otb::PCAImageFilter::m_GivenMeanValues
bool m_GivenMeanValues
Definition: otbPCAImageFilter.h:218
otb::PCAImageFilter::m_Transformer
TransformFilterPointerType m_Transformer
Definition: otbPCAImageFilter.h:232
otb::PCAImageFilter::TransformDirectionEnumType
Transform::TransformDirection TransformDirectionEnumType
Definition: otbPCAImageFilter.h:73
otb::PCAImageFilter::m_UseVarianceForNormalization
bool m_UseVarianceForNormalization
Definition: otbPCAImageFilter.h:217
otbMatrixImageFilter.h
otb::PCAImageFilter::SetStdDevValues
void SetStdDevValues(const VectorType &vec)
Definition: otbPCAImageFilter.h:161
otb::Transform< typename TFirstTransform::ScalarType, TFirstTransform::InputSpaceDimension, TSecondTransform::OutputSpaceDimension >::TransformDirection
TransformDirection
Definition: otbPCAImageFilter.h:34
otb::PCAImageFilter::m_StdDevValues
VectorType m_StdDevValues
Definition: otbPCAImageFilter.h:226
otb::PCAImageFilter::CovarianceEstimatorFilterType
StreamingStatisticsVectorImageFilter< InputImageType > CovarianceEstimatorFilterType
Definition: otbPCAImageFilter.h:81
otb::PCAImageFilter::SetStatisticsUserIgnoredValue
void SetStatisticsUserIgnoredValue(RealType value)
Definition: otbPCAImageFilter.h:170
otb::PCAImageFilter::InternalMatrixType
MatrixType::InternalMatrixType InternalMatrixType
Definition: otbPCAImageFilter.h:88
otb::PCAImageFilter::m_MeanValues
VectorType m_MeanValues
Definition: otbPCAImageFilter.h:225
otb::PCAImageFilter::Self
PCAImageFilter Self
Definition: otbPCAImageFilter.h:57
otb::StreamingStatisticsVectorImageFilter::MatrixObjectType
StatFilterType::MatrixObjectType MatrixObjectType
Definition: otbStreamingStatisticsVectorImageFilter.h:323
otb::StreamingStatisticsVectorImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbStreamingStatisticsVectorImageFilter.h:304
otb::PCAImageFilter
Performs a Principal Component Analysis.
Definition: otbPCAImageFilter.h:53
otb::PCAImageFilter::m_Whitening
bool m_Whitening
Definition: otbPCAImageFilter.h:223
otb::PCAImageFilter::TransformFilterType
MatrixImageFilter< TInputImage, TOutputImage > TransformFilterType
Definition: otbPCAImageFilter.h:91
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::PCAImageFilter::SetCovarianceMatrix
void SetCovarianceMatrix(const MatrixType &cov)
Definition: otbPCAImageFilter.h:121
otb::PCAImageFilter::m_CovarianceMatrix
MatrixType m_CovarianceMatrix
Definition: otbPCAImageFilter.h:227
otb::Transform::FORWARD
@ FORWARD
Definition: otbPCAImageFilter.h:36
otb::MetaDataKey::VectorType
std::vector< double > VectorType
Definition: otbMetaDataKey.h:119
otb::PCAImageFilter::VectorType
CovarianceEstimatorFilterType::RealPixelType VectorType
Definition: otbPCAImageFilter.h:85
otbMacro.h
otb::StreamingStatisticsVectorImageFilter::RealPixelType
StatFilterType::RealPixelType RealPixelType
Definition: otbStreamingStatisticsVectorImageFilter.h:320
otb::PCAImageFilter::m_NumberOfPrincipalComponentsRequired
unsigned int m_NumberOfPrincipalComponentsRequired
Definition: otbPCAImageFilter.h:215
otb::PCAImageFilter::MatrixObjectType
CovarianceEstimatorFilterType::MatrixObjectType MatrixObjectType
Definition: otbPCAImageFilter.h:86
otbNormalizeVectorImageFilter.h
otb::PCAImageFilter::MatrixType
MatrixObjectType::ComponentType MatrixType
Definition: otbPCAImageFilter.h:87
otb::PCAImageFilter::SetTransformationMatrix
void SetTransformationMatrix(const MatrixType &transf, bool isForward=true)
Definition: otbPCAImageFilter.h:130
otb::PCAImageFilter::~PCAImageFilter
~PCAImageFilter() override
Definition: otbPCAImageFilter.h:184
otb::StreamingStatisticsVectorImageFilter
This class streams the whole input image through the PersistentStatisticsImageFilter.
Definition: otbStreamingStatisticsVectorImageFilter.h:297
otb::PCAImageFilter::NormalizeFilterType
NormalizeVectorImageFilter< TInputImage, TOutputImage > NormalizeFilterType
Definition: otbPCAImageFilter.h:94
otb::MatrixImageFilter
Apply a matrix multiplication over the channels of an image.
Definition: otbMatrixImageFilter.h:50
otb::Transform
Class to overload method passed to virtual pure in ITK V4.
Definition: otbTransform.h:39
otb::PCAImageFilter::SetMeanValues
void SetMeanValues(const VectorType &data)
Definition: otbPCAImageFilter.h:149
otb::PCAImageFilter::NormalizeFilterPointerType
NormalizeFilterType::Pointer NormalizeFilterPointerType
Definition: otbPCAImageFilter.h:95
otb::PCAImageFilter::m_TransformationMatrix
MatrixType m_TransformationMatrix
Definition: otbPCAImageFilter.h:229
otb::Transform::INVERSE
@ INVERSE
Definition: otbPCAImageFilter.h:37
otb::PCAImageFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbPCAImageFilter.h:60
otb::PCAImageFilter::TransformFilterPointerType
TransformFilterType::Pointer TransformFilterPointerType
Definition: otbPCAImageFilter.h:92
otb::PCAImageFilter::RealType
CovarianceEstimatorFilterType::RealType RealType
Definition: otbPCAImageFilter.h:84
otb::PCAImageFilter::m_IsTransformationMatrixForward
bool m_IsTransformationMatrixForward
Definition: otbPCAImageFilter.h:222
otb::PCAImageFilter::CovarianceEstimatorFilterPointerType
CovarianceEstimatorFilterType::Pointer CovarianceEstimatorFilterPointerType
Definition: otbPCAImageFilter.h:82
otb::NormalizeVectorImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbNormalizeVectorImageFilter.h:142
otb::MatrixImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbMatrixImageFilter.h:67
otb::PCAImageFilter::InputImageType
TInputImage InputImageType
Definition: otbPCAImageFilter.h:77
otb::PCAImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbPCAImageFilter.h:59
otb::PCAImageFilter::m_GivenTransformationMatrix
bool m_GivenTransformationMatrix
Definition: otbPCAImageFilter.h:221
otb::PCAImageFilter::GetCovarianceMatrix
MatrixType GetCovarianceMatrix() const
Definition: otbPCAImageFilter.h:113
otb::PCAImageFilter::Superclass
itk::ImageToImageFilter< TInputImage, TOutputImage > Superclass
Definition: otbPCAImageFilter.h:58
otb::PCAImageFilter::OutputImageType
TOutputImage OutputImageType
Definition: otbPCAImageFilter.h:78
otb::PCAImageFilter::m_GivenCovarianceMatrix
bool m_GivenCovarianceMatrix
Definition: otbPCAImageFilter.h:220
otb::PCAImageFilter::SetUseNormalization
void SetUseNormalization(bool norm)
Definition: otbPCAImageFilter.h:141
otb::NormalizeVectorImageFilter
Normalize an VectorImage by setting its mean to zero and possibly variance to one (band by band).
Definition: otbNormalizeVectorImageFilter.h:132
otb::PCAImageFilter::MatrixElementType
InternalMatrixType::element_type MatrixElementType
Definition: otbPCAImageFilter.h:89
otbPCAImageFilter.hxx
otb::PCAImageFilter::m_CovarianceEstimator
CovarianceEstimatorFilterPointerType m_CovarianceEstimator
Definition: otbPCAImageFilter.h:231
otb::PCAImageFilter::m_GivenStdDevValues
bool m_GivenStdDevValues
Definition: otbPCAImageFilter.h:219
otb::StreamingStatisticsVectorImageFilter::RealType
StatFilterType::RealType RealType
Definition: otbStreamingStatisticsVectorImageFilter.h:318
otb::PCAImageFilter::m_Normalizer
NormalizeFilterPointerType m_Normalizer
Definition: otbPCAImageFilter.h:233
otb::PCAImageFilter::m_EigenValues
VectorType m_EigenValues
Definition: otbPCAImageFilter.h:228