ANIMA  4.0
animaDTIEstimationImageFilter.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include <itkVectorImage.h>
5 #include <itkImage.h>
6 
7 namespace anima
8 {
9 
10 template <class InputPixelScalarType, class OutputPixelScalarType>
12 public anima::MaskedImageToImageFilter < itk::Image<InputPixelScalarType,3>, itk::VectorImage<OutputPixelScalarType,3> >
13 {
14 public:
17  typedef itk::Image<InputPixelScalarType,3> InputImageType;
18  typedef itk::VectorImage<OutputPixelScalarType,3> OutputImageType;
19  typedef itk::Image<OutputPixelScalarType,3> OutputB0ImageType;
20  typedef OutputImageType DTIImageType;
21  typedef itk::Image<InputPixelScalarType,4> Image4DType;
23  typedef itk::SmartPointer<Self> Pointer;
24  typedef itk::SmartPointer<const Self> ConstPointer;
25 
27  itkNewMacro(Self)
28 
29 
31 
32 
33  typedef typename InputImageType::Pointer InputImagePointer;
34  typedef typename OutputImageType::Pointer OutputImagePointer;
35 
37  typedef typename Superclass::MaskImageType MaskImageType;
38  typedef typename Superclass::InputImageRegionType InputImageRegionType;
39  typedef typename Superclass::OutputImageRegionType OutputImageRegionType;
40 
42  {
43  Self *filter;
44  std::vector <double> dwi, predictedValues;
45  vnl_matrix <double> rotationMatrix, workTensor;
46  vnl_diag_matrix <double> workEigenValues;
47  };
48 
49  void SetBValuesList(std::vector <double> bValuesList ) {m_BValuesList = bValuesList;}
50 
51  itkSetMacro(B0Threshold, double)
52  itkGetMacro(B0Threshold, double)
53 
54  itkGetMacro(EstimatedB0Image, OutputB0ImageType *)
55  itkGetMacro(EstimatedVarianceImage, OutputB0ImageType *)
56 
57  void AddGradientDirection(unsigned int i, vnl_vector_fixed<double,3> &grad);
58 
59 protected:
61  : Superclass()
62  {
63  m_BValuesList.clear();
64 
65  m_B0Threshold = 0;
66  m_EstimatedB0Image = NULL;
67  m_EstimatedVarianceImage = NULL;
68  }
69 
71 
72  void CheckComputationMask() ITK_OVERRIDE;
73 
74  void GenerateOutputInformation() ITK_OVERRIDE;
75  void BeforeThreadedGenerateData() ITK_OVERRIDE;
76  void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) ITK_OVERRIDE;
77 
78  static double OptimizationFunction(const std::vector<double> &x, std::vector<double> &grad, void *func_data);
79  double ComputeCostAtPosition(const std::vector<double> &x, const std::vector <double> &observedData,
80  std::vector <double> &predictedValues, vnl_matrix <double> &rotationMatrix,
81  vnl_matrix <double> &workTensor, vnl_diag_matrix <double> &workEigenValues);
82 
83  double ComputeB0AndVarianceFromTensorVector(const vnl_matrix <double> &tensorValue, const std::vector <double> &dwiSignal, double &outVarianceValue);
84 
85 private:
86  ITK_DISALLOW_COPY_AND_ASSIGN(DTIEstimationImageFilter);
87 
88  std::vector <double> m_BValuesList;
89  std::vector< vnl_vector_fixed<double,3> > m_GradientDirections;
90 
91  double m_B0Threshold;
92  typename OutputB0ImageType::Pointer m_EstimatedB0Image, m_EstimatedVarianceImage;
93 
94  static const unsigned int m_NumberOfComponents = 6;
95 
96  vnl_matrix <double> m_InitialMatrixSolver;
97 };
98 
99 } // end of namespace anima
100 
void AddGradientDirection(unsigned int i, vnl_vector_fixed< double, 3 > &grad)
double ComputeB0AndVarianceFromTensorVector(const vnl_matrix< double > &tensorValue, const std::vector< double > &dwiSignal, double &outVarianceValue)
itk::Image< OutputPixelScalarType, 3 > OutputB0ImageType
Superclass::OutputImageRegionType OutputImageRegionType
itk::VectorImage< OutputPixelScalarType, 3 > OutputImageType
itk::Image< InputPixelScalarType, 4 > Image4DType
static double OptimizationFunction(const std::vector< double > &x, std::vector< double > &grad, void *func_data)
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) ITK_OVERRIDE
DTIEstimationImageFilter< InputPixelScalarType, OutputPixelScalarType > Self
itk::Image< InputPixelScalarType, 3 > InputImageType
Superclass::InputImageRegionType InputImageRegionType
itk::SmartPointer< const Self > ConstPointer
void SetBValuesList(std::vector< double > bValuesList)
anima::MaskedImageToImageFilter< InputImageType, OutputImageType > Superclass
double ComputeCostAtPosition(const std::vector< double > &x, const std::vector< double > &observedData, std::vector< double > &predictedValues, vnl_matrix< double > &rotationMatrix, vnl_matrix< double > &workTensor, vnl_diag_matrix< double > &workEigenValues)