X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=itk%2FclitkResampleImageWithOptionsFilter.txx;h=97f6f418c56bc88c0937079060002285d5184758;hb=7d4e77191e55f668f316ba3ddf0fddb63e59bd25;hp=dd5a82142edbc0d808a46d5ab713d8d96062e7f8;hpb=1e034c70105f0926939acaaa27ddb46e904ae8bf;p=clitk.git diff --git a/itk/clitkResampleImageWithOptionsFilter.txx b/itk/clitkResampleImageWithOptionsFilter.txx index dd5a821..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,18 +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" -namespace clitk -{ - //-------------------------------------------------------------------- -template -ResampleImageWithOptionsFilter:: -ResampleImageWithOptionsFilter():itk::ImageToImageFilter() +template +clitk::ResampleImageWithOptionsFilter:: +ResampleImageWithOptionsFilter():itk::ImageToImageFilter() { static const unsigned int dim = InputImageType::ImageDimension; this->SetNumberOfRequiredInputs(1); @@ -56,15 +54,18 @@ ResampleImageWithOptionsFilter():itk::ImageToImageFilter +template void -ResampleImageWithOptionsFilter:: +clitk::ResampleImageWithOptionsFilter:: SetInput(const InputImageType * image) { // Process object is not const-correct so the const casting is required. @@ -74,9 +75,9 @@ SetInput(const InputImageType * image) //-------------------------------------------------------------------- -template +template void -ResampleImageWithOptionsFilter:: +clitk::ResampleImageWithOptionsFilter:: GenerateInputRequestedRegion() { // call the superclass's implementation of this method @@ -84,7 +85,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; @@ -95,9 +96,9 @@ GenerateInputRequestedRegion() //-------------------------------------------------------------------- -template +template void -ResampleImageWithOptionsFilter:: +clitk::ResampleImageWithOptionsFilter:: GenerateOutputInformation() { static const unsigned int dim = InputImageType::ImageDimension; @@ -123,19 +124,31 @@ GenerateOutputInformation() if (m_OutputIsoSpacing != -1) { // apply isoSpacing for(unsigned int i=0; iGetOutput(0); - OutputImageRegionType region; - region.SetSize(m_OutputSize); - region.SetIndex(input->GetLargestPossibleRegion().GetIndex()); - DD(input->GetLargestPossibleRegion().GetIndex()); - outputImage->SetLargestPossibleRegion(region); + // OutputImageRegionType region; + m_OutputRegion.SetSize(m_OutputSize); + m_OutputRegion.SetIndex(input->GetLargestPossibleRegion().GetIndex()); + outputImage->CopyInformation(input); + outputImage->SetLargestPossibleRegion(m_OutputRegion); outputImage->SetSpacing(m_OutputSpacing); // Init Gaussian sigma if (m_GaussianSigma[0] != -1) { // Gaussian filter set by user m_GaussianFilteringEnabled = true; - } else { + } + else { if (m_GaussianFilteringEnabled) { // Automated sigma when downsample for(unsigned int i=0; i inputSpacing[i]) { // downsample m_GaussianSigma[i] = 0.5*m_OutputSpacing[i];// / inputSpacing[i]); - } else m_GaussianSigma[i] = 0; // will be ignore after + } + else m_GaussianSigma[i] = 0; // will be ignore after } } } @@ -178,9 +193,9 @@ GenerateOutputInformation() //-------------------------------------------------------------------- -template +template void -ResampleImageWithOptionsFilter:: +clitk::ResampleImageWithOptionsFilter:: GenerateData() { @@ -192,9 +207,7 @@ GenerateData() 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) { @@ -205,31 +218,39 @@ GenerateData() std::cout << "Sigma = " << m_GaussianSigma << std::endl; std::cout << "Interpol = "; switch (m_InterpolationType) { - case NearestNeighbor: - std::cout << "NearestNeighbor" << std::endl; - break; - 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 NearestNeighbor: std::cout << "NearestNeighbor" << std::endl; break; + 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); +#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) { @@ -260,9 +281,16 @@ 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 + // TODO : replace by itk::DiscreteGaussianImageFilter for small sigma typedef itk::RecursiveGaussianImageFilter GaussianFilterType; std::vector gaussianFilters; if (m_GaussianFilteringEnabled) { @@ -289,11 +317,33 @@ GenerateData() filter->Update(); // Set output - // DD("before Graft"); this->GraftOutput(filter->GetOutput()); - // DD("after Graft"); } //-------------------------------------------------------------------- -}//end clitk +//-------------------------------------------------------------------- +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(); +} +//--------------------------------------------------------------------