Orfeo Toolbox  4.0
otbNormalizeVectorImageFilter.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 __otbNormalizeVectorImageFilter_h
19 #define __otbNormalizeVectorImageFilter_h
20 
21 #include <vnl/vnl_math.h>
22 
23 #include <itkNumericTraits.h>
24 #include <itkMacro.h>
26 #include <otbVectorImage.h>
28 
30 
31 namespace otb
32 {
33 namespace Functor
34 {
38 template < class TInput, class TOutput >
40 {
41 public:
44 
47 
48  TOutput operator() ( const TInput & input )
49  {
50  unsigned int length = input.Size();
51  TOutput output ( length );
52  for ( unsigned int i = 0; i < length; ++i )
53  {
54  output[i] = static_cast<typename TOutput::ValueType>(
55  ( static_cast< RealType >( input[i] ) - m_Mean[i] )
56  / m_StdDev[i] );
57  }
58  return output;
59  }
60 
61  template < class T >
63  {
64  m_Mean.SetSize( m.Size() );
65  for ( unsigned int i = 0; i < m_Mean.Size(); ++i )
66  m_Mean[i] = static_cast< RealType >( m[i] );
67  }
68 
70  {
71  return this->m_Mean;
72  }
73 
74  template < class T>
75  void SetStdDev ( const itk::VariableLengthVector<T> & sigma )
76  {
77  m_StdDev.SetSize( sigma.Size() );
78  for ( unsigned int i = 0; i < m_StdDev.Size(); ++i )
79  {
80  m_StdDev[i] = static_cast< RealType >( sigma[i] );
82  {
83  throw itk::ExceptionObject(__FILE__, __LINE__,
84  "Cannot divide by zero !", ITK_LOCATION);
85  }
86  }
87  }
88 
89  template < class T >
91  {
92  m_StdDev.SetSize( var.Size() );
93  for ( unsigned int i = 0; i < m_StdDev.Size(); ++i )
94  {
95  m_StdDev[i] = vcl_sqrt( static_cast< RealType >( var[i] ) );
97  {
98  throw itk::ExceptionObject(__FILE__, __LINE__,
99  "Cannot divide by zero !", ITK_LOCATION);
100  }
101  }
102  }
103 
105  {
106  return this->m_StdDev;
107  }
108 
109 protected:
110 
113 }; // end of class NormalizeVectorImageFunctor
114 
115 } // end of namespace Functor
116 
117 
129 template < class TInputImage, class TOutputImage >
131  : public UnaryFunctorVectorImageFilter< TInputImage, TOutputImage,
132  Functor::NormalizeVectorImageFunctor<
133  typename TInputImage::PixelType,
134  typename TOutputImage::PixelType > >
135 {
136 public:
139  typedef UnaryFunctorVectorImageFilter< TInputImage, TOutputImage,
141  typename TInputImage::PixelType,
142  typename TOutputImage::PixelType > > Superclass;
145 
147  itkNewMacro(Self);
148 
150  itkTypeMacro(NormalizeVectorImageFilter, ImageToImageFilter);
151 
152  typedef TInputImage InputImageType;
153  typedef TOutputImage OutputImageType;
154 
157 
160 
161  itkGetConstMacro(CovarianceEstimator, CovarianceEstimatorFilterType*);
162 
163  template < class T >
164  void SetMean ( const itk::VariableLengthVector<T> & m )
165  {
166  this->GetFunctor().SetMean( m );
167  m_IsGivenMean = true;
168  m_UseMean = true;
169  this->Modified();
170  }
171 
172  template < class T >
173  void SetStdDev ( const itk::VariableLengthVector<T> & sigma )
174  {
175  this->GetFunctor().SetStdDev( sigma );
176  m_IsGivenStdDev = true;
177  m_UseStdDev = true;
178  this->Modified();
179  }
180 
181  template < class T >
182  void SetVariance ( const itk::VariableLengthVector<T> & var )
183  {
184  this->GetFunctor().SetVariance( var );
185  m_IsGivenStdDev = true;
186  m_UseStdDev = true;
187  this->Modified();
188  }
189 
190 
191  itkSetMacro(UseMean, bool);
192  itkSetMacro(UseStdDev, bool);
193 
194 protected:
197 
198  void BeforeThreadedGenerateData();
199 
200 private:
201  NormalizeVectorImageFilter ( const Self & );
202  void operator=( const Self & );
203 
206 
207  bool m_UseMean;
209 
211 
212 }; // end of class NormalizeVectorImageFilter
213 
214 } // end of namespace otb
215 
216 #ifndef OTB_MANUAL_INSTANTIATION
218 #endif
219 
220 #endif // __otbNormalizeVectorImageFilter_h
221 

Generated at Sat Mar 8 2014 16:11:37 for Orfeo Toolbox with doxygen 1.8.3.1