Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
itkStructureTensorEigenvalueImageFilter.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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef ITKSTRUCTURETENSOREIGENVALUEIMAGEFILTER_CPP
14 #define ITKSTRUCTURETENSOREIGENVALUEIMAGEFILTER_CPP
15 
17 #include <itkImageRegionIterator.h>
18 #include <vigra/tensorutilities.hxx>
19 #include <vigra/convolution.hxx>
20 
21 
22 template< class TInputImageType, class TOutputImageType, class TMaskImageType>
24 {
25  Superclass::GenerateOutputInformation();
26  this->GetOutput(0)->SetDirection(this->GetInput()->GetDirection());
27  this->GetOutput(0)->SetSpacing(this->GetInput()->GetSpacing());
28  this->GetOutput(0)->SetRegions(this->GetInput()->GetLargestPossibleRegion());
29  this->GetOutput(0)->Allocate();
30 
31  this->GetOutput(1)->SetDirection(this->GetInput()->GetDirection());
32  this->GetOutput(1)->SetSpacing(this->GetInput()->GetSpacing());
33  this->GetOutput(1)->SetRegions(this->GetInput()->GetLargestPossibleRegion());
34  this->GetOutput(1)->Allocate();
35 
36  this->GetOutput(2)->SetDirection(this->GetInput()->GetDirection());
37  this->GetOutput(2)->SetSpacing(this->GetInput()->GetSpacing());
38  this->GetOutput(2)->SetRegions(this->GetInput()->GetLargestPossibleRegion());
39  this->GetOutput(2)->Allocate();
40 }
41 
42 template< class TInputImageType, class TOutputImageType, class TMaskImageType>
44 {
45 
46 
47 
48  typedef typename TInputImageType::PixelType InputPixelType;
49 
50  typename TInputImageType::RegionType region = this->GetInput()->GetLargestPossibleRegion();
51  unsigned int xdim = region.GetSize(0);
52  unsigned int ydim = region.GetSize(1);
53  unsigned int zdim = region.GetSize(2);
54 
55 
56 
57  vigra::Shape3 shape(xdim,ydim,zdim);
58  vigra::MultiArrayView<3, InputPixelType, vigra::StridedArrayTag > input_image_view(
59  shape ,
60  this->GetInput()->GetBufferPointer());
61 
62  vigra::MultiArray<3, vigra::TinyVector<InputPixelType, 3> > structuretensor_image(shape);
63  vigra::MultiArray<3, vigra::TinyVector<InputPixelType, 3> > eigenvalues_image(shape);
64 
65 
66  for(unsigned int i = 0 ; i < zdim; ++i )
67  {
68  vigra::Shape2 slice_shape(xdim,ydim);
69  vigra::MultiArrayView<2, InputPixelType, vigra::StridedArrayTag > input_image_slice_view(
70  slice_shape,
71  input_image_view.data()+ (i*xdim*ydim));
72 
73  vigra::MultiArrayView<2, vigra::TinyVector<InputPixelType, 3> > structuretensor_image_slice_view(
74  slice_shape,
75  structuretensor_image.data() + (i*xdim*ydim));
76 
77  vigra::structureTensor(input_image_slice_view, structuretensor_image_slice_view, m_InnerScale, m_OuterScale);
78 
79  vigra::MultiArrayView<2, vigra::TinyVector<InputPixelType, 3> > eigenvalues_image_slice_view(
80  slice_shape,
81  eigenvalues_image.data() + (i*xdim*ydim));
82  vigra::tensorEigenRepresentation(structuretensor_image_slice_view, eigenvalues_image_slice_view);
83  }
84 
85  vigra::MultiArrayView<3, InputPixelType, vigra::StridedArrayTag > ev1_image = eigenvalues_image.bindElementChannel(0);
86  vigra::MultiArrayView<3, InputPixelType, vigra::StridedArrayTag > ev2_image = eigenvalues_image.bindElementChannel(1);
87  vigra::MultiArrayView<3, InputPixelType, vigra::StridedArrayTag > ev3_image = eigenvalues_image.bindElementChannel(2);
88 
89  for(unsigned int x = 0 ; x < xdim; ++x)
90  for(unsigned int y = 0 ; y < ydim; ++y)
91  for(unsigned int z = 0 ; z < zdim; ++z)
92  {
93  itk::Index<3> indx = {{x,y,z}};
94  this->GetOutput(0)->operator [](indx) = ev1_image(x,y,z);
95  this->GetOutput(1)->operator [](indx) = ev2_image(x,y,z);
96  this->GetOutput(2)->operator [](indx) = ev3_image(x,y,z);
97  }
98 
99 
100 }
101 
102 template< class TInputImageType, class TOutputImageType, class TMaskImageType>
104 {
105  this->m_ImageMask = maskimage;
106 }
107 
108 template< class TInputImageType, class TOutputImageType, class TMaskImageType>
110 {
111  this->SetNumberOfIndexedOutputs(3);
112  this->SetNumberOfIndexedInputs(1);
113 
114  this->SetNthOutput( 0, this->MakeOutput(0) );
115  this->SetNthOutput( 1, this->MakeOutput(1) );
116  this->SetNthOutput( 2, this->MakeOutput(2) );
117 
118 }
119 
120 template< class TInputImageType, class TOutputImageType, class TMaskImageType>
122 {
123 
124 }
125 
126 
127 
128 #endif