From: tbaudier Date: Thu, 24 Aug 2017 09:08:26 +0000 (+0200) Subject: Add adaptive tag to clitkAffineTransform for the transition with clitkResampleImage X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=a82fd2eb2ef9e747755b2999a74f30441cfb8359;p=clitk.git Add adaptive tag to clitkAffineTransform for the transition with clitkResampleImage --- diff --git a/tools/clitkAffineTransform.ggo b/tools/clitkAffineTransform.ggo index e3205a2..1d4c43a 100644 --- a/tools/clitkAffineTransform.ggo +++ b/tools/clitkAffineTransform.ggo @@ -23,6 +23,7 @@ option "elastix" e "Read EulerTransform from elastix output file (combine if mul option "rotate" r "Rotation to apply (radians)" double no multiple option "translate" t "Translation to apply (mm)" double no multiple option "pad" - "Edge padding value" double no default="0.0" +option "adaptive" - "Adapt the size, spacing or the origin when one of the previous tag is on (use previous clitkResampleImage)" flag off section "Interpolation" option "interp" - "Interpolation: 0=NN, 1=Linear, 2=BSpline, 3=BLUT" int no default="1" diff --git a/tools/clitkAffineTransformGenericFilter.txx b/tools/clitkAffineTransformGenericFilter.txx index bf31033..a1e0839 100644 --- a/tools/clitkAffineTransformGenericFilter.txx +++ b/tools/clitkAffineTransformGenericFilter.txx @@ -24,6 +24,7 @@ #include #include #include "clitkElastix.h" +#include "clitkResampleImageWithOptionsFilter.h" namespace clitk { @@ -130,6 +131,142 @@ namespace clitk reader->Update(); typename InputImageType::Pointer input= reader->GetOutput(); + //Adaptative size, spacing origin (use previous clitkResampleImage) + if (m_ArgsInfo.adaptive_given) { + // Filter + typedef clitk::ResampleImageWithOptionsFilter ResampleImageFilterType; + typename ResampleImageFilterType::Pointer filter = ResampleImageFilterType::New(); + filter->SetInput(input); + + // Set Verbose + filter->SetVerboseOptions(m_ArgsInfo.verbose_flag); + + // Set size / spacing + static const unsigned int dim = OutputImageType::ImageDimension; + typename OutputImageType::SpacingType spacing; + typename OutputImageType::SizeType size; + typename OutputImageType::PointType origin; + typename OutputImageType::DirectionType direction; + + if (m_ArgsInfo.like_given) { + itk::ImageIOBase::Pointer header = clitk::readImageHeader(m_ArgsInfo.like_arg); + if (header) { + for(unsigned int i=0; iGetSpacing(i); + size[i] = header->GetDimensions(i); + origin[i] = header->GetOrigin(i); + } + for(unsigned int i=0; iGetDirection(i)[j]; + } + } + filter->SetOutputSpacing(spacing); + filter->SetOutputSize(size); + filter->SetOutputOrigin(origin); + filter->SetOutputDirection(direction); + } + else { + std::cerr << "*** Warning : I could not read '" << m_ArgsInfo.like_arg << "' ***" << std::endl; + exit(0); + } + } + else { + if (m_ArgsInfo.spacing_given == 1) { + filter->SetOutputIsoSpacing(m_ArgsInfo.spacing_arg[0]); + } + else if ((m_ArgsInfo.spacing_given != 0) && (m_ArgsInfo.size_given != 0)) { + std::cerr << "Error: use spacing or size, not both." << std::endl; + exit(0); + } + else if (m_ArgsInfo.spacing_given) { + if ((m_ArgsInfo.spacing_given != 0) && (m_ArgsInfo.spacing_given != dim)) { + std::cerr << "Error: spacing should have one or " << dim << " values." << std::endl; + exit(0); + } + for(unsigned int i=0; iSetOutputSpacing(spacing); + } + else if (m_ArgsInfo.size_given) { + if ((m_ArgsInfo.size_given != 0) && (m_ArgsInfo.size_given != dim)) { + std::cerr << "Error: size should have " << dim << " values." << std::endl; + exit(0); + } + for(unsigned int i=0; iSetOutputSize(size); + } + for(unsigned int i=0; iGetOrigin()[i]; + } + for(unsigned int i=0; iGetDirection()[i][j]; + } + } + filter->SetOutputOrigin(origin); + filter->SetOutputDirection(direction); + } + + // Set temporal dimension + //filter->SetLastDimensionIsTime(m_ArgsInfo.time_flag); + + // Set Gauss + filter->SetGaussianFilteringEnabled(m_ArgsInfo.autogauss_flag); + if (m_ArgsInfo.gauss_given != 0) { + typename ResampleImageFilterType::GaussianSigmaType g; + for(unsigned int i=0; iSetGaussianSigma(g); + } + + // Set Interpolation + int interp = m_ArgsInfo.interp_arg; + if (interp == 0) { + filter->SetInterpolationType(ResampleImageFilterType::NearestNeighbor); + } else { + if (interp == 1) { + filter->SetInterpolationType(ResampleImageFilterType::Linear); + } else { + if (interp == 2) { + filter->SetInterpolationType(ResampleImageFilterType::BSpline); + } else { + if (interp == 3) { + filter->SetInterpolationType(ResampleImageFilterType::B_LUT); + } else { + std::cerr << "Error. I do not know interpolation '" << m_ArgsInfo.interp_arg + << "'. Choose among: nn, linear, bspline, blut, windowed sinc" << std::endl; + exit(0); + } + } + } + } + + // Set default pixel value + filter->SetDefaultPixelValue(m_ArgsInfo.pad_arg); + + // Set thread + //if (m_ArgsInfo.thread_given) { + // filter->SetNumberOfThreads(m_ArgsInfo.thread_arg); + //} + + // Go ! + filter->Update(); + typename OutputImageType::Pointer output = filter->GetOutput(); + //this->template SetNextOutput(outputImage); + + // Output + typedef itk::ImageFileWriter WriterType; + typename WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(m_ArgsInfo.output_arg); + writer->SetInput(output); + writer->Update(); + + return; + } + //Gaussian pre-filtering typename itk::Vector gaussianSigma; gaussianSigma.Fill(0);