X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=itk%2FclitkResampleImageWithOptionsFilter.txx;h=7e5eeab4eb78e9d4745d4b9a92fd8f2e34d6430b;hb=9a79f8cf7020e0a7ed5b1b97293bfa13a3a27b58;hp=dd5a82142edbc0d808a46d5ab713d8d96062e7f8;hpb=1e034c70105f0926939acaaa27ddb46e904ae8bf;p=clitk.git diff --git a/itk/clitkResampleImageWithOptionsFilter.txx b/itk/clitkResampleImageWithOptionsFilter.txx index dd5a821..7e5eeab 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); @@ -57,15 +55,16 @@ ResampleImageWithOptionsFilter():itk::ImageToImageFilter +template void -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)); @@ -74,17 +73,17 @@ SetInput(const InputImageType * image) //-------------------------------------------------------------------- -template +template void -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; @@ -95,10 +94,10 @@ GenerateInputRequestedRegion() //-------------------------------------------------------------------- -template +template void -ResampleImageWithOptionsFilter:: -GenerateOutputInformation() +clitk::ResampleImageWithOptionsFilter:: +GenerateOutputInformation() { static const unsigned int dim = InputImageType::ImageDimension; @@ -123,12 +122,16 @@ 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,12 +183,12 @@ GenerateOutputInformation() //-------------------------------------------------------------------- -template -void -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; @@ -192,9 +197,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,18 +208,11 @@ 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; } std::cout << "Threads = " << this->GetNumberOfThreads() << std::endl; std::cout << "LastDimIsTime = " << m_LastDimensionIsTime << std::endl; @@ -229,7 +225,8 @@ GenerateData() filter->SetOutputSpacing(m_OutputSpacing); filter->SetOutputOrigin(input->GetOrigin()); filter->SetDefaultPixelValue(m_DefaultPixelValue); - filter->SetNumberOfThreads(this->GetNumberOfThreads()); + filter->SetNumberOfThreads(this->GetNumberOfThreads()); + filter->SetOutputDirection(input->GetDirection()); // <-- NEEDED if we want to keep orientation (in case of PermutAxes for example) // Select interpolator switch (m_InterpolationType) { @@ -260,9 +257,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) { @@ -290,10 +294,37 @@ GenerateData() // Set output // DD("before Graft"); - this->GraftOutput(filter->GetOutput()); + + //this->GraftOutput(filter->GetOutput()); + this->SetNthOutput(0, 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(); +} +//--------------------------------------------------------------------