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 ===================================================================*/
16 /*=========================================================================
18 Program: Tensor ToolKit - TTK
19 Module: $URL: svn://scm.gforge.inria.fr/svn/ttk/trunk/Algorithms/itkResampleDwiImageFilter.txx $
21 Date: $Date: 2010-06-07 13:39:13 +0200 (Mo, 07 Jun 2010) $
22 Version: $Revision: 68 $
24 Copyright (c) INRIA 2010. All rights reserved.
25 See LICENSE.txt for details.
27 This software is distributed WITHOUT ANY WARRANTY; without even
28 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
29 PURPOSE. See the above copyright notices for more information.
31 =========================================================================*/
32 #ifndef _itk_ResampleDwiImageFilter_txx_
33 #define _itk_ResampleDwiImageFilter_txx_
36 #define _USE_MATH_DEFINES
38 #include "itkResampleDwiImageFilter.h"
39 #include <itkImageRegionIterator.h>
40 #include <itkImageRegion.h>
41 #include <itkResampleImageFilter.h>
42 #include <itkBSplineInterpolateImageFunction.h>
43 #include <itkNearestNeighborInterpolateImageFunction.h>
44 #include <itkLinearInterpolateImageFunction.h>
45 #include <itkWindowedSincInterpolateImageFunction.h>
50 template <class TScalarType>
51 ResampleDwiImageFilter<TScalarType>
52 ::ResampleDwiImageFilter()
53 : m_Interpolation(Interpolate_Linear)
55 this->SetNumberOfRequiredInputs( 1 );
58 template <class TScalarType>
60 ResampleDwiImageFilter<TScalarType>
63 // // initialize output image
64 // itk::Vector< double, 3 > spacing = this->GetInput()->GetSpacing();
65 // spacing[0] /= m_SamplingFactor[0];
66 // spacing[1] /= m_SamplingFactor[1];
67 // spacing[2] /= m_SamplingFactor[2];
68 // ImageRegion<3> region = this->GetInput()->GetLargestPossibleRegion();
69 // region.SetSize(0, region.GetSize(0)*m_SamplingFactor[0]);
70 // region.SetSize(1, region.GetSize(1)*m_SamplingFactor[1]);
71 // region.SetSize(2, region.GetSize(2)*m_SamplingFactor[2]);
73 itk::Point<double,3> origin = this->GetInput()->GetOrigin();
74 origin[0] -= this->GetInput()->GetSpacing()[0]/2;
75 origin[1] -= this->GetInput()->GetSpacing()[1]/2;
76 origin[2] -= this->GetInput()->GetSpacing()[2]/2;
78 origin[0] += m_NewSpacing[0]/2;
79 origin[1] += m_NewSpacing[1]/2;
80 origin[2] += m_NewSpacing[2]/2;
82 typename DwiImageType::Pointer outImage = DwiImageType::New();
83 outImage->SetSpacing( m_NewSpacing );
84 outImage->SetOrigin( origin );
85 outImage->SetDirection( this->GetInput()->GetDirection() );
86 outImage->SetLargestPossibleRegion( m_NewImageRegion );
87 outImage->SetBufferedRegion( m_NewImageRegion );
88 outImage->SetRequestedRegion( m_NewImageRegion );
89 outImage->SetVectorLength( this->GetInput()->GetVectorLength() );
92 typename itk::ResampleImageFilter<DwiChannelType, DwiChannelType>::Pointer resampler = itk::ResampleImageFilter<DwiChannelType, DwiChannelType>::New();
93 resampler->SetOutputParametersFromImage(outImage);
95 switch (m_Interpolation)
97 case Interpolate_NearestNeighbour:
99 typename itk::NearestNeighborInterpolateImageFunction<DwiChannelType>::Pointer interp = itk::NearestNeighborInterpolateImageFunction<DwiChannelType>::New();
100 resampler->SetInterpolator(interp);
103 case Interpolate_Linear:
105 typename itk::LinearInterpolateImageFunction<DwiChannelType>::Pointer interp = itk::LinearInterpolateImageFunction<DwiChannelType>::New();
106 resampler->SetInterpolator(interp);
109 case Interpolate_BSpline:
111 typename itk::BSplineInterpolateImageFunction<DwiChannelType>::Pointer interp = itk::BSplineInterpolateImageFunction<DwiChannelType>::New();
112 resampler->SetInterpolator(interp);
115 case Interpolate_WindowedSinc:
117 typename itk::WindowedSincInterpolateImageFunction<DwiChannelType, 3>::Pointer interp = itk::WindowedSincInterpolateImageFunction<DwiChannelType, 3>::New();
118 resampler->SetInterpolator(interp);
123 typename itk::LinearInterpolateImageFunction<DwiChannelType>::Pointer interp = itk::LinearInterpolateImageFunction<DwiChannelType>::New();
124 resampler->SetInterpolator(interp);
128 for (unsigned int i=0; i<this->GetInput()->GetVectorLength(); i++)
130 typename DwiChannelType::Pointer channel = DwiChannelType::New();
131 channel->SetSpacing( this->GetInput()->GetSpacing() );
132 channel->SetOrigin( this->GetInput()->GetOrigin() );
133 channel->SetDirection( this->GetInput()->GetDirection() );
134 channel->SetLargestPossibleRegion( this->GetInput()->GetLargestPossibleRegion() );
135 channel->SetBufferedRegion( this->GetInput()->GetLargestPossibleRegion() );
136 channel->SetRequestedRegion( this->GetInput()->GetLargestPossibleRegion() );
139 ImageRegionIterator<DwiChannelType> it(channel, channel->GetLargestPossibleRegion());
142 typename DwiImageType::PixelType pix = this->GetInput()->GetPixel(it.GetIndex());
147 resampler->SetInput(channel);
149 channel = resampler->GetOutput();
151 ImageRegionIterator<DwiImageType> it2(outImage, outImage->GetLargestPossibleRegion());
152 while(!it2.IsAtEnd())
154 typename DwiImageType::PixelType pix = it2.Get();
155 pix[i] = channel->GetPixel(it2.GetIndex());
161 this->SetNthOutput(0, outImage);
164 template <class TScalarType>
166 ResampleDwiImageFilter<TScalarType>
167 ::UpdateOutputInformation()
169 // Calls to superclass updateoutputinformation
170 //Superclass::UpdateOutputInformation();
172 this->GetOutput()->SetSpacing(m_NewSpacing);
173 this->GetOutput()->SetLargestPossibleRegion(m_NewImageRegion);
176 } // end of namespace