13 #ifndef ITKSTRUCTURETENSOREIGENVALUEIMAGEFILTER_CPP 14 #define ITKSTRUCTURETENSOREIGENVALUEIMAGEFILTER_CPP 17 #include <itkImageRegionIterator.h> 18 #include <vigra/tensorutilities.hxx> 19 #include <vigra/convolution.hxx> 22 template<
class TInputImageType,
class TOutputImageType,
class TMaskImageType>
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();
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();
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();
42 template<
class TInputImageType,
class TOutputImageType,
class TMaskImageType>
48 typedef typename TInputImageType::PixelType InputPixelType;
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);
57 vigra::Shape3 shape(xdim,ydim,zdim);
58 vigra::MultiArrayView<3, InputPixelType, vigra::StridedArrayTag > input_image_view(
60 this->GetInput()->GetBufferPointer());
62 vigra::MultiArray<3, vigra::TinyVector<InputPixelType, 3> > structuretensor_image(shape);
63 vigra::MultiArray<3, vigra::TinyVector<InputPixelType, 3> > eigenvalues_image(shape);
66 for(
unsigned int i = 0 ; i < zdim; ++i )
68 vigra::Shape2 slice_shape(xdim,ydim);
69 vigra::MultiArrayView<2, InputPixelType, vigra::StridedArrayTag > input_image_slice_view(
71 input_image_view.data()+ (i*xdim*ydim));
73 vigra::MultiArrayView<2, vigra::TinyVector<InputPixelType, 3> > structuretensor_image_slice_view(
75 structuretensor_image.data() + (i*xdim*ydim));
77 vigra::structureTensor(input_image_slice_view, structuretensor_image_slice_view, m_InnerScale, m_OuterScale);
79 vigra::MultiArrayView<2, vigra::TinyVector<InputPixelType, 3> > eigenvalues_image_slice_view(
81 eigenvalues_image.data() + (i*xdim*ydim));
82 vigra::tensorEigenRepresentation(structuretensor_image_slice_view, eigenvalues_image_slice_view);
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);
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)
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);
102 template<
class TInputImageType,
class TOutputImageType,
class TMaskImageType>
105 this->m_ImageMask = maskimage;
108 template<
class TInputImageType,
class TOutputImageType,
class TMaskImageType>
111 this->SetNumberOfIndexedOutputs(3);
112 this->SetNumberOfIndexedInputs(1);
114 this->SetNthOutput( 0, this->MakeOutput(0) );
115 this->SetNthOutput( 1, this->MakeOutput(1) );
116 this->SetNthOutput( 2, this->MakeOutput(2) );
120 template<
class TInputImageType,
class TOutputImageType,
class TMaskImageType>
void SetImageMask(TMaskImageType *maskimage)