]> Creatis software - clitk.git/commitdiff
This is a combination of 3 commits.
authorRomulo Pinho <romulo.pinho@lyon.unicancer.fr>
Thu, 9 Feb 2012 16:55:24 +0000 (17:55 +0100)
committerRomulo Pinho <romulo.pinho@lyon.unicancer.fr>
Fri, 10 Feb 2012 09:44:31 +0000 (10:44 +0100)
new filter to convert from BLUT coeffs to DVF

- refactoring of clitkConvertBSplineDeformableTransformToVFGenericFilter

corrections in last commit

removal of redundant coeffs to dvf tool

- updates in original coeffs to dvf tool
+ new clitk class/filter
- related toos use the new clitk filter

12 files changed:
common/clitkCoeffsToDVF.h [deleted file]
registration/clitkConvertBLUTCoeffsToVFFilter.h [new file with mode: 0644]
registration/clitkConvertBLUTCoeffsToVFFilter.txx [new file with mode: 0644]
registration/clitkConvertBSplineDeformableTransformToVFGenericFilter.cxx
registration/clitkConvertBSplineDeformableTransformToVFGenericFilter.h
scripts/create_midP-2.0.sh
tools/CMakeLists.txt
tools/clitkCoeffsToDVF.cxx [deleted file]
tools/clitkCoeffsToDVF.ggo [deleted file]
tools/clitkComposeVFGenericFilter.txx
tools/clitkInvertVFGenericFilter.txx
tools/clitkWarpImageGenericFilter.txx

diff --git a/common/clitkCoeffsToDVF.h b/common/clitkCoeffsToDVF.h
deleted file mode 100644 (file)
index 603ca70..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-/*=========================================================================
-  Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
-
-  Authors belong to:
-  - University of LYON              http://www.universite-lyon.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
-  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-  PURPOSE.  See the copyright notices for more information.
-
-  It is distributed under dual licence
-
-  - BSD        See included LICENSE.txt file
-  - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-===========================================================================**/
-#ifndef clitkCoeffsToDVF_h
-#define clitkCoeffsToDVF_h
-
-#include "itkImageFileReader.h"
-#include "itkImageIOBase.h"
-
-#include "clitkBSplineDeformableTransform.h"
-#include "clitkResampleBSplineDeformableTransformImageFilter.h"
-#if ITK_VERSION_MAJOR >= 4
-#include "itkTransformToDisplacementFieldSource.h"
-#else
-#include "itkTransformToDeformationFieldSource.h"
-#endif
-#include "itkBSplineDeformableTransform.h"
-
-namespace clitk
-{
-  //-------------------------------------------------------------------
-  // Initialize transform from coefficient images
-  //-------------------------------------------------------------------
-  template <class TransformType>
-  void 
-  SetInitialTransformParameters(typename TransformType::Pointer transform, const typename TransformType::CoefficientImageType::Pointer coefficientImage, typename TransformType::CoefficientImageType::SpacingType outputSpacing) 
-  {
-    unsigned int dim = TransformType::CoefficientImageType::ImageDimension;
-    transform->SetSplineOrder(3);
-    transform->SetGridRegion( coefficientImage->GetLargestPossibleRegion() );
-    transform->SetGridOrigin( coefficientImage->GetOrigin() );
-    transform->SetGridSpacing( coefficientImage->GetSpacing() );
-    transform->SetGridDirection( coefficientImage->GetDirection() );
-    typename TransformType::RegionType::SizeType samplingFactors;
-    for (unsigned int i=0; i< dim; i++) {
-        samplingFactors[i]= (int) ( coefficientImage->GetSpacing()[i]/ outputSpacing[i]);
-    }
-    transform->SetLUTSamplingFactors(samplingFactors);
-    
-    typedef typename TransformType::ParametersType     ParametersType;
-    const unsigned int numberOfParameters = transform->GetNumberOfParameters();
-    ParametersType params(numberOfParameters);
-    params.Fill( 0.0 );
-
-    typedef itk::ImageRegionConstIterator<typename TransformType::CoefficientImageType> Iterator;
-    Iterator it (coefficientImage, coefficientImage->GetLargestPossibleRegion() );
-    it.GoToBegin();
-    unsigned int i = 0;
-    while (! it.IsAtEnd()) {
-        for (unsigned int j = 0; j < dim; j++)
-            params[i+j]=it.Get()[j];
-
-        ++it;
-        i += dim;
-    }
-
-    transform->SetParameters(params);
-    transform->SetBulkTransform(NULL);
-  }
-
-  //-------------------------------------------------------------------
-  // Convert Coefficient image to DVF
-  //-------------------------------------------------------------------
-  template<class DisplacementFieldType>
-  typename DisplacementFieldType::Pointer
-  BLUTCoeffsToDVF(std::string fileName, std::string likeFileName, bool verbose = false)
-  {
-    const unsigned int dim = DisplacementFieldType::ImageDimension;
-    typedef clitk::BSplineDeformableTransform<double, DisplacementFieldType::ImageDimension, DisplacementFieldType::ImageDimension> TransformType;
-    typedef typename TransformType::CoefficientImageType CoefficientImageType;
-
-    typedef itk::ImageFileReader<CoefficientImageType> CoeffReaderType;
-    typename CoeffReaderType::Pointer reader = CoeffReaderType::New();
-    reader->SetFileName(fileName);
-    reader->Update();
-
-  #if ITK_VERSION_MAJOR >= 4
-        typedef itk::TransformToDisplacementFieldSource<DisplacementFieldType, double> ConvertorType;
-  #else
-        typedef itk::TransformToDeformationFieldSource<DisplacementFieldType, double> ConvertorType;
-  #endif
-
-    typedef itk::ImageIOBase ImageIOType;
-    typename ImageIOType::Pointer imageIO = itk::ImageIOFactory::CreateImageIO(likeFileName.c_str(), itk::ImageIOFactory::ReadMode);
-    imageIO->SetFileName(likeFileName);
-    imageIO->ReadImageInformation();
-
-    typename ConvertorType::Pointer convertor= ConvertorType::New();
-    typename ConvertorType::SizeType output_size;
-    typename ConvertorType::SpacingType output_spacing;
-    typename ConvertorType::OriginType output_origin;
-    typename ConvertorType::DirectionType output_direction;
-    for (unsigned int i = 0; i < dim; i++) {
-      output_size[i] = imageIO->GetDimensions(i);
-      output_spacing[i] = imageIO->GetSpacing(i);
-      output_origin[i] = imageIO->GetOrigin(i);
-      for (unsigned int j = 0; j < DisplacementFieldType::ImageDimension; j++)
-        output_direction[i][j] = imageIO->GetDirection(i)[j];
-    }
-
-    typename CoefficientImageType::Pointer coeffs = reader->GetOutput();
-    typename TransformType::Pointer transform = TransformType::New();
-    SetInitialTransformParameters<TransformType>(transform, coeffs, output_spacing);
-
-    if (verbose) {
-      std::cout << "Interpolating coefficients with grid:" << std::endl;
-      std::cout << output_size << output_spacing << std::endl;
-    }
-    
-    convertor->SetNumberOfThreads(1);
-    convertor->SetTransform(transform);
-    convertor->SetOutputOrigin(output_origin);
-    convertor->SetOutputSpacing(output_spacing);
-    convertor->SetOutputSize(output_size);
-    convertor->SetOutputDirection(output_direction);
-    convertor->Update();
-
-    return convertor->GetOutput();
-  }
-}
-
-#endif
diff --git a/registration/clitkConvertBLUTCoeffsToVFFilter.h b/registration/clitkConvertBLUTCoeffsToVFFilter.h
new file mode 100644 (file)
index 0000000..3cd1e67
--- /dev/null
@@ -0,0 +1,93 @@
+
+#ifndef clitkConvertBLUTCoeffsToVFFilter_h
+#define clitkConvertBLUTCoeffsToVFFilter_h
+
+#include "clitkIO.h"
+#include "clitkCommon.h"
+#include "clitkImageCommon.h"
+#include "clitkBSplineDeformableTransform.h"
+#include "itkBSplineDeformableTransform.h"
+#if ITK_VERSION_MAJOR >= 4
+#include "itkTransformToDisplacementFieldSource.h"
+#else
+#include "itkTransformToDeformationFieldSource.h"
+#endif
+
+namespace clitk 
+{
+  template <class TDVFType>
+  class ConvertBLUTCoeffsToVFFilter : 
+    public itk::ImageSource<TDVFType>
+  {
+  public:
+
+    /** Standard class typedefs. */
+    typedef ConvertBLUTCoeffsToVFFilter       Self;
+    typedef itk::ImageSource<TDVFType>         Superclass;
+    typedef itk::SmartPointer<Self>                      Pointer;
+    typedef itk::SmartPointer<const Self>                ConstPointer;
+    
+     // ImageTypes
+    typedef itk::ImageIOBase LikeImageType;
+    typedef typename LikeImageType::Pointer LikeImagePointer;
+
+    typedef TDVFType  OutputImageType;
+    typedef typename OutputImageType::Pointer       OutputImagePointer;
+    typedef typename OutputImageType::ConstPointer  OutputImageConstPointer;
+    typedef typename OutputImageType::RegionType    OutputImageRegionType;
+    typedef typename OutputImageType::SizeType    OutputImageSizeType;
+    typedef typename OutputImageType::PointType    OutputImagePointType;
+    typedef typename OutputImageType::SpacingType    OutputImageSpacingType;
+
+    typedef clitk::BSplineDeformableTransform<double, TDVFType::ImageDimension, TDVFType::ImageDimension> BLUTTransformType;
+    typedef typename BLUTTransformType::CoefficientImageType BLUTCoefficientImageType;
+    typedef itk::BSplineDeformableTransform<double, TDVFType::ImageDimension, TDVFType::ImageDimension> ITKTransformType;
+
+    typedef itk::Transform< double, TDVFType::ImageDimension, TDVFType::ImageDimension> GenericTransformType;
+    
+#if ITK_VERSION_MAJOR >= 4
+    typedef itk::TransformToDisplacementFieldSource<OutputImageType, double> ConvertorType;
+#else
+    typedef itk::TransformToDeformationFieldSource<OutputImageType, double> ConvertorType;
+#endif
+
+    itkNewMacro(Self);
+    
+    itkSetMacro(Verbose, bool);
+    itkSetMacro(InputFileName, std::string);
+    itkSetMacro(LikeFileName, std::string);
+    itkSetMacro(OutputOrigin, OutputImagePointType);
+    itkSetMacro(OutputSpacing, OutputImageSpacingType);
+    itkSetMacro(OutputSize, OutputImageSizeType);
+    itkSetMacro(TransformType, unsigned int);
+    itkSetMacro(MaskFileName, std::string);
+    itkSetMacro(BLUTSplineOrders, typename BLUTCoefficientImageType::SizeType);
+    
+    /** DeformationFieldImageFilter produces a vector image. */
+    virtual void GenerateOutputInformation( void );
+
+  private:
+    
+    ConvertBLUTCoeffsToVFFilter();
+    ~ConvertBLUTCoeffsToVFFilter() {};
+    
+    virtual void GenerateData();
+
+    bool m_Verbose;
+    unsigned int m_TransformType;
+    typename BLUTTransformType::Pointer m_BLUTTransform;
+    typename ITKTransformType::Pointer m_ITKTransform;
+    typename GenericTransformType::Pointer m_GenericTransform;
+    
+    std::string m_InputFileName, m_LikeFileName, m_MaskFileName;
+    OutputImageSizeType m_OutputSize;
+    OutputImageSpacingType m_OutputSpacing;
+    OutputImagePointType m_OutputOrigin;
+    typename BLUTCoefficientImageType::SizeType m_BLUTSplineOrders;
+    typename ConvertorType::Pointer m_Filter;
+  };
+}
+
+#include "clitkConvertBLUTCoeffsToVFFilter.txx"
+
+#endif // clitkConvertBLUTCoeffsToVFFilter_h
\ No newline at end of file
diff --git a/registration/clitkConvertBLUTCoeffsToVFFilter.txx b/registration/clitkConvertBLUTCoeffsToVFFilter.txx
new file mode 100644 (file)
index 0000000..32464d7
--- /dev/null
@@ -0,0 +1,176 @@
+
+#include "clitkConvertBLUTCoeffsToVFFilter.h"
+#include "clitkBSplineDeformableTransform.h"
+#include "clitkTransformToDeformationFieldSource.h"
+#include "clitkShapedBLUTSpatioTemporalDeformableTransform.h"
+#include "itkImageMaskSpatialObject.h"
+
+#include "clitkConvertBSplineDeformableTransformToVFGenericFilter.h"
+#include "clitkVectorImageToImageFilter.h"
+#if ITK_VERSION_MAJOR >= 4
+#include "itkTransformToDisplacementFieldSource.h"
+#else
+#include "itkTransformToDeformationFieldSource.h"
+#endif
+#include "itkBSplineDeformableTransform.h"
+
+namespace clitk 
+{
+  template <class TDVFType>
+  ConvertBLUTCoeffsToVFFilter<TDVFType>::ConvertBLUTCoeffsToVFFilter()
+  {
+    m_Verbose = false;
+    m_TransformType = 0;
+    m_OutputOrigin.Fill(0);
+    m_OutputSpacing.Fill(1);
+    m_OutputSize.Fill(1);
+    m_BLUTSplineOrders.Fill(3);
+
+    m_Filter = ConvertorType::New();
+    m_BLUTTransform = BLUTTransformType::New();
+    m_ITKTransform = ITKTransformType::New();
+  }
+
+  template <class TDVFType>
+  void ConvertBLUTCoeffsToVFFilter<TDVFType>::GenerateOutputInformation()
+  {
+    if (m_Verbose)
+      std::cout << "ConvertBLUTCoeffsToVFFilter<TDVFType>::GenerateOutputInformation()" << std::endl;
+
+    Superclass::GenerateOutputInformation();
+    OutputImagePointer output = this->GetOutput();
+    if (!m_LikeFileName.empty())
+    {
+        typename LikeImageType::Pointer imageIO = itk::ImageIOFactory::CreateImageIO(m_LikeFileName.c_str(), itk::ImageIOFactory::ReadMode);
+        imageIO->SetFileName(m_LikeFileName.c_str());
+        imageIO->ReadImageInformation();
+
+        typename ConvertorType::SizeType output_size;
+        typename ConvertorType::SpacingType output_spacing;
+        typename ConvertorType::OriginType output_origin;
+        typename ConvertorType::DirectionType output_direction;
+        for (unsigned int i = 0; i < OutputImageType::ImageDimension; i++) {
+          output_size[i] = imageIO->GetDimensions(i);
+          output_spacing[i] = imageIO->GetSpacing(i);
+          output_origin[i] = imageIO->GetOrigin(i);
+          //for (unsigned int j = 0; j < Dimension; j++)
+          //  output_direction[i][j] = imageIO->GetDirection(i)[j];
+        }
+        
+        if (m_Verbose)
+          std::cout << output_origin << output_size << output_spacing << std::endl;
+
+        output->SetOrigin(output_origin);
+        output->SetSpacing(output_spacing);
+        //output->SetDirection(output_direction);
+        OutputImageRegionType output_region;
+        output_region.SetSize(output_size);
+        output->SetRegions(output_region);
+    }
+    else
+    {
+        if (m_Verbose)
+          std::cout << m_OutputOrigin << m_OutputSize << m_OutputSpacing << std::endl;
+
+        output->SetOrigin(m_OutputOrigin);
+        output->SetSpacing(m_OutputSpacing);
+        OutputImageRegionType output_region;
+        output_region.SetSize(m_OutputSize);
+        output->SetRegions(output_region);
+    }
+
+  }
+
+  template <class TDVFType>
+  void ConvertBLUTCoeffsToVFFilter<TDVFType>::GenerateData()
+  {
+    // Read the input
+    typedef itk::ImageFileReader<BLUTCoefficientImageType> InputReaderType;
+    typename InputReaderType::Pointer reader = InputReaderType::New();
+    reader->SetFileName(m_InputFileName.c_str());
+    reader->Update();
+    typename BLUTCoefficientImageType::Pointer input = reader->GetOutput();
+    OutputImagePointer output = this->GetOutput();
+
+    if (m_TransformType != 0 ) { // using BLUT
+      // Spline orders:  Default is cubic splines
+        if (m_Verbose) {
+          std::cout << "Using clitk::BLUT." << std::endl;
+          std::cout << "Setting spline orders and sampling factors." << std::endl;
+        }
+
+      m_BLUTTransform->SetSplineOrders(m_BLUTSplineOrders);
+
+      typename BLUTCoefficientImageType::SizeType samplingFactors;
+      for (unsigned int i=0; i< OutputImageType::ImageDimension; i++)
+      {
+          samplingFactors[i]= (int) ( input->GetSpacing()[i]/ output->GetSpacing()[i]);
+          if (m_Verbose) std::cout<<"Setting sampling factor "<<i<<" to "<<samplingFactors[i]<<"..."<<std::endl;
+      }
+      m_BLUTTransform->SetLUTSamplingFactors(samplingFactors);
+      m_BLUTTransform->SetCoefficientImage(input);
+
+      // Mask
+      typedef itk::ImageMaskSpatialObject<BLUTCoefficientImageType::ImageDimension >   MaskType;
+      typename MaskType::Pointer  spatialObjectMask=NULL;
+      if (!m_MaskFileName.empty())
+      {
+          typedef itk::Image< unsigned char, BLUTCoefficientImageType::ImageDimension >   ImageMaskType;
+          typedef itk::ImageFileReader< ImageMaskType >    MaskReaderType;
+          typename MaskReaderType::Pointer  maskReader = MaskReaderType::New();
+          maskReader->SetFileName(m_MaskFileName.c_str());
+
+          try
+          {
+              maskReader->Update();
+          }
+          catch ( itk::ExceptionObject & err )
+          {
+              std::cerr << "ExceptionObject caught while reading mask !" << std::endl;
+              std::cerr << err << std::endl;
+              return;
+          }
+          if (m_Verbose)std::cout <<"Mask was read..." <<std::endl;
+
+          // Set the image to the spatialObject
+          spatialObjectMask = MaskType::New();
+          spatialObjectMask->SetImage( maskReader->GetOutput() );
+          m_BLUTTransform->SetMask(spatialObjectMask);
+      }
+
+      m_GenericTransform = m_BLUTTransform;
+    }
+    else { // using ITK transform
+      if (m_Verbose) {
+        std::cout << "Using itk::BSpline" << std::endl;
+        std::cout << "Extracting components from input coefficient image and creating one coefficient image per-component" << std::endl;
+      }
+        
+      typedef clitk::VectorImageToImageFilter<BLUTCoefficientImageType, typename ITKTransformType::ImageType> FilterType;
+      typename FilterType::Pointer component_filter[BLUTCoefficientImageType::ImageDimension];
+
+      typename ITKTransformType::ImagePointer coefficient_images[BLUTCoefficientImageType::ImageDimension];
+      for (unsigned int i=0; i < BLUTCoefficientImageType::ImageDimension; i++) {
+          component_filter[i] = FilterType::New();
+          component_filter[i]->SetInput(input);
+          component_filter[i]->SetComponentIndex(i);
+          component_filter[i]->Update();
+          coefficient_images[i] = component_filter[i]->GetOutput();
+      }
+      m_ITKTransform->SetCoefficientImage(coefficient_images);
+
+      m_GenericTransform = m_ITKTransform;
+    }
+
+    m_Filter->SetOutputOrigin(output->GetOrigin());
+    m_Filter->SetOutputSpacing(output->GetSpacing());
+    m_Filter->SetOutputSize(output->GetLargestPossibleRegion().GetSize());
+    m_Filter->SetTransform(m_GenericTransform);
+
+    m_Filter->Update();
+
+    SetNthOutput(0, m_Filter->GetOutput());
+  }
+
+
+}
\ No newline at end of file
index 98e5f75668ec04844d9bc51532442c1124740be5..d0e1fa73bf029c1bcc16565a6dfd91f294509e81 100644 (file)
  ===================================================*/
 
 // clitk include
-#include "clitkIO.h"
-#include "clitkCommon.h"
-#include "clitkImageCommon.h"
-#include "clitkConvertBSplineDeformableTransformToVF_ggo.h"
 #include "clitkBSplineDeformableTransform.h"
 #include "clitkTransformToDeformationFieldSource.h"
 #include "clitkShapedBLUTSpatioTemporalDeformableTransform.h"
-#include "itkImageMaskSpatialObject.h"
-
+#include "clitkConvertBLUTCoeffsToVFFilter.h"
 #include "clitkConvertBSplineDeformableTransformToVFGenericFilter.h"
-#include "clitkVectorImageToImageFilter.h"
-#if ITK_VERSION_MAJOR >= 4
-#include "itkTransformToDisplacementFieldSource.h"
-#else
-#include "itkTransformToDeformationFieldSource.h"
-#endif
-#include "itkBSplineDeformableTransform.h"
 
 
 namespace clitk
@@ -86,201 +74,45 @@ namespace clitk
     typedef itk::Image<InputPixelType, Dimension> InputImageType;
     typedef itk::Image<OutputPixelType, Dimension> OutputImageType;
 
-    // Read the input
-    typedef itk::ImageFileReader<InputImageType> InputReaderType;
-    InputReaderType::Pointer reader = InputReaderType::New();
-    reader->SetFileName( m_InputFileName);
-    reader->Update();
-    InputImageType::Pointer input= reader->GetOutput();
-
+    typedef ConvertBLUTCoeffsToVFFilter<OutputImageType> FilterType;
+    typename FilterType::Pointer filter = FilterType::New();
+    filter->SetInputFileName(m_InputFileName);
+    filter->SetTransformType(m_ArgsInfo.type_arg);
+    filter->SetVerbose(m_ArgsInfo.verbose_flag);
 
-    // -----------------------------------------------
-    // Filter
-    // -----------------------------------------------
-#if ITK_VERSION_MAJOR >= 4
-    typedef itk::TransformToDisplacementFieldSource<OutputImageType, double> ConvertorType;
-#else
-    typedef itk::TransformToDeformationFieldSource<OutputImageType, double> ConvertorType;
-#endif
-    ConvertorType::Pointer filter= ConvertorType::New();
-
-    //Output image info
-    if (m_ArgsInfo.like_given)
-    {
-/*        typedef itk::ImageFileReader<OutputImageType> ReaderType;
-        ReaderType::Pointer reader2=ReaderType::New();
-        reader2->SetFileName(m_ArgsInfo.like_arg);
-        reader2->Update();
-
-        OutputImageType::Pointer image=reader2->GetOutput();
-        filter->SetOutputParametersFromImage(image);*/
-
-        typedef itk::ImageIOBase ImageIOType;
-        typename ImageIOType::Pointer imageIO = itk::ImageIOFactory::CreateImageIO(m_ArgsInfo.like_arg, itk::ImageIOFactory::ReadMode);
-        imageIO->SetFileName(m_ArgsInfo.like_arg);
-        imageIO->ReadImageInformation();
-
-        typename ConvertorType::SizeType output_size;
-        typename ConvertorType::SpacingType output_spacing;
-        typename ConvertorType::OriginType output_origin;
-        typename ConvertorType::DirectionType output_direction;
-        for (unsigned int i = 0; i < Dimension; i++) {
-          output_size[i] = imageIO->GetDimensions(i);
-          output_spacing[i] = imageIO->GetSpacing(i);
-          output_origin[i] = imageIO->GetOrigin(i);
-          for (unsigned int j = 0; j < Dimension; j++)
-            output_direction[i][j] = imageIO->GetDirection(i)[j];
-        }
-        
-        filter->SetOutputOrigin(output_origin);
-        filter->SetOutputSpacing(output_spacing);
-        filter->SetOutputSize(output_size);
-        filter->SetOutputDirection(output_direction);
-    }
-    else
-    {
-        unsigned int i=0;
-        if (m_ArgsInfo.origin_given)
-        {
-            OutputImageType::PointType origin;
-            for (i=0;i<Dimension;i++)
-                origin[i]=m_ArgsInfo.origin_arg[i];
-            filter->SetOutputOrigin(origin);
-        }
-        if (m_ArgsInfo.spacing_given)
-        {
-            OutputImageType::SpacingType spacing;
-            for (i=0;i<Dimension;i++)
-                spacing[i]=m_ArgsInfo.spacing_arg[i];
-            filter->SetOutputSpacing(spacing);
-        }
-        if (m_ArgsInfo.spacing_given)
-        {
-            OutputImageType::SizeType size;
-            for (i=0;i<Dimension;i++)
-                size[i]=m_ArgsInfo.size_arg[i];
-            filter->SetOutputSize(size);
-        }
+    if (m_ArgsInfo.like_given) {
+      filter->SetLikeFileName(m_ArgsInfo.like_arg);
     }
-
-    if (m_Verbose)
-    {
-        std::cout<< "Setting output origin to "<<filter->GetOutputOrigin()<<"..."<<std::endl;
-        std::cout<< "Setting output spacing to "<<filter->GetOutputSpacing()<<"..."<<std::endl;
-        std::cout<< "Setting output size to "<<filter->GetOutputSize()<<"..."<<std::endl;
+    else {
+      typename FilterType::OutputImagePointType origin;
+      typename FilterType::OutputImageSpacingType spacing;
+      typename FilterType::OutputImageSizeType size;
+      for (unsigned int i = 0; i < Dimension; i++) {
+        origin[i] = m_ArgsInfo.origin_arg[i];
+        spacing[i] = m_ArgsInfo.spacing_arg[i];
+        size[i] = m_ArgsInfo.size_arg[i];
+      }
+      filter->SetOutputOrigin(origin);
+      filter->SetOutputSpacing(spacing);
+      filter->SetOutputSize(size);
     }
-
-
-    // -----------------------------------------------
-    // Transform
-    // -----------------------------------------------
-    typedef clitk::BSplineDeformableTransform< double, Dimension, Dimension> BLUTTransformType;
-    BLUTTransformType::Pointer blut_transform=BLUTTransformType::New();
-
-    typedef itk::BSplineDeformableTransform< double, Dimension, Dimension> ITKTransformType;
-    ITKTransformType::Pointer itk_transform=ITKTransformType::New();
     
-    typedef itk::Transform< double, Dimension, Dimension> GenericTransformType;
-    typename GenericTransformType::Pointer transform;
-    
-    // Mask
-    typedef itk::ImageMaskSpatialObject<  Dimension >   MaskType;
-    MaskType::Pointer  spatialObjectMask=NULL;
-    if (m_ArgsInfo.mask_given)
-    {
-        typedef itk::Image< unsigned char, Dimension >   ImageMaskType;
-        typedef itk::ImageFileReader< ImageMaskType >    MaskReaderType;
-        MaskReaderType::Pointer  maskReader = MaskReaderType::New();
-        maskReader->SetFileName(m_ArgsInfo.mask_arg);
-
-        try
-        {
-            maskReader->Update();
-        }
-        catch ( itk::ExceptionObject & err )
-        {
-            std::cerr << "ExceptionObject caught while reading mask !" << std::endl;
-            std::cerr << err << std::endl;
-            return;
-        }
-        if (m_Verbose)std::cout <<"Mask was read..." <<std::endl;
-
-        // Set the image to the spatialObject
-        spatialObjectMask = MaskType::New();
-        spatialObjectMask->SetImage( maskReader->GetOutput() );
-        blut_transform->SetMask(spatialObjectMask);
-    }
-
-    if (m_ArgsInfo.type_arg != 0 ) { // using BLUT
-      // Spline orders:  Default is cubic splines
-        if (m_Verbose) {
-          std::cout << "Using clitk::BLUT." << std::endl;
-          std::cout << "Setting spline orders and sampling factors." << std::endl;
-        }
-      InputImageType::RegionType::SizeType splineOrders ;
-      splineOrders.Fill(3);
-      if (m_ArgsInfo.order_given)
-          for (unsigned int i=0; i<Dimension;i++)
-              splineOrders[i]=m_ArgsInfo.order_arg[i];
-      if (m_Verbose) std::cout<<"Setting the spline orders  to "<<splineOrders<<"..."<<std::endl;
-
-      // Samplingfactors
-      InputImageType::SizeType samplingFactors;
-      for (unsigned int i=0; i< Dimension; i++)
-      {
-          samplingFactors[i]= (int) ( input->GetSpacing()[i]/ filter->GetOutputSpacing()[i]);
-          if (m_Verbose) std::cout<<"Setting sampling factor "<<i<<" to "<<samplingFactors[i]<<"..."<<std::endl;
+    if (m_ArgsInfo.order_given) {
+      typename FilterType::OutputImageSizeType order;
+      for (unsigned int i = 0; i < Dimension; i++) {
+        order[i] = m_ArgsInfo.order_arg[i];
       }
-      blut_transform->SetSplineOrders(splineOrders);
-      blut_transform->SetLUTSamplingFactors(samplingFactors);
-      blut_transform->SetCoefficientImage(input);
-
-      transform = blut_transform;
-    }
-    else { // using ITK transform
-        if (m_Verbose) {
-          std::cout << "Using itk::BSpline" << std::endl;
-          std::cout << "Extracting components from input coefficient image and creating one coefficient image per-component" << std::endl;
-        }
-          
-        typedef  double PixelType;
-        typedef itk::Vector<PixelType, Dimension> CoefficientType;
-        typedef itk::Image<CoefficientType, Dimension> CoefficientImageType;
-        typedef clitk::VectorImageToImageFilter<CoefficientImageType, typename ITKTransformType::ImageType> FilterType;
-        typename FilterType::Pointer component_filter[Dimension];
-
-        typename ITKTransformType::ImagePointer coefficient_images[Dimension];
-        for (unsigned int i=0; i < Dimension; i++) {
-            component_filter[i] = FilterType::New();
-            component_filter[i]->SetInput(input);
-            component_filter[i]->SetComponentIndex(i);
-            component_filter[i]->Update();
-            coefficient_images[i] = component_filter[i]->GetOutput();
-        }
-        itk_transform->SetCoefficientImage(coefficient_images);
 
-        transform = itk_transform;
-    }
-   
-    filter->SetTransform(transform);
-
-
-    // -----------------------------------------------
-    // Update
-    // -----------------------------------------------
-    if (m_Verbose)std::cout<< "Converting the BSpline transform..."<<std::endl;
-    try
-    {
-        filter->Update();
-    }
-    catch (itk::ExceptionObject)
-    {
-        std::cerr<<"Error: Exception thrown during execution convertion filter!"<<std::endl;
+      filter->SetBLUTSplineOrders(order);
     }
-
+    
+    if (m_ArgsInfo.mask_given)
+      filter->SetMaskFileName(m_ArgsInfo.mask_arg);
+    
+    filter->Update();
+    
     OutputImageType::Pointer output=filter->GetOutput();
 
-
     // -----------------------------------------------
     // Output
     // -----------------------------------------------
index f65802d39fbcdc74aa760de4172baae05d2a9ae6..8447a08996a71c5afa3cc9d7eccc61dce09e7104 100644 (file)
@@ -30,7 +30,7 @@
 
 // clitk include
 #include "clitkCommon.h"
-// #include "clitkConvertBSplineDeformableTransformToVF_ggo.h"
+#include "clitkConvertBSplineDeformableTransformToVF_ggo.h"
 
 //itk include
 #include "itkLightObject.h"
index c38555a6196029396f79c1486d8bf4e1c347eb05..3b943d38657eeef452294836b7cfbefa007093cd 100755 (executable)
@@ -78,8 +78,8 @@ registration()
 
       # registration
       if [ "$method" == "blutdir" ]; then
-        registration_blutdir $reference_in $target_in $mask_ref_in $mask_targ_in $vf_in $result_in $params $log_in $coeff_in $init_coeff_in
-        registration_blutdir $reference_out $target_out $mask_ref_out $mask_targ_out $vf_out $result_out $params $log_out $coeff_out $init_coeff_out
+        registration_blutdir $reference_in $target_in $mask_ref_in $mask_targ_in $vf_in $result_in $params $log_in $coeff_in 
+        registration_blutdir $reference_out $target_out $mask_ref_out $mask_targ_out $vf_out $result_out $params $log_out $coeff_out 
       elif [ "$method" == "elastix" ]; then
         registration_elastix $reference_in $target_in $mask_ref_in $mask_targ_in $vf_in $result_in $params $log_in
         registration_elastix $reference_out $target_out $mask_ref_out $mask_targ_out $vf_out $result_out $params $log_out
@@ -131,6 +131,10 @@ registration()
   create_mhd_4D_pattern.sh $vf_dir/vf_inside_${ref_phase_nb}_
   create_mhd_4D_pattern.sh $vf_dir/vf_outside_${ref_phase_nb}_
 
+  # create 4D coeffs
+  create_mhd_4D_pattern.sh $vf_dir/coeff_inside_${ref_phase_nb}_ _0
+  create_mhd_4D_pattern.sh $vf_dir/coeff_outside_${ref_phase_nb}_ _0
+
   # create 4D result image
   create_mhd_4D_pattern.sh $output_dir/result_inside_${ref_phase_nb}_
   create_mhd_4D_pattern.sh $output_dir/result_outside_${ref_phase_nb}_
@@ -237,16 +241,22 @@ midp_in_out()
   echo "Calculating midp_$phase_nb.mhd..."
   vf_midp_in=$midp_dir/vf_inside_midp_$phase_nb.mhd
   vf_midp_out=$midp_dir/vf_outside_midp_$phase_nb.mhd
+  coeff_midp_in=$midp_dir/coeff_inside_midp_$phase_nb.mhd
+  coeff_midp_out=$midp_dir/coeff_outside_midp_$phase_nb.mhd
   # average the vf's from reference phase to phase
-  clitkAverageTemporalDimension -i $vf_dir/vf_inside_${ref_phase_nb}_4D.mhd -o $vf_midp_in
+  # clitkAverageTemporalDimension -i $vf_dir/vf_inside_${ref_phase_nb}_4D.mhd -o $vf_midp_in
+  clitkAverageTemporalDimension -i $vf_dir/coeff_inside_${ref_phase_nb}_4D_0.mhd -o $coeff_midp_in
   abort_on_error midp $? clean_up_midp
-  clitkAverageTemporalDimension -i $vf_dir/vf_outside_${ref_phase_nb}_4D.mhd -o $vf_midp_out
+  # clitkAverageTemporalDimension -i $vf_dir/vf_outside_${ref_phase_nb}_4D.mhd -o $vf_midp_out
+  clitkAverageTemporalDimension -i $vf_dir/coeff_outside_${ref_phase_nb}_4D_0.mhd -o $coeff_midp_out
   abort_on_error midp $? clean_up_midp
 
-  # invert the vf (why?)
-  clitkInvertVF -i $vf_midp_in -o $vf_midp_in
+  # invert the vf 
+  # clitkInvertVF -i $vf_midp_in -o $vf_midp_in
+  clitkInvertVF -i $coeff_midp_in -o $vf_midp_in --type 1 --like $ref_phase_file
   abort_on_error midp $? clean_up_midp
-  clitkInvertVF -i $vf_midp_out -o $vf_midp_out
+  # clitkInvertVF -i $vf_midp_out -o $vf_midp_out
+  clitkInvertVF -i $coeff_midp_out -o $vf_midp_out --type 1 --like $ref_phase_file
   abort_on_error midp $? clean_up_midp
 
   # combine in and out VF's
index a201e18144dffd14f59c1bf05bac32006843a1db..5ccace9e6c41ecbf36506d1861ccf478a8edfdf7 100644 (file)
@@ -360,11 +360,6 @@ IF (CLITK_BUILD_TOOLS)
   TARGET_LINK_LIBRARIES(clitkCatImage clitkCommon ${ITK_LIBRARIES})
   SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkCatImage)
 
-  WRAP_GGO(clitkCoeffsToDVF_GGO_C clitkCoeffsToDVF.ggo)
-  ADD_EXECUTABLE(clitkCoeffsToDVF clitkCoeffsToDVF.cxx ${clitkCoeffsToDVF_GGO_C})
-  TARGET_LINK_LIBRARIES(clitkCoeffsToDVF clitkCommon ${ITK_LIBRARIES})
-  SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkCoeffsToDVF)
-
   IF(CLITK_EXPERIMENTAL)
     WRAP_GGO(clitkBinaryImageToMesh_GGO_C clitkBinaryImageToMesh.ggo)
     ADD_EXECUTABLE(clitkBinaryImageToMesh clitkBinaryImageToMesh.cxx ${clitkBinaryImageToMesh_GGO_C})
diff --git a/tools/clitkCoeffsToDVF.cxx b/tools/clitkCoeffsToDVF.cxx
deleted file mode 100644 (file)
index 266f8ae..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-#include "clitkCoeffsToDVF_ggo.h"
-#include "clitkCoeffsToDVF.h"
-#include "itkImage.h"
-#include "itkImageFileWriter.h"
-#include "itkImageIOFactory.h"
-#include <string>
-
-template <class DisplacementFieldType> 
-void
-Write(typename DisplacementFieldType::Pointer dvf, std::string fileName)
-{
-  typedef itk::ImageFileWriter<DisplacementFieldType> ImageWriterType;
-  typename ImageWriterType::Pointer writer = ImageWriterType::New();
-  writer->SetFileName(fileName);
-  writer->SetInput(dvf);
-  writer->Update();
-}
-
-int main(int argc, char** argv) 
-{
-  GGO(clitkCoeffsToDVF, args_info);
-  CLITK_INIT;
-
-  typename itk::ImageIOBase::Pointer image_io = itk::ImageIOFactory::CreateImageIO(args_info.input_arg, itk::ImageIOFactory::ReadMode);
-  image_io->SetFileName(args_info.input_arg);
-  image_io->ReadImageInformation();
-  
-  unsigned int ndim = image_io->GetNumberOfDimensions();
-  switch (ndim) {
-    case 2:
-    {
-      unsigned const dim = 2;
-      typedef itk::Vector<double, dim>  PixelType;
-      typedef itk::Image<PixelType, dim> DVFType;
-      typename DVFType::Pointer dvf = clitk::BLUTCoeffsToDVF<DVFType>(args_info.input_arg, args_info.like_arg);
-      Write<DVFType>(dvf, args_info.output_arg);
-    }
-    break;
-    
-    case 3:
-    {
-      unsigned const dim = 3;
-      typedef itk::Vector<double, dim>  PixelType;
-      typedef itk::Image<PixelType, dim> DVFType;
-      typename DVFType::Pointer dvf = clitk::BLUTCoeffsToDVF<DVFType>(args_info.input_arg, args_info.like_arg);
-      Write<DVFType>(dvf, args_info.output_arg);
-    }
-    break;
-    
-    default:
-      std::cerr << "Unsupported image dimension (either 2 or 3)" << std::endl;
-      return -1;
-  }
-  
-  return 0;
-}
\ No newline at end of file
diff --git a/tools/clitkCoeffsToDVF.ggo b/tools/clitkCoeffsToDVF.ggo
deleted file mode 100644 (file)
index a3d9d5e..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-#File clitkComposeVF.ggo
-#Author: Rômulo Pinho
-#Date : Wed 24 January 2012
-
-package "clitk"
-version "Convert a BLUT-coefficient image to a vector field."
-
-option "config"       - "Config file"     string    no
-option "input"       i     "Input1 VF filename"    string    yes
-option "output"       o     "Output VF filename"    string    yes
-option "like"   l "Image to read output parameters from"    string    yes
-
index 5cb6da8bdb956b63d9752bfaa624e23be41b24bd..0e6d1a47e2ad187e16f09379fc43cac4dd602d79 100644 (file)
@@ -19,7 +19,7 @@
 #define __clitkComposeVFGenericFilter_txx
 #include "clitkComposeVFGenericFilter.h"
 
-#include "clitkCoeffsToDVF.h"
+#include "clitkConvertBLUTCoeffsToVFFilter.h"
 
 namespace clitk
 {
@@ -47,8 +47,17 @@ namespace clitk
 
     //Define the image type
     if (m_Type == 1) {
-      input1 = BLUTCoeffsToDVF<ImageType>(m_InputName1, m_LikeImage, m_Verbose);
-      input2 = BLUTCoeffsToDVF<ImageType>(m_InputName2, m_LikeImage, m_Verbose);
+      typedef ConvertBLUTCoeffsToVFFilter<ImageType> VFFilterType;
+      typename VFFilterType::Pointer vf_filter = VFFilterType::New();
+      vf_filter->SetInputFileName(m_InputName1);
+      vf_filter->SetLikeFileName(m_LikeImage);
+      vf_filter->SetVerbose(m_Verbose);
+      vf_filter->Update();
+      input1 = vf_filter->GetOutput();
+
+      vf_filter->SetInputFileName(m_InputName2);
+      vf_filter->Update();
+      input2 = vf_filter->GetOutput();
     }
     else {
       //Read the input1
index c5b47179a3dd266814a866c87b4631eaddf2cb73..812ed0c69db5737b56b0eccc26e68c48dab90f3b 100644 (file)
@@ -19,7 +19,7 @@
 #define clitkInvertVFGenericFilter_txx
 
 #include "itkVectorResampleImageFilter.h"
-#include "clitkCoeffsToDVF.h"
+#include "clitkConvertBLUTCoeffsToVFFilter.h"
 
 /* =================================================
  * @file   clitkInvertVFGenericFilter.txx
@@ -177,7 +177,13 @@ InvertVFGenericFilter<args_info_type>::UpdateWithDimAndPixelType()
     typedef clitk::InvertVFFilter<InputImageType,OutputImageType> FilterType;
     typename FilterType::Pointer filter =FilterType::New();
     if (m_ArgsInfo.like_given) {
-      filter->SetInput(BLUTCoeffsToDVF<OutputImageType>(m_InputFileName, m_ArgsInfo.like_arg));
+      typedef ConvertBLUTCoeffsToVFFilter<InputImageType> VFFilterType;
+      typename VFFilterType::Pointer vf_filter = VFFilterType::New();
+      vf_filter->SetInputFileName(m_InputFileName);
+      vf_filter->SetLikeFileName(m_ArgsInfo.like_arg);
+      vf_filter->SetVerbose(m_Verbose);
+      vf_filter->Update();
+      filter->SetInput(vf_filter->GetOutput());
     }
 
     filter->SetVerbose(m_Verbose);
index 4c30c4c6b44e0632a5cf804be43d9a8e7fa778a9..cc3b17dd76666fbce0639ff3935ac1ebc58279cc 100644 (file)
@@ -28,7 +28,7 @@
  ===================================================*/
 
 #include "itkVectorResampleImageFilter.h"
-#include "clitkCoeffsToDVF.h"
+#include "clitkConvertBLUTCoeffsToVFFilter.h"
 
 namespace clitk
 {
@@ -90,7 +90,13 @@ WarpImageGenericFilter::UpdateWithDimAndPixelType()
   
   typename DeformationFieldType::Pointer deformationField;
   if (m_ArgsInfo.coeff_given) {
-    deformationField = BLUTCoeffsToDVF<DeformationFieldType>(m_ArgsInfo.coeff_arg, m_InputFileName, m_Verbose);
+    typedef ConvertBLUTCoeffsToVFFilter<DeformationFieldType> FilterType;
+    typename FilterType::Pointer filter = FilterType::New();
+    filter->SetInputFileName(m_ArgsInfo.coeff_arg);
+    filter->SetLikeFileName(m_InputFileName);
+    filter->SetVerbose(m_Verbose);
+    filter->Update();
+    deformationField = filter->GetOutput();
   }
   else {
     //Read the deformation field