OTB  6.7.0
Orfeo Toolbox
otbFastICAImageFilter.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 otbFastICAImageFilter_h
22 #define otbFastICAImageFilter_h
23 
24 #include "itkImageToImageFilter.h"
25 #include "otbPCAImageFilter.h"
27 #include <functional>
28 
29 namespace otb
30 {
46 template <class TInputImage, class TOutputImage, Transform::TransformDirection TDirectionOfTransformation >
47 class ITK_EXPORT FastICAImageFilter
48  : public itk::ImageToImageFilter<TInputImage, TOutputImage>
49 {
50 public:
56 
58  itkNewMacro(Self);
59 
61  itkTypeMacro(FastICAImageFilter, ImageToImageFilter);
62 
64  itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
65  itkStaticConstMacro(OutputImageDimension, unsigned int, TOutputImage::ImageDimension);
67 
69  itkStaticConstMacro(DirectionOfTransformation, TransformDirectionEnumType, TDirectionOfTransformation);
70 
72  typedef TInputImage InputImageType;
73  typedef TOutputImage OutputImageType;
74 
78 
82  typedef typename MatrixType::InternalMatrixType InternalMatrixType;
83  typedef typename InternalMatrixType::element_type MatrixElementType;
84 
87 
91 
94 
95  typedef std::function<double(double)> NonLinearityType;
96 
100  itkGetMacro(NumberOfPrincipalComponentsRequired, unsigned int);
101  itkSetMacro(NumberOfPrincipalComponentsRequired, unsigned int);
103 
104  itkGetConstMacro(PCAFilter, PCAFilterType *);
105  itkGetMacro(PCAFilter, PCAFilterType *);
106 
107  itkGetConstMacro(TransformFilter, TransformFilterType *);
108  itkGetMacro(TransformFilter, TransformFilterType *);
109 
111  {
112  return this->GetPCAFilter()->GetMeanValues();
113  }
114  void SetMeanValues ( const VectorType & vec )
115  {
116  m_PCAFilter->SetMeanValues(vec);
117  }
118 
120  {
121  return this->GetPCAFilter()->GetStdDevValues();
122  }
123  void SetStdDevValues ( const VectorType & vec )
124  {
125  m_PCAFilter->SetStdDevValues(vec);
126  }
127 
129  {
130  return this->GetPCAFilter()->GetTransformationMatrix();
131  }
132  void SetPCATransformationMatrix ( const MatrixType & mat, bool isForward = true )
133  {
134  m_PCAFilter->SetTransformationMatrix(mat, isForward);
135  }
136 
137  itkGetConstMacro(TransformationMatrix, MatrixType);
138  itkGetMacro(TransformationMatrix, MatrixType);
139  void SetTransformationMatrix ( const MatrixType & mat, bool isForward = true )
140  {
141  m_IsTransformationForward = isForward;
142  m_GivenTransformationMatrix = true;
143  m_TransformationMatrix = mat;
144  this->Modified();
145  }
146 
147  itkGetMacro(NumberOfIterations, unsigned int);
148  itkSetMacro(NumberOfIterations, unsigned int);
149 
150  itkGetMacro(ConvergenceThreshold, double);
151  itkSetMacro(ConvergenceThreshold, double);
152 
154  NonLinearityType NonLinearityDerivative)
155  {
156  m_NonLinearity = NonLinearity;
157  m_NonLinearityDerivative = NonLinearityDerivative;
158  this->Modified();
159  }
160 
161  itkGetMacro(NonLinearity, NonLinearityType);
162  itkGetMacro(NonLinearityDerivative, NonLinearityType);
163 
164  itkGetMacro(Mu, double);
165  itkSetMacro(Mu, double);
166 
167 protected:
169  ~FastICAImageFilter() override { }
170 
179  void GenerateOutputInformation() override;
180 
184  void GenerateData () override;
185 
187  void ForwardGenerateOutputInformation();
188  void ReverseGenerateOutputInformation();
189  virtual void ForwardGenerateData();
190  virtual void ReverseGenerateData();
192 
194  virtual void GenerateTransformationMatrix();
195 
197 
202 
204  unsigned int m_NumberOfIterations; // def is 50
205  double m_ConvergenceThreshold; // def is 1e-4
206  NonLinearityType m_NonLinearity; // see g() function in the biblio. Def is tanh
208  double m_Mu; // def is 1. in [0, 1]
210 
213 
214 private:
215  FastICAImageFilter( const Self & ) = delete;
216  void operator =( const Self & ) = delete;
217 }; // end of class
218 
219 } // end of namespace otb
220 
221 #ifndef OTB_MANUAL_INSTANTIATION
222 #include "otbFastICAImageFilter.hxx"
223 #endif
224 
225 
226 #endif
227 
228 
itk::ImageToImageFilter< TInputImage, TOutputImage > Superclass
Apply a matrix multiplication over the channels of an image.
void SetNonLinearity(NonLinearityType NonLinearity, NonLinearityType NonLinearityDerivative)
Performs a Independent Component Analysis (ICA)
VectorType GetStdDevValues() const
PCAFilterPointerType m_PCAFilter
TransformFilterPointerType m_TransformFilter
MeanEstimatorFilterType::Pointer MeanEstimatorFilterPointerType
MatrixType GetPCATransformationMatrix() const
MatrixObjectType::ComponentType MatrixType
unsigned int m_NumberOfPrincipalComponentsRequired
VectorType GetMeanValues() const
PCAFilterType::RealType RealType
Performs a Principal Component Analysis.
MatrixImageFilter< TInputImage, TOutputImage > TransformFilterType
Internal optimisation of the FastICA unmixing filter.
TransformFilterType::Pointer TransformFilterPointerType
void SetStdDevValues(const VectorType &vec)
NonLinearityType m_NonLinearityDerivative
MatrixType::InternalMatrixType InternalMatrixType
std::function< double(double)> NonLinearityType
FastICAInternalOptimizerVectorImageFilter< InputImageType, InputImageType > InternalOptimizerType
void SetMeanValues(const VectorType &vec)
void SetTransformationMatrix(const MatrixType &mat, bool isForward=true)
Transform::TransformDirection TransformDirectionEnumType
PCAImageFilter< InputImageType, OutputImageType, TDirectionOfTransformation > PCAFilterType
itk::SmartPointer< const Self > ConstPointer
itk::SmartPointer< Self > Pointer
CovarianceEstimatorFilterType::RealType RealType
StreamingStatisticsVectorImageFilter< InputImageType > MeanEstimatorFilterType
CovarianceEstimatorFilterType::RealPixelType VectorType
This class streams the whole input image through the PersistentStatisticsImageFilter.
PCAFilterType::MatrixType MatrixType
PCAFilterType::VectorType VectorType
InternalOptimizerType::Pointer InternalOptimizerPointerType
void SetPCATransformationMatrix(const MatrixType &mat, bool isForward=true)
PCAFilterType::Pointer PCAFilterPointerType
InternalMatrixType::element_type MatrixElementType