Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkDiffusionImageCorrectionFilter.cpp
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 
18 #ifndef MITKDIFFUSIONIMAGECORRECTIONFILTER_CPP
19 #define MITKDIFFUSIONIMAGECORRECTIONFILTER_CPP
20 
23 
24 #include <vnl/algo/vnl_symmetric_eigensystem.h>
25 #include <vnl/vnl_inverse.h>
26 
27 
29 {
30 
31 }
32 
33 
37 {
39 
40  B = A * A.transpose();
41 
42  // get the eigenvalues and eigenvectors
43  typedef double MType;
44  vnl_vector< MType > eigvals;
45  vnl_matrix< MType > eigvecs;
46  vnl_symmetric_eigensystem_compute< MType > ( B, eigvecs, eigvals );
47 
48  vnl_matrix_fixed< MType, 3, 3 > eigvecs_fixed;
49  eigvecs_fixed.set_columns(0, eigvecs );
50 
52  C.set_identity();
53 
54  vnl_vector_fixed< MType, 3 > eigvals_sqrt;
55  for(unsigned int i=0; i<3; i++)
56  {
57  C(i,i) = std::sqrt( eigvals[i] );
58  }
59 
60  TransformMatrixType S = vnl_inverse( eigvecs_fixed * C * vnl_inverse( eigvecs_fixed )) * A;
61 
62  return S;
63 }
64 
65 
67 ::CorrectDirections( const TransformsVectorType& transformations)
68 {
69  if( m_SourceImage.IsNull() )
70  {
71  mitkThrow() << " No diffusion image given! ";
72  }
73 
74  GradientDirectionContainerPointerType directions = static_cast<mitk::GradientDirectionsProperty*>( m_SourceImage->GetProperty(mitk::DiffusionPropertyHelper::GRADIENTCONTAINERPROPERTYNAME.c_str()).GetPointer() )->GetGradientDirectionsContainer();
75  GradientDirectionContainerPointerType corrected_directions =
77 
78  unsigned int transformed = 0;
79  for(size_t i=0; i< directions->Size(); i++ )
80  {
81 
82  // skip b-zero images
83  if( directions->ElementAt(i).one_norm() <= 0.0 )
84  {
85  corrected_directions->push_back( directions->ElementAt(i) );
86  continue;
87  }
88 
89  GradientDirectionType corrected = GetRotationComponent(
90  transformations.at(transformed))
91  * directions->ElementAt(i);
92  // store the corrected direction
93  corrected_directions->push_back( corrected );
94  transformed++;
95  }
96 
97  // replace the old directions with the corrected ones
98  m_SourceImage->SetProperty( mitk::DiffusionPropertyHelper::GRADIENTCONTAINERPROPERTYNAME.c_str(), mitk::GradientDirectionsProperty::New( corrected_directions ) );
99 }
100 
101 
104 {
105  if( m_SourceImage.IsNull() )
106  {
107  mitkThrow() << " No diffusion image given! ";
108  }
109  TransformsVectorType transfVec;
110  for (unsigned int i=0; i< static_cast<mitk::GradientDirectionsProperty*>( m_SourceImage->GetProperty(mitk::DiffusionPropertyHelper::GRADIENTCONTAINERPROPERTYNAME.c_str()).GetPointer() )->GetGradientDirectionsContainer()->Size();i++)
111  {
112  transfVec.push_back(transformation);
113  }
114  this->CorrectDirections(transfVec);
115 }
116 
117 #endif
std::vector< TransformMatrixType > TransformsVectorType
vnl_matrix_fixed< double, 3, 3 > TransformMatrixType
TransformMatrixType GetRotationComponent(const TransformMatrixType &)
Get the rotation component following the Finite Strain.
#define mitkThrow()
GradientDirectionContainerType::Pointer GradientDirectionContainerPointerType
void CorrectDirections(const TransformsVectorType &)
Correct each gradient direction according to the given transform.
static const std::string GRADIENTCONTAINERPROPERTYNAME
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.