Orfeo Toolbox  3.16
otbUnConstrainedLeastSquareImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef __otbUnConstrainedLeastSquareImageFilter_h
19 #define __otbUnConstrainedLeastSquareImageFilter_h
20 
21 #include "itkMacro.h"
23 #include "vnl/algo/vnl_svd.h"
24 #include <boost/shared_ptr.hpp>
25 
26 namespace otb
27 {
28 
29 namespace Functor {
30 
36 template<class TInput, class TOutput, class TPrecision>
38 {
39 public:
40  typedef TInput InputType;
41  typedef TOutput OutputType;
42  typedef TPrecision PrecisionType;
43 
44  typedef vnl_vector<PrecisionType> VectorType;
45  typedef vnl_matrix<PrecisionType> MatrixType;
46 
49 
50  unsigned int GetOutputSize() const
51  {
52  return m_OutputSize;
53  }
54 
56  {
57  return true;
58  }
59 
61  {
62  return !(*this != other);
63  }
64 
65  void SetMatrix(const MatrixType& m)
66  {
67  //std::cout << "m : " << m.rows() << " " << m.cols() << std::endl;
68  m_Svd.reset( new SVDType(m) );
69  m_Inv = m_Svd->inverse();
70  m_OutputSize = m.cols();
71  }
72 
73  OutputType operator ()(const InputType& in) const
74  {
75  // TODO : support different types between input and output ?
76  VectorType inVector(in.Size());
77  for (unsigned int i = 0; i < in.GetSize(); ++i )
78  {
79  inVector[i] = in[i];
80  }
81 
82  VectorType outVector = m_Inv * inVector;
83 
84  OutputType out(outVector.size());
85  for (unsigned int i = 0; i < out.GetSize(); ++i )
86  {
87  out[i] = outVector[i];
88  }
89 
90  return out;
91  }
92 
93 private:
94 
95  typedef vnl_svd<PrecisionType> SVDType;
96  typedef boost::shared_ptr<SVDType> SVDPointerType;
97 
98  unsigned int m_OutputSize;
101 };
102 }
103 
123 template <class TInputImage, class TOutputImage, class TPrecision>
125  public otb::UnaryFunctorImageFilter<TInputImage, TOutputImage,
126  Functor::UnConstrainedLeastSquareFunctor<typename TInputImage::PixelType,
127  typename TOutputImage::PixelType, TPrecision> >
128 {
129 public:
133  <TInputImage,
134  TOutputImage,
136  typename TInputImage::PixelType,
137  typename TOutputImage::PixelType,
138  TPrecision>
140 
143 
145  typename TInputImage::PixelType,
146  typename TOutputImage::PixelType,
147  TPrecision> FunctorType;
148 
150 
152  itkNewMacro(Self);
153 
156 
158  typedef typename TInputImage::PixelType InputPixelType;
159  typedef typename TOutputImage::PixelType OutputPixelType;
160 
161  void SetMatrix(const MatrixType& m)
162  {
163  this->GetFunctor().SetMatrix(m);
164  this->Modified();
165  }
166 
167 protected:
169 
171 
172  void PrintSelf(std::ostream& os, itk::Indent indent) const;
173 
174 private:
175  UnConstrainedLeastSquareImageFilter(const Self &); //purposely not implemented
176 
177  void operator =(const Self&); //purposely not implemented
178 
179 };
180 
181 } // end namespace otb
182 
183 #ifndef OTB_MANUAL_INSTANTIATION
185 #endif
186 
187 #endif
188 

Generated at Sun May 19 2013 00:55:55 for Orfeo Toolbox with doxygen 1.8.3.1