X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=itk%2FclitkResampleImageWithOptionsFilter.txx;h=a3f88beb3db8443f08fa376da1480433f24e4051;hb=39562adceed3b608834959f2ed079b945187bb22;hp=993b7ec85abc8199c6d2822133a6c4fe96fc1202;hpb=25f2ec51914dc5a55443c223bc52ca8c234fe100;p=clitk.git diff --git a/itk/clitkResampleImageWithOptionsFilter.txx b/itk/clitkResampleImageWithOptionsFilter.txx index 993b7ec..a3f88be 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); @@ -54,14 +55,15 @@ 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. @@ -71,9 +73,9 @@ SetInput(const InputImageType * image) //-------------------------------------------------------------------- -template +template void -clitk::ResampleImageWithOptionsFilter:: +clitk::ResampleImageWithOptionsFilter:: GenerateInputRequestedRegion() { // call the superclass's implementation of this method @@ -81,7 +83,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; @@ -92,9 +94,9 @@ GenerateInputRequestedRegion() //-------------------------------------------------------------------- -template +template void -clitk::ResampleImageWithOptionsFilter:: +clitk::ResampleImageWithOptionsFilter:: GenerateOutputInformation() { static const unsigned int dim = InputImageType::ImageDimension; @@ -120,12 +122,20 @@ GenerateOutputInformation() if (m_OutputIsoSpacing != -1) { // apply isoSpacing for(unsigned int i=0; iGetOutput(0); // OutputImageRegionType region; @@ -177,9 +187,9 @@ GenerateOutputInformation() //-------------------------------------------------------------------- -template +template void -clitk::ResampleImageWithOptionsFilter:: +clitk::ResampleImageWithOptionsFilter:: GenerateData() { @@ -187,18 +197,11 @@ GenerateData() 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,6 +216,7 @@ 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; } std::cout << "Threads = " << this->GetNumberOfThreads() << std::endl; std::cout << "LastDimIsTime = " << m_LastDimensionIsTime << std::endl; @@ -257,6 +261,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 @@ -288,7 +298,37 @@ GenerateData() // 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(); +} +//--------------------------------------------------------------------