18 #include <itkResampleImageFilter.h>
21 #include <itkImageFileWriter.h>
22 #include <itkIdentityTransform.h>
23 #include <itkLinearInterpolateImageFunction.h>
24 #include <itkNearestNeighborInterpolateImageFunction.h>
27 m_ResampledX(100), m_ResampledY(100),m_ResampledZ(1)
44 if ( (inputImage->GetDimension() > 3) || (inputImage->GetDimension() < 2) )
46 MITK_ERROR <<
"mitk::TofImageDownsamplingFilter:GenerateData works only with 2D and 3D images, sorry." << std::endl;
47 itkExceptionMacro(
"mitk::TofImageDownsamplingFilter:GenerateData works only with 2D and 3D images, sorry.");
51 if ( (inputImage->GetDimension(0)<m_ResampledX) || (inputImage->GetDimension(1)<m_ResampledY) || (inputImage->GetDimension(2)<m_ResampledZ) )
53 MITK_ERROR <<
"mitk::TofImageDownsamplingFilter:GenerateData only downsamples. Your requested dimensions exceed the original image dimensions." << std::endl;
54 itkExceptionMacro(
"mitk::TofImageDownsamplingFilter:GenerateData only downsamples. Your requested dimensions exceed the original image dimensions.");
58 if ( (m_ResampledX < 1) || (m_ResampledY < 1)|| (m_ResampledZ < 1) )
60 MITK_ERROR <<
"mitk::TofImageDownsamplingFilter:GenerateData works only for positive input dimensions " << std::endl;
61 itkExceptionMacro(
"mitk::TofImageDownsamplingFilter:GenerateData works only for positive input dimensions");
65 switch(inputImage->GetDimension())
82 template<
typename TPixel,
unsigned int VImageDimension>
86 typedef itk::Image< TPixel, VImageDimension > ItkImageType;
89 typedef itk::ResampleImageFilter<ItkImageType,ItkImageType> ResamplerFilterType;
90 typedef itk::IdentityTransform<double, VImageDimension> TransformType;
91 typedef itk::NearestNeighborInterpolateImageFunction<ItkImageType, double > InterpolatorType;
92 typedef typename ItkImageType::SizeType::SizeValueType SizeValueType;
100 typename ItkImageType::SizeType inputSize = itkImage->GetLargestPossibleRegion().GetSize();
101 typename ItkImageType::SizeType size;
103 size[0] =
static_cast< SizeValueType
>( m_ResampledX );
104 size[1] =
static_cast< SizeValueType
>( m_ResampledY );
105 size[2] =
static_cast< SizeValueType
>( m_ResampledZ );
108 const typename ItkImageType::SpacingType& inputSpacing = itkImage->GetSpacing();
109 typename ItkImageType::SpacingType outputSpacing;
111 outputSpacing[0] = inputSpacing[0] * ( inputSize[0]/ m_ResampledX );
112 outputSpacing[1] = inputSpacing[1] * ( inputSize[1]/ m_ResampledY );
113 outputSpacing[2] = inputSpacing[2] * ( inputSize[2]/ m_ResampledZ );
116 mitkspacing[0] = outputSpacing[0];
117 mitkspacing[1] = outputSpacing[1];
118 mitkspacing[2] = outputSpacing[2];
121 mitkorig[0] = itkImage->GetOrigin()[0];
122 mitkorig[1] = itkImage->GetOrigin()[1];
126 transform->SetIdentity();
127 resampler->SetTransform(transform);
128 resampler->SetInterpolator(interpolator);
129 resampler->SetOutputSpacing(outputSpacing);
130 resampler->SetOutputOrigin(itkImage->GetOrigin());
131 resampler->SetSize(size);
132 resampler->SetInput(itkImage);
133 resampler->UpdateLargestPossibleRegion();
137 resultImage->SetSpacing(mitkspacing);
138 resultImage->SetOrigin(mitkorig);
itk::SmartPointer< Self > Pointer
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
void ItkImageResampling(const itk::Image< TPixel, VImageDimension > *itkImage)
Templated method for ITK image type which performs the resampling with an itk filter.
virtual void GenerateData() override
Method generating the output of this filter. Called in the updated process of the pipeline...
void CastToMitkImage(const itk::SmartPointer< ItkOutputImageType > &itkimage, itk::SmartPointer< mitk::Image > &mitkoutputimage)
Cast an itk::Image (with a specific type) to an mitk::Image.
ToFImageDownsamplingFilter()
Standard constructor.
OutputType * GetOutput()
Get the output data of this image source object.
~ToFImageDownsamplingFilter()
Standard destructor.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.