DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkNormalizeODFImageFilter.h
Go to the documentation of this file.
1 
18 #ifndef __itkNormalizeODFImageFilter_h
19 #define __itkNormalizeODFImageFilter_h
20 
21 #include "itkUnaryFunctorImageFilter.h"
22 
23 namespace itk
24 {
25 namespace Functor
26 {
28 template <class TInput, class TOutput>
30 {
31 public:
33  {
34  m_ODFType=SH;
35  }
36 
38  {
39  }
40 
41  bool operator!=(const ODFNormlizeFunctor & other) const
42  {
43  return !( *this == other );
44  }
45 
46  bool operator==(const ODFNormlizeFunctor & other) const
47  {
48  return other.m_ODFType == m_ODFType;
49  }
50 
51  typedef enum
52  {
53  SH=0,
55  } ODFType;
56 
57  inline TOutput operator()(const TInput & A) const
58  {
59  unsigned int size = A.GetSize();
60  TOutput value;
61  value.SetSize( size );
62 
63  double norm = 0;
64  for ( unsigned int k=0; k < size; k++ )
65  norm += std::fabs(A[k]);
66  if (norm>0)
67  {
68  double normFactor = 1.0;
69  if (m_ODFType==SH && std::fabs(A[0])>1e-8)
70  {
71  normFactor = 1.0/std::sqrt(4*M_PI) * 1.0/A[0];
72  }
73  if (m_ODFType==SAMPLE)
74  {
75  double sum = 0;
76  for ( unsigned int k=0; k < size; k++ )
77  sum += A[k];
78  if (std::fabs(sum)>1e-8)
79  normFactor = 1.0/sum * double(size)/(4*M_PI);
80  }
81  for ( unsigned int k=0; k < size; k++ )
82  value[k] = A[k]*normFactor;
83  }
84  else
85  {
86  for ( unsigned int k=0; k < size; k++ )
87  value[k] = 0;
88  }
89  return value;
90  }
91 
92  void SetODFType(ODFType odfType)
93  {
94  this->m_ODFType = odfType;
95  }
96 
97  const ODFType & GetODFType() const
98  {
99  return m_ODFType;
100  }
101 
102  ODFType m_ODFType;
103 
104 };
105 }
106 
115 template <class TInputImage, class TOutputImage>
116 class ITK_EXPORT NormalizeODFImageFilter :
117  public
118  UnaryFunctorImageFilter<TInputImage, TOutputImage,
119  Functor::ODFNormlizeFunctor< typename TInputImage::PixelType,typename TOutputImage::PixelType> >
120 {
121 public:
124  typedef UnaryFunctorImageFilter<
125  TInputImage, TOutputImage,
127  typename TInputImage::PixelType, typename TOutputImage::PixelType> > Superclass;
128 
129  typedef SmartPointer<Self> Pointer;
130  typedef SmartPointer<const Self> ConstPointer;
131 
133  itkNewMacro( Self );
134 
136  itkTypeMacro( NormalizeODFImageFilter, UnaryFunctorImageFilter );
137 
138  typedef Functor::ODFNormlizeFunctor< typename TInputImage::PixelType,
139  typename TOutputImage::PixelType> FunctorType;
140 
141  typedef typename FunctorType::ODFType ODFType;
142 
144  void SetODFType( ODFType type )
145  {
146  if( type != this->GetFunctor().GetODFType() )
147  {
148  this->GetFunctor().SetODFType( type );
149  this->Modified();
150  }
151  }
152 
153  const ODFType & GetODFType() const
154  {
155  return this->GetFunctor().GetODFType();
156  }
157 
158 protected:
160  {
161  }
162 
164  {
165  }
166 
167  void PrintSelf(std::ostream & os, Indent indent ) const ITK_OVERRIDE
168  {
169  Superclass::PrintSelf( os, indent );
170 
171  os << indent << "ODFType: " << this->GetODFType() << std::endl;
172  }
173 
174 private:
175  NormalizeODFImageFilter(const Self &); // purposely not implemented
176  void operator=(const Self &); // purposely not implemented
177 };
178 } // end namespace itk
179 
180 
181 #endif
182 
TOutput operator()(const TInput &A) const
bool operator!=(const ODFNormlizeFunctor &other) const
Functor::ODFNormlizeFunctor< typename TInputImage::PixelType, typename TOutputImage::PixelType > FunctorType
SmartPointer< const Self > ConstPointer
#define ITK_OVERRIDE
Definition: utlITKMacro.h:46
void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
#define M_PI
Definition: utlCoreMacro.h:57
Normalize the input ODF such that the output ODF has unit integral. The input ODF can be represented ...
UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::ODFNormlizeFunctor< typename TInputImage::PixelType, typename TOutputImage::PixelType > > Superclass
bool operator==(const ODFNormlizeFunctor &other) const