From: tbaudier Date: Wed, 9 Aug 2017 11:51:42 +0000 (+0200) Subject: Add gaussian filtering options into clitkAffineTransform X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=7a3df37d7df358eeddb6b5d7fd2a529a388f678e;p=clitk.git Add gaussian filtering options into clitkAffineTransform --- diff --git a/tools/clitkAffineTransform.ggo b/tools/clitkAffineTransform.ggo index 8eaedd5..e3205a2 100644 --- a/tools/clitkAffineTransform.ggo +++ b/tools/clitkAffineTransform.ggo @@ -31,3 +31,7 @@ option "interpSF" - "Sampling factor if BLUT" int no default="20" option "interpVF" - "Interpolation: 0=NN, 1=Linear, 2=BSpline, 3=BLUT" int no default="1" option "interpVFOrder" - "Order if BLUT or BSpline (0-5)" int no default="3" option "interpVFSF" - "Sampling factor if BLUT" int no default="20" + +section "Gaussian filtering" +option "gauss" g "Apply gaussian filter before (sigma in mm) (default=0.0)" double no multiple +option "autogauss" - "Apply gaussian filter before with auto sigma when downsampling (default=off)" flag off \ No newline at end of file diff --git a/tools/clitkAffineTransformGenericFilter.txx b/tools/clitkAffineTransformGenericFilter.txx index 15baf2d..bf31033 100644 --- a/tools/clitkAffineTransformGenericFilter.txx +++ b/tools/clitkAffineTransformGenericFilter.txx @@ -22,6 +22,7 @@ #include #include #include +#include #include "clitkElastix.h" namespace clitk @@ -129,6 +130,37 @@ namespace clitk reader->Update(); typename InputImageType::Pointer input= reader->GetOutput(); + //Gaussian pre-filtering + typename itk::Vector gaussianSigma; + gaussianSigma.Fill(0); + bool gaussianFilteringEnabled(false); + bool autoGaussEnabled(false); + if (m_ArgsInfo.autogauss_given) { // Gaussian filter auto + autoGaussEnabled = m_ArgsInfo.autogauss_flag; + } + if (m_ArgsInfo.gauss_given) { // Gaussian filter set by user + gaussianFilteringEnabled = true; + if (m_ArgsInfo.gauss_given == 1) + { + for (unsigned int i=0; i ResampleFilterType; typename ResampleFilterType::Pointer resampler = ResampleFilterType::New(); @@ -213,6 +245,14 @@ namespace clitk likeReader->Update(); resampler->SetOutputParametersFromImage(likeReader->GetOutput()); resampler->SetOutputDirection(likeReader->GetOutput()->GetDirection()); + if (autoGaussEnabled) { // Automated sigma when downsample + for(unsigned int i=0; iGetOutput()->GetSpacing()[i] > input->GetSpacing()[i]) { // downsample + gaussianSigma[i] = 0.5*likeReader->GetOutput()->GetSpacing()[i];// / inputSpacing[i]); + } + else gaussianSigma[i] = 0; // will be ignore after + } + } } else if(m_ArgsInfo.transform_grid_flag) { typename itk::Matrix invMatrix( matrix.GetInverse() ); typename itk::Matrix invRotMatrix( clitk::GetRotationalPartMatrix(invMatrix) ); @@ -229,6 +269,14 @@ namespace clitk outputSpacing = invRotMatrix * input->GetDirection() * input->GetSpacing(); + if (autoGaussEnabled) { // Automated sigma when downsample + for(unsigned int i=0; i input->GetSpacing()[i]) { // downsample + gaussianSigma[i] = 0.5*outputSpacing[i];// / inputSpacing[i]); + } + else gaussianSigma[i] = 0; // will be ignore after + } + } // Origin is influenced by translation but not by input direction typename InputImageType::PointType outputOrigin; @@ -273,6 +321,14 @@ namespace clitk for(unsigned int i=0; i< Dimension; i++) outputSpacing[i]=m_ArgsInfo.spacing_arg[i]; } else outputSpacing=input->GetSpacing(); + if (autoGaussEnabled) { // Automated sigma when downsample + for(unsigned int i=0; i input->GetSpacing()[i]) { // downsample + gaussianSigma[i] = 0.5*outputSpacing[i];// / inputSpacing[i]); + } + else gaussianSigma[i] = 0; // will be ignore after + } + } //Origin typename OutputImageType::PointType outputOrigin; @@ -327,7 +383,28 @@ namespace clitk std::cout << "Setting the output direction to " << resampler->GetOutputDirection() << "..." << std::endl; } - resampler->SetInput( input ); + typedef itk::RecursiveGaussianImageFilter GaussianFilterType; + std::vector gaussianFilters; + if (gaussianFilteringEnabled || autoGaussEnabled) { + for(unsigned int i=0; iSetDirection(i); + gaussianFilters[i]->SetOrder(GaussianFilterType::ZeroOrder); + gaussianFilters[i]->SetNormalizeAcrossScale(false); + gaussianFilters[i]->SetSigma(gaussianSigma[i]); // in millimeter ! + if (gaussianFilters.size() == 1) { // first + gaussianFilters[0]->SetInput(input); + } else { + gaussianFilters[i]->SetInput(gaussianFilters[i-1]->GetOutput()); + } + } + } + if (gaussianFilters.size() > 0) { + resampler->SetInput(gaussianFilters[gaussianFilters.size()-1]->GetOutput()); + } else resampler->SetInput(input); + } else resampler->SetInput(input); + resampler->SetTransform( affineTransform ); resampler->SetInterpolator( genericInterpolator->GetInterpolatorPointer()); resampler->SetDefaultPixelValue( static_cast(m_ArgsInfo.pad_arg) ); @@ -369,6 +446,37 @@ namespace clitk reader->Update(); typename InputImageType::Pointer input= reader->GetOutput(); + //Gaussian pre-filtering + typename itk::Vector gaussianSigma; + gaussianSigma.Fill(0); + bool gaussianFilteringEnabled(false); + bool autoGaussEnabled(false); + if (m_ArgsInfo.autogauss_given) { // Gaussian filter auto + autoGaussEnabled = m_ArgsInfo.autogauss_flag; + } + if (m_ArgsInfo.gauss_given) { // Gaussian filter set by user + gaussianFilteringEnabled = true; + if (m_ArgsInfo.gauss_given == 1) + { + for (unsigned int i=0; i ResampleFilterType; typename ResampleFilterType::Pointer resampler = ResampleFilterType::New(); @@ -449,6 +557,14 @@ namespace clitk resampler->SetOutputSpacing( likeReader->GetOutput()->GetSpacing() ); resampler->SetOutputOrigin( likeReader->GetOutput()->GetOrigin() ); resampler->SetOutputDirection( likeReader->GetOutput()->GetDirection() ); + if (autoGaussEnabled) { // Automated sigma when downsample + for(unsigned int i=0; iGetOutput()->GetSpacing()[i] > input->GetSpacing()[i]) { // downsample + gaussianSigma[i] = 0.5*likeReader->GetOutput()->GetSpacing()[i];// / inputSpacing[i]); + } + else gaussianSigma[i] = 0; // will be ignore after + } + } } else { //Size typename OutputImageType::SizeType outputSize; @@ -464,6 +580,14 @@ namespace clitk for(unsigned int i=0; i< Dimension; i++) outputSpacing[i]=m_ArgsInfo.spacing_arg[i]; } else outputSpacing=input->GetSpacing(); + if (autoGaussEnabled) { // Automated sigma when downsample + for(unsigned int i=0; i input->GetSpacing()[i]) { // downsample + gaussianSigma[i] = 0.5*outputSpacing[i];// / inputSpacing[i]); + } + else gaussianSigma[i] = 0; // will be ignore after + } + } std::cout<<"Setting the spacing to "< GaussianFilterType; + std::vector gaussianFilters; + if (gaussianFilteringEnabled || autoGaussEnabled) { + for(unsigned int i=0; iSetDirection(i); + gaussianFilters[i]->SetOrder(GaussianFilterType::ZeroOrder); + gaussianFilters[i]->SetNormalizeAcrossScale(false); + gaussianFilters[i]->SetSigma(gaussianSigma[i]); // in millimeter ! + if (gaussianFilters.size() == 1) { // first + gaussianFilters[0]->SetInput(input); + } else { + gaussianFilters[i]->SetInput(gaussianFilters[i-1]->GetOutput()); + } + } + } + if (gaussianFilters.size() > 0) { + resampler->SetInput(gaussianFilters[gaussianFilters.size()-1]->GetOutput()); + } else resampler->SetInput(input); + } else resampler->SetInput(input); + resampler->SetInput( input ); resampler->SetTransform( affineTransform ); resampler->SetInterpolator( genericInterpolator->GetInterpolatorPointer());