1 /*===================================================================
3 The Medical Imaging Interaction Toolkit (MITK)
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 See LICENSE.txt or http://www.mitk.org for details.
15 ===================================================================*/
17 #ifndef __itkTensorDerivedMeasurementsFilter_txx
18 #define __itkTensorDerivedMeasurementsFilter_txx
21 #include <itkImageRegionIterator.h>
26 template <class TPixel>
27 TensorDerivedMeasurementsFilter<TPixel>::TensorDerivedMeasurementsFilter() : m_Measure(AD)
31 template <class TPixel>
32 void TensorDerivedMeasurementsFilter<TPixel>::GenerateData()
34 typename TensorImageType::Pointer tensorImage = static_cast< TensorImageType * >( this->ProcessObject::GetInput(0) );
35 typedef ImageRegionConstIterator< TensorImageType > TensorImageIteratorType;
36 typedef ImageRegionIterator< OutputImageType > OutputImageIteratorType;
39 typename OutputImageType::Pointer outputImage =
40 static_cast< OutputImageType * >(this->ProcessObject::GetPrimaryOutput());
42 typename TensorImageType::RegionType region = tensorImage->GetLargestPossibleRegion();
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();
51 TensorImageIteratorType tensorIt(tensorImage, tensorImage->GetLargestPossibleRegion());
52 OutputImageIteratorType outputIt(outputImage, outputImage->GetLargestPossibleRegion());
57 while(!tensorIt.IsAtEnd() && !outputIt.IsAtEnd()){
59 TensorType tensor = tensorIt.Get();
65 TPixel diffusionIndex = tensor.GetFractionalAnisotropy();
66 outputIt.Set(diffusionIndex);
71 TPixel diffusionIndex = tensor.GetRelativeAnisotropy();
72 outputIt.Set(diffusionIndex);
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);
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);
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);
105 outputIt.Set(1.0-(evs[0]+evs[1])/(2.0*evs[2]));
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]);
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]);
128 typename TensorType::EigenValuesArrayType evs;
129 tensor.ComputeEigenValues(evs);
130 outputIt.Set((evs[0]+evs[1]+evs[2])/3.0);
145 #endif // __itkTensorDerivedMeasurements_txx