/*
Image resampling with several interpolations and Gaussian filtering included.
*/
- //--------------------------------------------------------------------
-
- template <class TInputImage, class TOutputImage=TInputImage>
- class ITK_EXPORT ResampleImageWithOptionsFilter:
- public itk::ImageToImageFilter<TInputImage, TOutputImage> {
+ //--------------------------------------------------------------------
+ template <class InputImageType, class OutputImageType=InputImageType>
+ class ITK_EXPORT ResampleImageWithOptionsFilter:
+ public itk::ImageToImageFilter<InputImageType, OutputImageType> {
public:
- /** Standard class typedefs. */
- typedef ResampleImageWithOptionsFilter Self;
- typedef itk::ImageToImageFilter<TInputImage, TOutputImage> Superclass;
- typedef itk::SmartPointer<Self> Pointer;
- typedef itk::SmartPointer<const Self> ConstPointer;
+ /** Standard class typedefs. */
+ typedef ResampleImageWithOptionsFilter Self;
+ typedef itk::ImageToImageFilter<InputImageType, OutputImageType> Superclass;
+ typedef itk::SmartPointer<Self> Pointer;
+ typedef itk::SmartPointer<const Self> ConstPointer;
- /** Method for creation through the object factory. */
- itkNewMacro(Self);
+ /** Method for creation through the object factory. */
+ itkNewMacro(Self);
- /** Run-time type information (and related methods). */
- itkTypeMacro(ResampleImageWithOptionsFilter, ImageToImageFilter);
-
- /** Some convenient typedefs. */
- typedef TInputImage InputImageType;
- typedef typename InputImageType::ConstPointer InputImageConstPointer;
- typedef typename InputImageType::Pointer InputImagePointer;
- typedef typename InputImageType::RegionType InputImageRegionType;
- typedef typename InputImageType::PixelType InputImagePixelType;
- typedef typename InputImageType::SpacingType InputImageSpacingType;
- typedef typename InputImageType::SizeType InputImageSizeType;
+ /** Run-time type information (and related methods). */
+ itkTypeMacro(ResampleImageWithOptionsFilter, ImageToImageFilter);
+
+ /** Some convenient typedefs. */
+ typedef typename InputImageType::ConstPointer InputImageConstPointer;
+ typedef typename InputImageType::Pointer InputImagePointer;
+ typedef typename InputImageType::RegionType InputImageRegionType;
+ typedef typename InputImageType::PixelType InputImagePixelType;
+ typedef typename InputImageType::SpacingType InputImageSpacingType;
+ typedef typename InputImageType::SizeType InputImageSizeType;
- typedef TOutputImage OutputImageType;
- typedef typename OutputImageType::ConstPointer OutputImageConstPointer;
- typedef typename OutputImageType::Pointer OutputImagePointer;
- typedef typename OutputImageType::RegionType OutputImageRegionType;
- typedef typename OutputImageType::PixelType OutputImagePixelType;
- typedef typename OutputImageType::SpacingType OutputImageSpacingType;
- typedef typename OutputImageType::SizeType OutputImageSizeType;
+ typedef typename OutputImageType::ConstPointer OutputImageConstPointer;
+ typedef typename OutputImageType::Pointer OutputImagePointer;
+ typedef typename OutputImageType::RegionType OutputImageRegionType;
+ typedef typename OutputImageType::PixelType OutputImagePixelType;
+ typedef typename OutputImageType::SpacingType OutputImageSpacingType;
+ typedef typename OutputImageType::SizeType OutputImageSizeType;
- typedef itk::AffineTransform<double, InputImageType::ImageDimension> TransformType;
- typedef typename InputImageType::SpacingType GaussianSigmaType;
-
- /** ImageDimension constants */
- itkStaticConstMacro(InputImageDimension, unsigned int,
- TInputImage::ImageDimension);
- itkStaticConstMacro(OutputImageDimension, unsigned int,
- TOutputImage::ImageDimension);
- itkConceptMacro(SameDimensionCheck,
- (itk::Concept::SameDimension<InputImageDimension, OutputImageDimension>));
-
- /** Interpolation types */
- typedef enum {
- NearestNeighbor = 0,
- Linear = 1,
- BSpline = 2,
- B_LUT = 3,
- WSINC
- } InterpolationTypeEnumeration;
-
- /** Input : image to resample */
- void SetInput(const InputImageType * image);
+ typedef itk::AffineTransform<double, InputImageType::ImageDimension> TransformType;
+ typedef typename InputImageType::SpacingType GaussianSigmaType;
+
+ /** Interpolation types */
+ typedef enum {
+ NearestNeighbor = 0,
+ Linear = 1,
+ BSpline = 2,
+ B_LUT = 3,
+ WSINC = 4
+ } InterpolationTypeEnumeration;
+
+ /** ImageDimension constants */
+ itkStaticConstMacro(InputImageDimension, unsigned int,
+ InputImageType::ImageDimension);
+ itkStaticConstMacro(OutputImageDimension, unsigned int,
+ OutputImageType::ImageDimension);
+ itkConceptMacro(SameDimensionCheck,
+ (itk::Concept::SameDimension<InputImageDimension, OutputImageDimension>));
+
+ /** Input : image to resample */
+ void SetInput(const InputImageType * image);
- /** ImageDimension constants */
- itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension);
-
- // Options
- itkGetMacro(LastDimensionIsTime, bool);
- itkSetMacro(LastDimensionIsTime, bool);
- itkSetMacro(OutputIsoSpacing, double);
- itkGetMacro(OutputIsoSpacing, double);
- itkSetMacro(OutputSpacing, OutputImageSpacingType);
- itkGetMacro(OutputSpacing, OutputImageSpacingType);
- itkSetMacro(OutputSize, OutputImageSizeType);
- itkGetMacro(OutputSize, OutputImageSizeType);
- itkGetMacro(InterpolationType, InterpolationTypeEnumeration);
- itkSetMacro(InterpolationType, InterpolationTypeEnumeration);
- itkGetMacro(GaussianFilteringEnabled, bool);
- itkSetMacro(GaussianFilteringEnabled, bool);
- itkGetMacro(BSplineOrder, int);
- itkSetMacro(BSplineOrder, int);
- itkGetMacro(BLUTSamplingFactor, int);
- itkSetMacro(BLUTSamplingFactor, int);
- itkGetMacro(Transform, typename TransformType::Pointer);
- itkSetMacro(Transform, typename TransformType::Pointer);
- itkGetMacro(GaussianSigma, GaussianSigmaType);
- itkSetMacro(GaussianSigma, GaussianSigmaType);
- itkGetMacro(DefaultPixelValue, OutputImagePixelType);
- itkSetMacro(DefaultPixelValue, OutputImagePixelType);
- itkGetMacro(VerboseOptions, bool);
- itkSetMacro(VerboseOptions, bool);
+ /** ImageDimension constants */
+ itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension);
+
+ // Options
+ itkGetMacro(LastDimensionIsTime, bool);
+ itkSetMacro(LastDimensionIsTime, bool);
+ itkSetMacro(OutputIsoSpacing, double);
+ itkGetMacro(OutputIsoSpacing, double);
+ itkSetMacro(OutputSpacing, OutputImageSpacingType);
+ itkGetMacro(OutputSpacing, OutputImageSpacingType);
+ itkSetMacro(OutputSize, OutputImageSizeType);
+ itkGetMacro(OutputSize, OutputImageSizeType);
+ itkGetMacro(InterpolationType, InterpolationTypeEnumeration);
+ itkSetMacro(InterpolationType, InterpolationTypeEnumeration);
+ itkGetMacro(GaussianFilteringEnabled, bool);
+ itkSetMacro(GaussianFilteringEnabled, bool);
+ itkGetMacro(BSplineOrder, int);
+ itkSetMacro(BSplineOrder, int);
+ itkGetMacro(BLUTSamplingFactor, int);
+ itkSetMacro(BLUTSamplingFactor, int);
+ itkGetMacro(Transform, typename TransformType::Pointer);
+ itkSetMacro(Transform, typename TransformType::Pointer);
+ itkGetMacro(GaussianSigma, GaussianSigmaType);
+ itkSetMacro(GaussianSigma, GaussianSigmaType);
+ itkGetMacro(DefaultPixelValue, OutputImagePixelType);
+ itkSetMacro(DefaultPixelValue, OutputImagePixelType);
+ itkGetMacro(VerboseOptions, bool);
+ itkSetMacro(VerboseOptions, bool);
protected:
- ResampleImageWithOptionsFilter();
- virtual ~ResampleImageWithOptionsFilter() {}
+ ResampleImageWithOptionsFilter();
+ virtual ~ResampleImageWithOptionsFilter() {}
- bool m_LastDimensionIsTime;
- double m_OutputIsoSpacing;
- InterpolationTypeEnumeration m_InterpolationType;
- bool m_GaussianFilteringEnabled;
- int m_BSplineOrder;
- int m_BLUTSamplingFactor;
- OutputImageSizeType m_OutputSize;
- OutputImageSpacingType m_OutputSpacing;
- typename TransformType::Pointer m_Transform;
- GaussianSigmaType m_GaussianSigma;
- OutputImagePixelType m_DefaultPixelValue;
- bool m_VerboseOptions;
- OutputImageRegionType m_OutputRegion;
-
- virtual void GenerateInputRequestedRegion();
- virtual void GenerateOutputInformation();
- virtual void GenerateData();
+ bool m_LastDimensionIsTime;
+ double m_OutputIsoSpacing;
+ InterpolationTypeEnumeration m_InterpolationType;
+ bool m_GaussianFilteringEnabled;
+ int m_BSplineOrder;
+ int m_BLUTSamplingFactor;
+ OutputImageSizeType m_OutputSize;
+ OutputImageSpacingType m_OutputSpacing;
+ typename TransformType::Pointer m_Transform;
+ GaussianSigmaType m_GaussianSigma;
+ OutputImagePixelType m_DefaultPixelValue;
+ bool m_VerboseOptions;
+ OutputImageRegionType m_OutputRegion;
+
+ virtual void GenerateInputRequestedRegion();
+ virtual void GenerateOutputInformation();
+ virtual void GenerateData();
private:
- ResampleImageWithOptionsFilter(const Self&); //purposely not implemented
- void operator=(const Self&); //purposely not implemented
+ ResampleImageWithOptionsFilter(const Self&); //purposely not implemented
+ void operator=(const Self&); //purposely not implemented
}; // end class
//--------------------------------------------------------------------
+ // Convenient function
+ template<class InputImageType>
+ typename InputImageType::Pointer ResampleImageSpacing(typename InputImageType::Pointer input,
+ typename InputImageType::SpacingType spacing,
+ int interpolationType=0);
+
} // end namespace clitk
//--------------------------------------------------------------------
#include "itkCommand.h"
//--------------------------------------------------------------------
-template <class TInputImage, class TOutputImage>
-clitk::ResampleImageWithOptionsFilter<TInputImage, TOutputImage>::
-ResampleImageWithOptionsFilter():itk::ImageToImageFilter<TInputImage, TOutputImage>()
+template <class InputImageType, class OutputImageType>
+clitk::ResampleImageWithOptionsFilter<InputImageType, OutputImageType>::
+ResampleImageWithOptionsFilter():itk::ImageToImageFilter<InputImageType, OutputImageType>()
{
static const unsigned int dim = InputImageType::ImageDimension;
this->SetNumberOfRequiredInputs(1);
//--------------------------------------------------------------------
-template <class TInputImage, class TOutputImage>
+template <class InputImageType, class OutputImageType>
void
-clitk::ResampleImageWithOptionsFilter<TInputImage, TOutputImage>::
+clitk::ResampleImageWithOptionsFilter<InputImageType, OutputImageType>::
SetInput(const InputImageType * image)
{
// Process object is not const-correct so the const casting is required.
//--------------------------------------------------------------------
-template <class TInputImage, class TOutputImage>
+template <class InputImageType, class OutputImageType>
void
-clitk::ResampleImageWithOptionsFilter<TInputImage, TOutputImage>::
+clitk::ResampleImageWithOptionsFilter<InputImageType, OutputImageType>::
GenerateInputRequestedRegion()
{
// call the superclass's implementation of this method
// get pointers to the input and output
InputImagePointer inputPtr =
- const_cast< TInputImage *>( this->GetInput() );
+ const_cast< InputImageType *>( this->GetInput() );
// Request the entire input image
InputImageRegionType inputRegion;
//--------------------------------------------------------------------
-template <class TInputImage, class TOutputImage>
+template <class InputImageType, class OutputImageType>
void
-clitk::ResampleImageWithOptionsFilter<TInputImage, TOutputImage>::
+clitk::ResampleImageWithOptionsFilter<InputImageType, OutputImageType>::
GenerateOutputInformation()
{
static const unsigned int dim = InputImageType::ImageDimension;
//--------------------------------------------------------------------
-template <class TInputImage, class TOutputImage>
+template <class InputImageType, class OutputImageType>
void
-clitk::ResampleImageWithOptionsFilter<TInputImage, TOutputImage>::
+clitk::ResampleImageWithOptionsFilter<InputImageType, OutputImageType>::
GenerateData()
{
// DD("after Graft");
}
//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template<class InputImageType>
+typename InputImageType::Pointer
+clitk::ResampleImageSpacing(typename InputImageType::Pointer input,
+ typename InputImageType::SpacingType spacing,
+ int interpolationType)
+{
+ typedef clitk::ResampleImageWithOptionsFilter<InputImageType> ResampleFilterType;
+ typename ResampleFilterType::Pointer resampler = ResampleFilterType::New();
+ resampler->SetInput(input);
+ resampler->SetOutputSpacing(spacing);
+ typename ResampleFilterType::InterpolationTypeEnumeration inter=ResampleFilterType::NearestNeighbor;
+ switch(interpolationType) {
+ case 0: inter = ResampleFilterType::NearestNeighbor; break;
+ case 1: inter = ResampleFilterType::Linear; break;
+ case 2: inter = ResampleFilterType::BSpline; break;
+ case 3: inter = ResampleFilterType::B_LUT; break;
+ case 4: inter = ResampleFilterType::WSINC; break;
+ }
+ resampler->SetInterpolationType(inter);
+ resampler->SetGaussianFilteringEnabled(true);
+ resampler->Update();
+ return resampler->GetOutput();
+}
+//--------------------------------------------------------------------