OTB  10.0.0
Orfeo Toolbox
otbFastICAImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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 : public itk::ImageToImageFilter<TInputImage, TOutputImage>
48 {
49 public:
52  typedef itk::ImageToImageFilter<TInputImage, TOutputImage> Superclass;
53  typedef itk::SmartPointer<Self> Pointer;
54  typedef itk::SmartPointer<const Self> ConstPointer;
55 
57  itkNewMacro(Self);
58 
60  itkTypeMacro(FastICAImageFilter, ImageToImageFilter);
61 
63  itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
64  itkStaticConstMacro(OutputImageDimension, unsigned int, TOutputImage::ImageDimension);
66 
68  itkStaticConstMacro(DirectionOfTransformation, TransformDirectionEnumType, TDirectionOfTransformation);
69 
71  typedef TInputImage InputImageType;
72  typedef TOutputImage OutputImageType;
73 
76 
80  typedef typename MatrixType::InternalMatrixType InternalMatrixType;
81  typedef typename InternalMatrixType::element_type MatrixElementType;
82 
85 
88 
91 
92  typedef std::function<double(double)> NonLinearityType;
93 
97  itkGetMacro(NumberOfPrincipalComponentsRequired, unsigned int);
98  itkSetMacro(NumberOfPrincipalComponentsRequired, unsigned int);
100 
101  itkGetConstMacro(PCAFilter, PCAFilterType*);
102  itkGetMacro(PCAFilter, PCAFilterType*);
103 
104  itkGetConstMacro(TransformFilter, TransformFilterType*);
105  itkGetMacro(TransformFilter, TransformFilterType*);
106 
108  {
109  return this->GetPCAFilter()->GetMeanValues();
110  }
111  void SetMeanValues(const VectorType& vec)
112  {
113  m_PCAFilter->SetMeanValues(vec);
114  }
115 
117  {
118  return this->GetPCAFilter()->GetStdDevValues();
119  }
120  void SetStdDevValues(const VectorType& vec)
121  {
122  m_PCAFilter->SetStdDevValues(vec);
123  }
124 
126  {
127  return this->GetPCAFilter()->GetTransformationMatrix();
128  }
129  void SetPCATransformationMatrix(const MatrixType& mat, bool isForward = true)
130  {
131  m_PCAFilter->SetTransformationMatrix(mat, isForward);
132  }
133 
134  itkGetConstMacro(TransformationMatrix, MatrixType);
135  itkGetMacro(TransformationMatrix, MatrixType);
136  void SetTransformationMatrix(const MatrixType& mat, bool isForward = true)
137  {
138  m_IsTransformationForward = isForward;
139  m_GivenTransformationMatrix = true;
140  m_TransformationMatrix = mat;
141  this->Modified();
142  }
143 
144  itkGetMacro(NumberOfIterations, unsigned int);
145  itkSetMacro(NumberOfIterations, unsigned int);
146 
147  itkGetMacro(ConvergenceThreshold, double);
148  itkSetMacro(ConvergenceThreshold, double);
149 
150  void SetNonLinearity(NonLinearityType NonLinearity, NonLinearityType NonLinearityDerivative)
151  {
152  m_NonLinearity = NonLinearity;
153  m_NonLinearityDerivative = NonLinearityDerivative;
154  this->Modified();
155  }
156 
157  itkGetMacro(NonLinearity, NonLinearityType);
158  itkGetMacro(NonLinearityDerivative, NonLinearityType);
159 
160  itkGetMacro(Mu, double);
161  itkSetMacro(Mu, double);
162 
163 protected:
166  {
167  }
168 
177  void GenerateOutputInformation() override;
178 
182  void GenerateData() override;
183 
185  void ForwardGenerateOutputInformation();
186  void ReverseGenerateOutputInformation();
187  virtual void ForwardGenerateData();
188  virtual void ReverseGenerateData();
190 
192  virtual void GenerateTransformationMatrix();
193 
195 
200 
202  unsigned int m_NumberOfIterations; // def is 50
203  double m_ConvergenceThreshold; // def is 1e-4
204  NonLinearityType m_NonLinearity; // see g() function in the biblio. Def is tanh
206  double m_Mu; // def is 1. in [0, 1]
208 
211 
212 private:
213  FastICAImageFilter(const Self&) = delete;
214  void operator=(const Self&) = delete;
215 }; // end of class
216 
217 } // end of namespace otb
218 
219 #ifndef OTB_MANUAL_INSTANTIATION
220 #include "otbFastICAImageFilter.hxx"
221 #endif
222 
223 
224 #endif
Performs a Independent Component Analysis (ICA)
void SetNonLinearity(NonLinearityType NonLinearity, NonLinearityType NonLinearityDerivative)
InternalMatrixType::element_type MatrixElementType
itk::SmartPointer< const Self > ConstPointer
PCAFilterType::MatrixType MatrixType
std::function< double(double)> NonLinearityType
PCAFilterPointerType m_PCAFilter
MatrixType GetPCATransformationMatrix() const
PCAFilterType::VectorType VectorType
FastICAImageFilter(const Self &)=delete
MeanEstimatorFilterType::Pointer MeanEstimatorFilterPointerType
StreamingStatisticsVectorImageFilter< InputImageType > MeanEstimatorFilterType
PCAFilterType::RealType RealType
PCAImageFilter< InputImageType, OutputImageType, TDirectionOfTransformation > PCAFilterType
unsigned int m_NumberOfPrincipalComponentsRequired
MatrixImageFilter< TInputImage, TOutputImage > TransformFilterType
void SetMeanValues(const VectorType &vec)
TransformFilterPointerType m_TransformFilter
TransformFilterType::Pointer TransformFilterPointerType
void SetStdDevValues(const VectorType &vec)
itk::ImageToImageFilter< TInputImage, TOutputImage > Superclass
void operator=(const Self &)=delete
itk::SmartPointer< Self > Pointer
FastICAInternalOptimizerVectorImageFilter< InputImageType, InputImageType > InternalOptimizerType
PCAFilterType::Pointer PCAFilterPointerType
MatrixType::InternalMatrixType InternalMatrixType
VectorType GetMeanValues() const
VectorType GetStdDevValues() const
void SetPCATransformationMatrix(const MatrixType &mat, bool isForward=true)
NonLinearityType m_NonLinearityDerivative
void SetTransformationMatrix(const MatrixType &mat, bool isForward=true)
InternalOptimizerType::Pointer InternalOptimizerPointerType
Transform::TransformDirection TransformDirectionEnumType
Internal optimisation of the FastICA unmixing filter.
Apply a matrix multiplication over the channels of an image.
itk::SmartPointer< Self > Pointer
Performs a Principal Component Analysis.
MatrixObjectType::ComponentType MatrixType
CovarianceEstimatorFilterType::RealPixelType VectorType
CovarianceEstimatorFilterType::RealType RealType
itk::SmartPointer< Self > Pointer
This class streams the whole input image through the PersistentStatisticsImageFilter.
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.