X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=itk%2FclitkResampleImageWithOptionsFilter.txx;h=97f6f418c56bc88c0937079060002285d5184758;hb=7d4e77191e55f668f316ba3ddf0fddb63e59bd25;hp=b9969dacb9b1ad1d4a69cae08e1752b5f5d185ef;hpb=77ee327ec2ae14e038106ccebea0f89774733f10;p=clitk.git diff --git a/itk/clitkResampleImageWithOptionsFilter.txx b/itk/clitkResampleImageWithOptionsFilter.txx index b9969da..97f6f41 100644 --- a/itk/clitkResampleImageWithOptionsFilter.txx +++ b/itk/clitkResampleImageWithOptionsFilter.txx @@ -3,7 +3,7 @@ Authors belong to: - University of LYON http://www.universite-lyon.fr/ - - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - Léon Bérard cancer center http://www.centreleonberard.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr This software is distributed WITHOUT ANY WARRANTY; without even @@ -14,10 +14,10 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html - ======================================================================-====*/ + ===========================================================================**/ // clitk -#include "clitkCommon.h" +#include "clitkDD.h" // itk include #include "itkImage.h" @@ -28,15 +28,16 @@ #include "itkResampleImageFilter.h" #include "itkAffineTransform.h" #include "itkNearestNeighborInterpolateImageFunction.h" +#include "itkWindowedSincInterpolateImageFunction.h" #include "itkLinearInterpolateImageFunction.h" #include "itkBSplineInterpolateImageFunction.h" #include "itkBSplineInterpolateImageFunctionWithLUT.h" #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); @@ -53,16 +54,19 @@ ResampleImageWithOptionsFilter():itk::ImageToImageFilter +template void -clitk::ResampleImageWithOptionsFilter:: -SetInput(const InputImageType * image) +clitk::ResampleImageWithOptionsFilter:: +SetInput(const InputImageType * image) { // Process object is not const-correct so the const casting is required. this->SetNthInput(0, const_cast(image)); @@ -71,17 +75,17 @@ SetInput(const InputImageType * image) //-------------------------------------------------------------------- -template +template void -clitk::ResampleImageWithOptionsFilter:: -GenerateInputRequestedRegion() +clitk::ResampleImageWithOptionsFilter:: +GenerateInputRequestedRegion() { // call the superclass's implementation of this method Superclass::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; @@ -92,10 +96,10 @@ GenerateInputRequestedRegion() //-------------------------------------------------------------------- -template +template void -clitk::ResampleImageWithOptionsFilter:: -GenerateOutputInformation() +clitk::ResampleImageWithOptionsFilter:: +GenerateOutputInformation() { static const unsigned int dim = InputImageType::ImageDimension; @@ -120,19 +124,31 @@ GenerateOutputInformation() if (m_OutputIsoSpacing != -1) { // apply isoSpacing for(unsigned int i=0; iGetOutput(0); // OutputImageRegionType region; @@ -177,28 +193,21 @@ GenerateOutputInformation() //-------------------------------------------------------------------- -template -void -clitk::ResampleImageWithOptionsFilter:: -GenerateData() +template +void +clitk::ResampleImageWithOptionsFilter:: +GenerateData() { - + // Get input pointer InputImagePointer input = dynamic_cast(itk::ProcessObject::GetInput(0)); static const unsigned int dim = InputImageType::ImageDimension; - // Set regions and allocate - //this->GetOutput()->SetRegions(m_OutputRegion); - //this->GetOutput()->Allocate(); - // this->GetOutput()->FillBuffer(m_DefaultPixelValue); - // Create main Resample Image Filter typedef itk::ResampleImageFilter FilterType; typename FilterType::Pointer filter = FilterType::New(); filter->GraftOutput(this->GetOutput()); - // this->GetOutput()->Print(std::cout); - // this->GetOutput()->SetBufferedRegion(this->GetOutput()->GetLargestPossibleRegion()); - // this->GetOutput()->Print(std::cout); + this->GetOutput()->SetBufferedRegion(this->GetOutput()->GetLargestPossibleRegion()); // Print options if needed if (m_VerboseOptions) { @@ -213,20 +222,35 @@ GenerateData() case Linear: std::cout << "Linear" << std::endl; break; case BSpline: std::cout << "BSpline " << m_BSplineOrder << std::endl; break; case B_LUT: std::cout << "B-LUT " << m_BSplineOrder << " " << m_BLUTSamplingFactor << std::endl; break; + case WSINC: std::cout << "Windowed Sinc" << std::endl; break; } +#if ITK_VERSION_MAJOR <= 4 std::cout << "Threads = " << this->GetNumberOfThreads() << std::endl; +#else + std::cout << "Threads = " << this->GetNumberOfWorkUnits() << std::endl; +#endif std::cout << "LastDimIsTime = " << m_LastDimensionIsTime << std::endl; } + // Compute origin based on image corner + for(unsigned int i=0; iGetSpacing()[i]; + m_OutputOrigin[i] += 0.5 * m_OutputSpacing[i]; + } + // Instance of the transform object to be passed to the resample // filter. By default, identity transform is applied filter->SetTransform(m_Transform); filter->SetSize(m_OutputSize); filter->SetOutputSpacing(m_OutputSpacing); - filter->SetOutputOrigin(input->GetOrigin()); + filter->SetOutputOrigin(m_OutputOrigin); filter->SetDefaultPixelValue(m_DefaultPixelValue); - filter->SetNumberOfThreads(this->GetNumberOfThreads()); - filter->SetOutputDirection(input->GetDirection()); // <-- NEEDED if we want to keep orientation (in case of PermutAxes for example) +#if ITK_VERSION_MAJOR <= 4 + filter->SetNumberOfThreads(this->GetNumberOfThreads()); +#else + filter->SetNumberOfWorkUnits(this->GetNumberOfWorkUnits()); +#endif + filter->SetOutputDirection(m_OutputDirection); // <-- NEEDED if we want to keep orientation (in case of PermutAxes for example) // Select interpolator switch (m_InterpolationType) { @@ -257,6 +281,12 @@ GenerateData() filter->SetInterpolator(interpolator); break; } + case WSINC: { + typedef itk::WindowedSincInterpolateImageFunction InterpolatorType; + typename InterpolatorType::Pointer interpolator = InterpolatorType::New(); + filter->SetInterpolator(interpolator); + break; + } } // Initial Gaussian blurring if needed @@ -287,11 +317,33 @@ GenerateData() filter->Update(); // Set output - // DD("before Graft"); + this->GraftOutput(filter->GetOutput()); +} +//-------------------------------------------------------------------- - //this->GraftOutput(filter->GetOutput()); - this->SetNthOutput(0, filter->GetOutput()); - // 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(); } //--------------------------------------------------------------------