From: dsarrut Date: Wed, 7 Jul 2010 07:00:26 +0000 (+0000) Subject: add resample function X-Git-Tag: v1.2.0~564 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=c6af1ad959db0f78028d4cb11b6eb75f2cadc4ba;p=clitk.git add resample function --- diff --git a/itk/clitkResampleImageWithOptionsFilter.h b/itk/clitkResampleImageWithOptionsFilter.h index d90c724..3fa1871 100644 --- a/itk/clitkResampleImageWithOptionsFilter.h +++ b/itk/clitkResampleImageWithOptionsFilter.h @@ -28,123 +28,126 @@ namespace clitk { /* Image resampling with several interpolations and Gaussian filtering included. */ - //-------------------------------------------------------------------- - - template - class ITK_EXPORT ResampleImageWithOptionsFilter: - public itk::ImageToImageFilter { + //-------------------------------------------------------------------- + template + class ITK_EXPORT ResampleImageWithOptionsFilter: + public itk::ImageToImageFilter { public: - /** Standard class typedefs. */ - typedef ResampleImageWithOptionsFilter Self; - typedef itk::ImageToImageFilter Superclass; - typedef itk::SmartPointer Pointer; - typedef itk::SmartPointer ConstPointer; + /** Standard class typedefs. */ + typedef ResampleImageWithOptionsFilter Self; + typedef itk::ImageToImageFilter Superclass; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer 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 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)); - - /** 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 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)); + + /** 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 + typename InputImageType::Pointer ResampleImageSpacing(typename InputImageType::Pointer input, + typename InputImageType::SpacingType spacing, + int interpolationType=0); + } // end namespace clitk //-------------------------------------------------------------------- diff --git a/itk/clitkResampleImageWithOptionsFilter.txx b/itk/clitkResampleImageWithOptionsFilter.txx index aa09f71..beb85cc 100644 --- a/itk/clitkResampleImageWithOptionsFilter.txx +++ b/itk/clitkResampleImageWithOptionsFilter.txx @@ -35,9 +35,9 @@ #include "itkCommand.h" //-------------------------------------------------------------------- -template -clitk::ResampleImageWithOptionsFilter:: -ResampleImageWithOptionsFilter():itk::ImageToImageFilter() +template +clitk::ResampleImageWithOptionsFilter:: +ResampleImageWithOptionsFilter():itk::ImageToImageFilter() { static const unsigned int dim = InputImageType::ImageDimension; this->SetNumberOfRequiredInputs(1); @@ -60,9 +60,9 @@ ResampleImageWithOptionsFilter():itk::ImageToImageFilter +template void -clitk::ResampleImageWithOptionsFilter:: +clitk::ResampleImageWithOptionsFilter:: SetInput(const InputImageType * image) { // Process object is not const-correct so the const casting is required. @@ -72,9 +72,9 @@ SetInput(const InputImageType * image) //-------------------------------------------------------------------- -template +template void -clitk::ResampleImageWithOptionsFilter:: +clitk::ResampleImageWithOptionsFilter:: GenerateInputRequestedRegion() { // call the superclass's implementation of this method @@ -82,7 +82,7 @@ GenerateInputRequestedRegion() // 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; @@ -93,9 +93,9 @@ GenerateInputRequestedRegion() //-------------------------------------------------------------------- -template +template void -clitk::ResampleImageWithOptionsFilter:: +clitk::ResampleImageWithOptionsFilter:: GenerateOutputInformation() { static const unsigned int dim = InputImageType::ImageDimension; @@ -178,9 +178,9 @@ GenerateOutputInformation() //-------------------------------------------------------------------- -template +template void -clitk::ResampleImageWithOptionsFilter:: +clitk::ResampleImageWithOptionsFilter:: GenerateData() { @@ -303,3 +303,30 @@ GenerateData() // DD("after Graft"); } //-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +typename InputImageType::Pointer +clitk::ResampleImageSpacing(typename InputImageType::Pointer input, + typename InputImageType::SpacingType spacing, + int interpolationType) +{ + typedef clitk::ResampleImageWithOptionsFilter 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(); +} +//--------------------------------------------------------------------