Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
itkTensorDerivedMeasurementsFilter.txx
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef __itkTensorDerivedMeasurementsFilter_txx
18 #define __itkTensorDerivedMeasurementsFilter_txx
19 
20 
21 #include <itkImageRegionIterator.h>
22 
23 
24 namespace itk {
25 
26  template <class TPixel>
27  TensorDerivedMeasurementsFilter<TPixel>::TensorDerivedMeasurementsFilter() : m_Measure(AD)
28  {
29  }
30 
31  template <class TPixel>
32  void TensorDerivedMeasurementsFilter<TPixel>::GenerateData()
33  {
34  typename TensorImageType::Pointer tensorImage = static_cast< TensorImageType * >( this->ProcessObject::GetInput(0) );
35  typedef ImageRegionConstIterator< TensorImageType > TensorImageIteratorType;
36  typedef ImageRegionIterator< OutputImageType > OutputImageIteratorType;
37 
38 
39  typename OutputImageType::Pointer outputImage =
40  static_cast< OutputImageType * >(this->ProcessObject::GetPrimaryOutput());
41 
42  typename TensorImageType::RegionType region = tensorImage->GetLargestPossibleRegion();
43 
44 
45  outputImage->SetSpacing( tensorImage->GetSpacing() ); // Set the image spacing
46  outputImage->SetOrigin( tensorImage->GetOrigin() ); // Set the image origin
47  outputImage->SetDirection( tensorImage->GetDirection() ); // Set the image direction
48  outputImage->SetRegions( tensorImage->GetLargestPossibleRegion());
49  outputImage->Allocate();
50 
51  TensorImageIteratorType tensorIt(tensorImage, tensorImage->GetLargestPossibleRegion());
52  OutputImageIteratorType outputIt(outputImage, outputImage->GetLargestPossibleRegion());
53 
54  tensorIt.GoToBegin();
55  outputIt.GoToBegin();
56 
57  while(!tensorIt.IsAtEnd() && !outputIt.IsAtEnd()){
58 
59  TensorType tensor = tensorIt.Get();
60 
61  switch(m_Measure)
62  {
63  case FA:
64  {
65  TPixel diffusionIndex = tensor.GetFractionalAnisotropy();
66  outputIt.Set(diffusionIndex);
67  break;
68  }
69  case RA:
70  {
71  TPixel diffusionIndex = tensor.GetRelativeAnisotropy();
72  outputIt.Set(diffusionIndex);
73  break;
74  }
75  case AD:
76  {
77  // eigenvalues are sorted in ascending order by default because the
78  // itk::SymmetricEigenAnalysis defaults are not touched in the tensor implementation
79  typename TensorType::EigenValuesArrayType evs;
80  tensor.ComputeEigenValues(evs);
81  outputIt.Set(evs[2]);
82  break;
83  }
84  case RD:
85  {
86  // eigenvalues are sorted in ascending order by default because the
87  // itk::SymmetricEigenAnalysis defaults are not touched in the tensor implementation
88  typename TensorType::EigenValuesArrayType evs;
89  tensor.ComputeEigenValues(evs);
90  outputIt.Set((evs[0]+evs[1])/2.0);
91 
92  break;
93  }
94  case CA:
95  {
96  // eigenvalues are sorted in ascending order by default because the
97  // itk::SymmetricEigenAnalysis defaults are not touched in the tensor implementation
98  typename TensorType::EigenValuesArrayType evs;
99  tensor.ComputeEigenValues(evs);
100  if (evs[2] == 0)
101  {
102  outputIt.Set(0);
103  break;
104  }
105  outputIt.Set(1.0-(evs[0]+evs[1])/(2.0*evs[2]));
106  break;
107  }
108  case L2:
109  {
110  // eigenvalues are sorted in ascending order by default because the
111  // itk::SymmetricEigenAnalysis defaults are not touched in the tensor implementation
112  typename TensorType::EigenValuesArrayType evs;
113  tensor.ComputeEigenValues(evs);
114  outputIt.Set(evs[1]);
115  break;
116  }
117  case L3:
118  {
119  // eigenvalues are sorted in ascending order by default because the
120  // itk::SymmetricEigenAnalysis defaults are not touched in the tensor implementation
121  typename TensorType::EigenValuesArrayType evs;
122  tensor.ComputeEigenValues(evs);
123  outputIt.Set(evs[0]);
124  break;
125  }
126  case MD:
127  {
128  typename TensorType::EigenValuesArrayType evs;
129  tensor.ComputeEigenValues(evs);
130  outputIt.Set((evs[0]+evs[1]+evs[2])/3.0);
131  break;
132  }
133  }
134 
135  ++tensorIt;
136  ++outputIt;
137  }
138 
139 
140  }
141 
142 
143 }
144 
145 #endif // __itkTensorDerivedMeasurements_txx