File: otbFastICAImageFilter.h

package info (click to toggle)
otb 5.8.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 38,496 kB
  • ctags: 40,282
  • sloc: cpp: 306,573; ansic: 3,575; python: 450; sh: 214; perl: 74; java: 72; makefile: 70
file content (205 lines) | stat: -rw-r--r-- 6,681 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.


     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef otbFastICAImageFilter_h
#define otbFastICAImageFilter_h

#include "itkImageToImageFilter.h"
#include "otbPCAImageFilter.h"
#include "otbFastICAInternalOptimizerVectorImageFilter.h"

namespace otb
{
/** \class FastICAImageFilter
 * \brief Performs a Independent Component Analysis
 *
 * The internal structure of this filter is a filter-to-filter like structure.
 * The estimation of the covariance matrix has persistent capabilities...
 *
 * \sa PCAImageFilter
 *
 * \ingroup OTBDimensionalityReduction
 */
template <class TInputImage, class TOutputImage, Transform::TransformDirection TDirectionOfTransformation >
class ITK_EXPORT FastICAImageFilter
  : public itk::ImageToImageFilter<TInputImage, TOutputImage>
{
public:
  /** Standard typedefs */
  typedef FastICAImageFilter                                 Self;
  typedef itk::ImageToImageFilter<TInputImage, TOutputImage> Superclass;
  typedef itk::SmartPointer<Self>                            Pointer;
  typedef itk::SmartPointer<const Self>                      ConstPointer;

  /** Type macro */
  itkNewMacro(Self);

  /** Creation through object factory macro */
  itkTypeMacro(FastICAImageFilter, ImageToImageFilter);

  /** Dimension */
  itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension);
  itkStaticConstMacro(OutputImageDimension, unsigned int, TOutputImage::ImageDimension);

  typedef Transform::TransformDirection TransformDirectionEnumType;
  itkStaticConstMacro(DirectionOfTransformation, TransformDirectionEnumType, TDirectionOfTransformation);

  /** typedefs */
  typedef TInputImage InputImageType;
  typedef TOutputImage OutputImageType;

  typedef PCAImageFilter< InputImageType, OutputImageType, TDirectionOfTransformation >
      PCAFilterType;
  typedef typename PCAFilterType::Pointer PCAFilterPointerType;

  typedef typename PCAFilterType::RealType RealType;
  typedef typename PCAFilterType::VectorType VectorType;
  typedef typename PCAFilterType::MatrixType MatrixType;
  typedef typename MatrixType::InternalMatrixType InternalMatrixType;
  typedef typename InternalMatrixType::element_type MatrixElementType;

  typedef MatrixImageFilter< TInputImage, TOutputImage > TransformFilterType;
  typedef typename TransformFilterType::Pointer TransformFilterPointerType;

  typedef FastICAInternalOptimizerVectorImageFilter< InputImageType, InputImageType >
      InternalOptimizerType;
  typedef typename InternalOptimizerType::Pointer InternalOptimizerPointerType;

  typedef StreamingStatisticsVectorImageFilter< InputImageType > MeanEstimatorFilterType;
  typedef typename MeanEstimatorFilterType::Pointer MeanEstimatorFilterPointerType;

  typedef double (*ContrastFunctionType) ( double );

  /**
   * Set/Get the number of required largest principal components.
   */
  itkGetMacro(NumberOfPrincipalComponentsRequired, unsigned int);
  itkSetMacro(NumberOfPrincipalComponentsRequired, unsigned int);

  itkGetConstMacro(PCAFilter, PCAFilterType *);
  itkGetMacro(PCAFilter, PCAFilterType *);

  itkGetConstMacro(TransformFilter, TransformFilterType *);
  itkGetMacro(TransformFilter, TransformFilterType *);

  VectorType GetMeanValues () const
  {
    return this->GetPCAFilter()->GetMeanValues();
  }
  void SetMeanValues ( const VectorType & vec )
  {
    m_PCAFilter->SetMeanValues(vec);
  }

  VectorType GetStdDevValues ( ) const
  {
    return this->GetPCAFilter()->GetStdDevValues();
  }
  void SetStdDevValues ( const VectorType & vec )
  {
    m_PCAFilter->SetStdDevValues(vec);
  }

  MatrixType GetPCATransformationMatrix () const
  {
    return this->GetPCAFilter()->GetTransformationMatrix();
  }
  void SetPCATransformationMatrix ( const MatrixType & mat, bool isForward = true )
  {
    m_PCAFilter->SetTransformationMatrix(mat, isForward);
  }

  itkGetConstMacro(TransformationMatrix, MatrixType);
  itkGetMacro(TransformationMatrix, MatrixType);
  void SetTransformationMatrix ( const MatrixType & mat, bool isForward = true )
  {
    m_IsTransformationForward = isForward;
    m_GivenTransformationMatrix = true;
    m_TransformationMatrix = mat;
    this->Modified();
  }

  itkGetMacro(NumberOfIterations, unsigned int);
  itkSetMacro(NumberOfIterations, unsigned int);

  itkGetMacro(ConvergenceThreshold, double);
  itkSetMacro(ConvergenceThreshold, double);

  itkGetMacro(ContrastFunction, ContrastFunctionType);

  itkGetMacro(Mu, double);
  itkSetMacro(Mu, double);

protected:
  FastICAImageFilter ();
  ~FastICAImageFilter() ITK_OVERRIDE { }

  /** GenerateOutputInformation
   * Propagate vector length info and modify if needed
   * NumberOfPrincipalComponentsRequired
   *
   * In REVERSE mode, the covariance matrix or the transformation matrix
   * (which may not be square) has to be given,
   * otherwize, GenerateOutputInformation throws an itk::ExceptionObject
   */
  void GenerateOutputInformation() ITK_OVERRIDE;

  /** GenerateData
   * Through a filter of filter structure
   */
  void GenerateData () ITK_OVERRIDE;

  /** Internal methods */
  void ForwardGenerateOutputInformation();
  void ReverseGenerateOutputInformation();
  virtual void ForwardGenerateData();
  virtual void ReverseGenerateData();

  /** this is the specific part of FastICA */
  virtual void GenerateTransformationMatrix();

  unsigned int m_NumberOfPrincipalComponentsRequired;

  /** Transformation matrix refers to the ICA step (not PCA) */
  bool m_GivenTransformationMatrix;
  bool m_IsTransformationForward;
  MatrixType m_TransformationMatrix;

  /** FastICA parameters */
  unsigned int m_NumberOfIterations; // def is 50
  double m_ConvergenceThreshold; // def is 1e-4
  ContrastFunctionType m_ContrastFunction; // see g() function in the biblio. Def is tanh
  double m_Mu; // def is 1. in [0, 1]

  PCAFilterPointerType m_PCAFilter;
  TransformFilterPointerType m_TransformFilter;

private:
  FastICAImageFilter( const Self & ); //purposely not implemented
  void operator =( const Self & ); //purposely not implemented
}; // end of class

} // end of namespace otb

#ifndef OTB_MANUAL_INSTANTIATION
#include "otbFastICAImageFilter.txx"
#endif


#endif