DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkNormalizeVectorImageFilter.h
Go to the documentation of this file.
1 
18 #ifndef __itkNormalizeVectorImageFilter_h
19 #define __itkNormalizeVectorImageFilter_h
20 
21 #include "itkUnaryFunctorImageFilter.h"
22 
23 namespace itk
24 {
25 
31 namespace Functor {
32 
33 template< class TInput, class TOutput>
35 {
36 public:
37  //typedef typename TInput::RealValueType RealType;
38 
41  bool operator!=( const NormalizeVectorImageFunctor & other) const
42  {
43  return !( *this == other );
44  }
45  bool operator==( const NormalizeVectorImageFunctor & other ) const
46  {
47  return m_NormalizeType == other.m_NormalizeType;
48  }
49  typedef enum
50  {
51  NONE=0,
52  SUM,
55  } NormalizeType;
56 
57  inline TOutput operator()( const TInput & A ) const
58  {
59  unsigned int vectorSize = A.GetSize();
60 
61  TOutput output;
62  output.SetSize( vectorSize );
63 
64  double norm = 0;
65 
66  for ( unsigned int k=0; k < vectorSize; k++ )
67  norm += std::fabs(A[k]);
68 
69  if ( norm > 0 )
70  {
71  if (m_NormalizeType==NONE)
72  norm = 1.0;
73  else if (m_NormalizeType==L1NORM)
74  {
75  }
76  else if (m_NormalizeType==SUM)
77  {
78  norm=0;
79  for ( unsigned int k=0; k < vectorSize; k++ )
80  norm += A[k];
81  }
82  else if (m_NormalizeType==L2NORM)
83  {
84  norm=0;
85  for ( unsigned int k=0; k < vectorSize; k++ )
86  norm += A[k]*A[k];
87  norm = std::sqrt(norm);
88  }
89  if (norm!=0)
90  {
91  for ( unsigned int k=0; k < vectorSize; k++ )
92  output[k] = A[k] / norm;
93  }
94  else
95  {
96  for ( unsigned int k=0; k < vectorSize; k++ )
97  output[k] = 0;
98  }
99  }
100  else
101  {
102  for ( unsigned int k=0; k < vectorSize; k++ )
103  output[k] = 0;
104  }
105 
106  return output;
107  }
108 
109  void SetNormalizeType( NormalizeType norm)
110  {
111  m_NormalizeType = norm;
112  }
113  NormalizeType GetNormalizeType() const
114  {
115  return m_NormalizeType;
116  }
117 
118 private:
119 
120  NormalizeType m_NormalizeType;
121 };
122 }
123 
124 template <class TInputImage, class TOutputImage>
125 class ITK_EXPORT NormalizeVectorImageFilter :
126  public
127 UnaryFunctorImageFilter<TInputImage,TOutputImage,
128  Functor::NormalizeVectorImageFunctor< typename TInputImage::PixelType,
129  typename TOutputImage::PixelType> >
130 {
131 public:
134  typedef UnaryFunctorImageFilter<
135  TInputImage,TOutputImage,
136  Functor::NormalizeVectorImageFunctor< typename TInputImage::PixelType,
137  typename TOutputImage::PixelType> > Superclass;
138  typedef SmartPointer<Self> Pointer;
139  typedef SmartPointer<const Self> ConstPointer;
140 
142  itkNewMacro(Self);
143 
145  itkTypeMacro(NormalizeVectorImageFilter,
146  UnaryFunctorImageFilter);
147 
148  typedef Functor::NormalizeVectorImageFunctor< typename TInputImage::PixelType,
149  typename TOutputImage::PixelType> FunctorType;
150 
152 
153  void SetNormalizeType(NormalizeType norm)
154  {
155  this->GetFunctor().SetNormalizeType(norm);
156  this->Modified();
157  }
158 
159  NormalizeType GetNormalizeType() const
160  {
161  return this->GetFunctor().GetNormalizeType();
162  }
163 
164 protected:
166  {
167  }
168 
170 
171 
172 private:
173  NormalizeVectorImageFilter(const Self&); //purposely not implemented
174  void operator=(const Self&); //purposely not implemented
175 
176 };
177 
178 } // end namespace itk
179 
180 
181 
182 #endif
183 
184 
UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::NormalizeVectorImageFunctor< typename TInputImage::PixelType, typename TOutputImage::PixelType > > Superclass
Functor::NormalizeVectorImageFunctor< typename TInputImage::PixelType, typename TOutputImage::PixelType > FunctorType
bool operator==(const NormalizeVectorImageFunctor &other) const
Pixel-wise vector normalization.
bool operator!=(const NormalizeVectorImageFunctor &other) const