OTB  6.7.0
Orfeo Toolbox
otbPCAImageFilter.h
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 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 
48 template <class TInputImage, class TOutputImage, Transform::TransformDirection TDirectionOfTransformation >
49 class ITK_EXPORT PCAImageFilter
50  : public itk::ImageToImageFilter<TInputImage, TOutputImage>
51 {
52 public:
58 
60  itkNewMacro(Self);
61 
63  itkTypeMacro(PCAImageFilter, ImageToImageFilter);
64 
66  itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
67  itkStaticConstMacro(OutputImageDimension, unsigned int, TOutputImage::ImageDimension);
69 
71  itkStaticConstMacro(DirectionOfTransformation, TransformDirectionEnumType, TDirectionOfTransformation);
72 
74  typedef TInputImage InputImageType;
75  typedef TOutputImage OutputImageType;
76 
80 
85  typedef typename MatrixType::InternalMatrixType InternalMatrixType;
86  typedef typename InternalMatrixType::element_type MatrixElementType;
87 
90 
93 
99  itkSetMacro(NumberOfPrincipalComponentsRequired, unsigned int);
100  itkGetMacro(NumberOfPrincipalComponentsRequired, unsigned int);
102 
103  itkGetMacro(CovarianceEstimator, CovarianceEstimatorFilterType *);
104  itkGetMacro(Transformer, TransformFilterType *);
105 
106  itkGetMacro(GivenCovarianceMatrix, bool);
108  {
109  if ( m_GivenCovarianceMatrix )
110  return m_CovarianceMatrix;
111  else
112  return this->GetCovarianceEstimator()->GetCovariance();
113  }
114 
115  void SetCovarianceMatrix ( const MatrixType & cov )
116  {
117  m_CovarianceMatrix = cov;
118  m_GivenCovarianceMatrix = true;
119  this->Modified();
120  }
121 
122  itkGetMacro(TransformationMatrix, MatrixType);
123  itkGetMacro(GivenTransformationMatrix, bool);
124  void SetTransformationMatrix( const MatrixType & transf, bool isForward = true )
125  {
126  m_TransformationMatrix = transf;
127  m_GivenTransformationMatrix = true;
128  m_IsTransformationMatrixForward = isForward;
129  this->Modified();
130  }
131 
132  itkGetConstMacro(EigenValues, VectorType);
133 
134  itkGetMacro(UseNormalization, bool);
135  void SetUseNormalization ( bool norm )
136  {
137  m_UseNormalization = norm;
138  m_UseVarianceForNormalization = norm;
139  this->Modified();
140  }
141 
142  itkGetConstMacro(MeanValues, VectorType);
143  void SetMeanValues ( const VectorType & data )
144  {
145  m_UseNormalization = true;
146  m_GivenMeanValues = true;
147  m_MeanValues = data;
148  this->Modified();
149  }
150 
151  itkGetConstMacro(UseVarianceForNormalization, bool);
152  itkSetMacro(UseVarianceForNormalization, bool);
153 
154  itkGetConstMacro(StdDevValues, VectorType);
155  void SetStdDevValues ( const VectorType & vec )
156  {
157  m_UseNormalization = true;
158  m_UseVarianceForNormalization = true;
159  m_GivenStdDevValues = true;
160  m_StdDevValues = vec;
161  this->Modified();
162  }
163 
164 protected:
165  PCAImageFilter();
166  ~PCAImageFilter() override { }
167 
176  void GenerateOutputInformation() override;
177 
181  void GenerateData () override;
182 
183  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
184 
186  virtual void ForwardGenerateOutputInformation();
187  virtual void ReverseGenerateOutputInformation();
188  virtual void ForwardGenerateData();
189  virtual void ReverseGenerateData();
191 
192  void GenerateTransformationMatrix();
193 
203 
209 
213 
214 private:
215  PCAImageFilter( const Self & ); // not implemented
216  void operator= ( const Self & ); // not implemented
217 };
218 
219 } // end of namespace otb
220 
221 #ifndef OTB_MANUAL_INSTANTIATION
222 #include "otbPCAImageFilter.hxx"
223 #endif
224 
225 #endif // otbPCAImageFilter_h
Apply a matrix multiplication over the channels of an image.
itk::SmartPointer< Self > Pointer
TOutputImage OutputImageType
std::vector< double > VectorType
itk::ImageToImageFilter< TInputImage, TOutputImage > Superclass
NormalizeFilterType::Pointer NormalizeFilterPointerType
TransformFilterType::Pointer TransformFilterPointerType
MatrixObjectType::ComponentType MatrixType
MatrixImageFilter< TInputImage, TOutputImage > TransformFilterType
CovarianceEstimatorFilterType::MatrixObjectType MatrixObjectType
Transform::TransformDirection TransformDirectionEnumType
void SetCovarianceMatrix(const MatrixType &cov)
itk::SmartPointer< const Self > ConstPointer
NormalizeFilterPointerType m_Normalizer
unsigned int m_NumberOfPrincipalComponentsRequired
Performs a Principal Component Analysis.
void SetUseNormalization(bool norm)
MatrixType m_TransformationMatrix
RealType ComponentType
Definition: mvdTypes.h:88
NormalizeVectorImageFilter< TInputImage, TOutputImage > NormalizeFilterType
void SetMeanValues(const VectorType &data)
TransformFilterPointerType m_Transformer
CovarianceEstimatorFilterType::Pointer CovarianceEstimatorFilterPointerType
CovarianceEstimatorFilterPointerType m_CovarianceEstimator
CovarianceEstimatorFilterType::RealType RealType
InternalMatrixType::element_type MatrixElementType
CovarianceEstimatorFilterType::RealPixelType VectorType
TInputImage InputImageType
void SetTransformationMatrix(const MatrixType &transf, bool isForward=true)
This class streams the whole input image through the PersistentStatisticsImageFilter.
void SetStdDevValues(const VectorType &vec)
Normalize an VectorImage by setting its mean to zero and possibly variance to one (band by band)...
MatrixType GetCovarianceMatrix() const
MatrixType::InternalMatrixType InternalMatrixType
StreamingStatisticsVectorImageFilter< InputImageType > CovarianceEstimatorFilterType
Class to overload method passed to virtual pure in ITK V4.
Definition: otbTransform.h:40