Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
itkDiffusionTensor3DNearestCorrection.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Diffusion Applications
4 Module: $HeadURL$
5 Language: C++
6 Date: $Date$
7 Version: $Revision$
8
9 Copyright (c) Brigham and Women's Hospital (BWH) All Rights Reserved.
10
11 See License.txt or http://www.slicer.org/copyright/copyright.txt for details.
12
13==========================================================================*/
14#ifndef itkDiffusionTensor3DNearestCorrection_h
15#define itkDiffusionTensor3DNearestCorrection_h
16
17#include "itkUnaryFunctorImageFilter.h"
18#include "itkMath.h"
19#include <itkMatrix.h>
21
22namespace itk
23{
24
40namespace Functor
41{
42
43template <class TInput, class TOutput>
45{
46public:
49 bool operator!=(const DiffusionTensor3DNearest& other) const { return *this != other; }
50
51 bool operator==(const DiffusionTensor3DNearest& other) const { return !(*this != other); }
52
53 inline DiffusionTensor3D<TOutput> operator()(const DiffusionTensor3D<TInput>& tensorA)
54 {
55 DiffusionTensor3DExtended<double> tensorDouble(tensorA);
56 Matrix<double, 3, 3> B;
57 Matrix<double, 3, 3> A;
58 Matrix<double, 3, 3> transpose;
59 Matrix<double, 3, 3> H;
60 Matrix<double, 3, 3> mat;
61 A = tensorDouble.GetTensor2Matrix();
62 transpose = A.GetTranspose();
63 B = (A + transpose) / 2;
64 transpose = B.GetTranspose();
65 H = transpose * B;
66 tensorDouble.SetTensorFromMatrix(H);
67
70 tensorDouble.ComputeEigenAnalysis(eigenValues, eigenVectors);
71 for (int i = 0; i < 3; i++)
72 {
73 mat[i][i] = sqrt(eigenValues[i]);
74 }
75 eigenVectors = eigenVectors.GetTranspose();
76 H = eigenVectors * mat * eigenVectors.GetInverse();
77 mat = (B + H) / 2;
78 tensorDouble.SetTensorFromMatrix(mat);
79 tensorDouble.ComputeEigenAnalysis(eigenValues, eigenVectors); // sometimes very small negative eigenvalues
80 // appear; we suppress them
81 mat.Fill(0);
82 for (int i = 0; i < 3; i++)
83 {
84 mat[i][i] = (eigenValues[i] <= 0 ? ITK_DIFFUSION_TENSOR_3D_ZERO : eigenValues[i]);
85 }
86 eigenVectors = eigenVectors.GetTranspose();
87 tensorDouble.SetTensorFromMatrix<double>(eigenVectors * mat * eigenVectors.GetInverse());
88
89 DiffusionTensor3D<TOutput> tensor;
90 for (int i = 0; i < 6; i++)
91 {
92 tensor[i] = (TOutput)tensorDouble[i];
93 }
94 return tensor;
95 }
96};
97} // namespace Functor
98
99template <class TInputImage, class TOutputImage>
101 : public UnaryFunctorImageFilter<TInputImage,
102 TOutputImage,
103 Functor::DiffusionTensor3DNearest<typename TInputImage::PixelType::ComponentType, typename TOutputImage::PixelType::ComponentType>>
104{
105public:
108 typedef UnaryFunctorImageFilter<TInputImage, TOutputImage, Functor::DiffusionTensor3DNearest<typename TInputImage::PixelType, typename TOutputImage::PixelType>> Superclass;
109 typedef SmartPointer<Self> Pointer;
110 typedef SmartPointer<const Self> ConstPointer;
111
114 void operator=(const Self&) = delete;
115
118
121
122#ifdef ITK_USE_CONCEPT_CHECKING
124 itkConceptMacro(InputTensorTypeCheck, (Concept::SameType<DiffusionTensor3D<typename TInputImage::PixelType::ComponentType>, typename TInputImage::PixelType>));
125 itkConceptMacro(OutputTensorTypeCheck, (Concept::SameType<DiffusionTensor3D<typename TOutputImage::PixelType::ComponentType>, typename TOutputImage::PixelType>));
126
128#endif
129protected:
132};
133
134} // end namespace itk
135
136#endif
void SetTensorFromMatrix(Matrix< C, 3, 3 > matrix)
itkTypeMacro(DiffusionTensor3DNearestCorrectionFilter, UnaryFunctorImageFilter)
UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::DiffusionTensor3DNearest< typename TInputImage::PixelType, typename TOutputImage::PixelType > > Superclass
~DiffusionTensor3DNearestCorrectionFilter() override=default
DiffusionTensor3DNearestCorrectionFilter(const Self &)=delete
DiffusionTensor3D< TOutput > operator()(const DiffusionTensor3D< TInput > &tensorA)
bool operator!=(const DiffusionTensor3DNearest &other) const
bool operator==(const DiffusionTensor3DNearest &other) const
#define ITK_DIFFUSION_TENSOR_3D_ZERO
Simplified inverse ITK transforms.