]> Creatis software - clitk.git/commitdiff
Add adaptive tag to clitkAffineTransform for the transition with clitkResampleImage
authortbaudier <thomas.baudier@creatis.insa-lyon.fr>
Thu, 24 Aug 2017 09:08:26 +0000 (11:08 +0200)
committertbaudier <thomas.baudier@creatis.insa-lyon.fr>
Thu, 24 Aug 2017 09:08:26 +0000 (11:08 +0200)
tools/clitkAffineTransform.ggo
tools/clitkAffineTransformGenericFilter.txx

index e3205a20b3ce131d81c9b87d1907c37766819c38..1d4c43ad85a4370e7d1b9b3a24497f4f150129d5 100644 (file)
@@ -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"
index bf31033d515b9df7ee321e1a1d1bce1fc0ae5829..a1e0839a320aa7fbe6339c36c2ba230b9f20f644 100644 (file)
@@ -24,6 +24,7 @@
 #include <itkCenteredEuler3DTransform.h>
 #include <itkRecursiveGaussianImageFilter.h>
 #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<InputImageType, OutputImageType> 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; i<dim; i++){
+            spacing[i] = header->GetSpacing(i);
+            size[i] = header->GetDimensions(i);
+            origin[i] = header->GetOrigin(i);
+          }
+          for(unsigned int i=0; i<dim; i++) {
+            for(unsigned int j=0;j<dim;j++) {
+                direction(i,j) = header->GetDirection(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; i<dim; i++)
+            spacing[i] = m_ArgsInfo.spacing_arg[i];
+          filter->SetOutputSpacing(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; i<dim; i++)
+            size[i] = m_ArgsInfo.size_arg[i];
+          filter->SetOutputSize(size);
+        }
+        for(unsigned int i=0; i<dim; i++){
+          origin[i] = input->GetOrigin()[i];
+        }
+        for(unsigned int i=0; i<dim; i++) {
+          for(unsigned int j=0;j<dim;j++) {
+              direction(i,j) = input->GetDirection()[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; i<dim; i++) {
+          g[i] = m_ArgsInfo.gauss_arg[i];
+        }
+        filter->SetGaussianSigma(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<OutputImageType>(outputImage);
+
+      // Output
+      typedef itk::ImageFileWriter<OutputImageType> 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<double, Dimension> gaussianSigma;
     gaussianSigma.Fill(0);