From 4f2fb7a9394563fd56582639232a9fe12492c5d6 Mon Sep 17 00:00:00 2001 From: Romulo Pinho Date: Thu, 9 Feb 2012 17:55:24 +0100 Subject: [PATCH] This is a combination of 3 commits. 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 --- common/clitkCoeffsToDVF.h | 136 ----------- .../clitkConvertBLUTCoeffsToVFFilter.h | 93 +++++++ .../clitkConvertBLUTCoeffsToVFFilter.txx | 176 ++++++++++++++ ...neDeformableTransformToVFGenericFilter.cxx | 230 +++--------------- ...lineDeformableTransformToVFGenericFilter.h | 2 +- scripts/create_midP-2.0.sh | 24 +- tools/CMakeLists.txt | 5 - tools/clitkCoeffsToDVF.cxx | 56 ----- tools/clitkCoeffsToDVF.ggo | 12 - tools/clitkComposeVFGenericFilter.txx | 15 +- tools/clitkInvertVFGenericFilter.txx | 10 +- tools/clitkWarpImageGenericFilter.txx | 10 +- 12 files changed, 346 insertions(+), 423 deletions(-) delete mode 100644 common/clitkCoeffsToDVF.h create mode 100644 registration/clitkConvertBLUTCoeffsToVFFilter.h create mode 100644 registration/clitkConvertBLUTCoeffsToVFFilter.txx delete mode 100644 tools/clitkCoeffsToDVF.cxx delete mode 100644 tools/clitkCoeffsToDVF.ggo diff --git a/common/clitkCoeffsToDVF.h b/common/clitkCoeffsToDVF.h deleted file mode 100644 index 603ca70..0000000 --- a/common/clitkCoeffsToDVF.h +++ /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 - 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 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 - typename DisplacementFieldType::Pointer - BLUTCoeffsToDVF(std::string fileName, std::string likeFileName, bool verbose = false) - { - const unsigned int dim = DisplacementFieldType::ImageDimension; - typedef clitk::BSplineDeformableTransform TransformType; - typedef typename TransformType::CoefficientImageType CoefficientImageType; - - typedef itk::ImageFileReader CoeffReaderType; - typename CoeffReaderType::Pointer reader = CoeffReaderType::New(); - reader->SetFileName(fileName); - reader->Update(); - - #if ITK_VERSION_MAJOR >= 4 - typedef itk::TransformToDisplacementFieldSource ConvertorType; - #else - typedef itk::TransformToDeformationFieldSource 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(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 index 0000000..3cd1e67 --- /dev/null +++ b/registration/clitkConvertBLUTCoeffsToVFFilter.h @@ -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 ConvertBLUTCoeffsToVFFilter : + public itk::ImageSource + { + public: + + /** Standard class typedefs. */ + typedef ConvertBLUTCoeffsToVFFilter Self; + typedef itk::ImageSource Superclass; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer 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 BLUTTransformType; + typedef typename BLUTTransformType::CoefficientImageType BLUTCoefficientImageType; + typedef itk::BSplineDeformableTransform ITKTransformType; + + typedef itk::Transform< double, TDVFType::ImageDimension, TDVFType::ImageDimension> GenericTransformType; + +#if ITK_VERSION_MAJOR >= 4 + typedef itk::TransformToDisplacementFieldSource ConvertorType; +#else + typedef itk::TransformToDeformationFieldSource 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 index 0000000..32464d7 --- /dev/null +++ b/registration/clitkConvertBLUTCoeffsToVFFilter.txx @@ -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 + ConvertBLUTCoeffsToVFFilter::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 + void ConvertBLUTCoeffsToVFFilter::GenerateOutputInformation() + { + if (m_Verbose) + std::cout << "ConvertBLUTCoeffsToVFFilter::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 + void ConvertBLUTCoeffsToVFFilter::GenerateData() + { + // Read the input + typedef itk::ImageFileReader 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 "<SetLUTSamplingFactors(samplingFactors); + m_BLUTTransform->SetCoefficientImage(input); + + // Mask + typedef itk::ImageMaskSpatialObject 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..." <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 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 diff --git a/registration/clitkConvertBSplineDeformableTransformToVFGenericFilter.cxx b/registration/clitkConvertBSplineDeformableTransformToVFGenericFilter.cxx index 98e5f75..d0e1fa7 100644 --- a/registration/clitkConvertBSplineDeformableTransformToVFGenericFilter.cxx +++ b/registration/clitkConvertBSplineDeformableTransformToVFGenericFilter.cxx @@ -28,23 +28,11 @@ ===================================================*/ // 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 InputImageType; typedef itk::Image OutputImageType; - // Read the input - typedef itk::ImageFileReader InputReaderType; - InputReaderType::Pointer reader = InputReaderType::New(); - reader->SetFileName( m_InputFileName); - reader->Update(); - InputImageType::Pointer input= reader->GetOutput(); - + typedef ConvertBLUTCoeffsToVFFilter 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 ConvertorType; -#else - typedef itk::TransformToDeformationFieldSource ConvertorType; -#endif - ConvertorType::Pointer filter= ConvertorType::New(); - - //Output image info - if (m_ArgsInfo.like_given) - { -/* typedef itk::ImageFileReader 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;iSetOutputOrigin(origin); - } - if (m_ArgsInfo.spacing_given) - { - OutputImageType::SpacingType spacing; - for (i=0;iSetOutputSpacing(spacing); - } - if (m_ArgsInfo.spacing_given) - { - OutputImageType::SizeType size; - for (i=0;iSetOutputSize(size); - } + if (m_ArgsInfo.like_given) { + filter->SetLikeFileName(m_ArgsInfo.like_arg); } - - if (m_Verbose) - { - std::cout<< "Setting output origin to "<GetOutputOrigin()<<"..."<GetOutputSpacing()<<"..."<GetOutputSize()<<"..."<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..." <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; iGetSpacing()[i]/ filter->GetOutputSpacing()[i]); - if (m_Verbose) std::cout<<"Setting sampling factor "<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 CoefficientType; - typedef itk::Image CoefficientImageType; - typedef clitk::VectorImageToImageFilter 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..."<Update(); - } - catch (itk::ExceptionObject) - { - std::cerr<<"Error: Exception thrown during execution convertion filter!"<SetBLUTSplineOrders(order); } - + + if (m_ArgsInfo.mask_given) + filter->SetMaskFileName(m_ArgsInfo.mask_arg); + + filter->Update(); + OutputImageType::Pointer output=filter->GetOutput(); - // ----------------------------------------------- // Output // ----------------------------------------------- diff --git a/registration/clitkConvertBSplineDeformableTransformToVFGenericFilter.h b/registration/clitkConvertBSplineDeformableTransformToVFGenericFilter.h index f65802d..8447a08 100644 --- a/registration/clitkConvertBSplineDeformableTransformToVFGenericFilter.h +++ b/registration/clitkConvertBSplineDeformableTransformToVFGenericFilter.h @@ -30,7 +30,7 @@ // clitk include #include "clitkCommon.h" -// #include "clitkConvertBSplineDeformableTransformToVF_ggo.h" +#include "clitkConvertBSplineDeformableTransformToVF_ggo.h" //itk include #include "itkLightObject.h" diff --git a/scripts/create_midP-2.0.sh b/scripts/create_midP-2.0.sh index c38555a..3b943d3 100755 --- a/scripts/create_midP-2.0.sh +++ b/scripts/create_midP-2.0.sh @@ -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 diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index a201e18..5ccace9 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -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 index 266f8ae..0000000 --- a/tools/clitkCoeffsToDVF.cxx +++ /dev/null @@ -1,56 +0,0 @@ -#include "clitkCoeffsToDVF_ggo.h" -#include "clitkCoeffsToDVF.h" -#include "itkImage.h" -#include "itkImageFileWriter.h" -#include "itkImageIOFactory.h" -#include - -template -void -Write(typename DisplacementFieldType::Pointer dvf, std::string fileName) -{ - typedef itk::ImageFileWriter 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 PixelType; - typedef itk::Image DVFType; - typename DVFType::Pointer dvf = clitk::BLUTCoeffsToDVF(args_info.input_arg, args_info.like_arg); - Write(dvf, args_info.output_arg); - } - break; - - case 3: - { - unsigned const dim = 3; - typedef itk::Vector PixelType; - typedef itk::Image DVFType; - typename DVFType::Pointer dvf = clitk::BLUTCoeffsToDVF(args_info.input_arg, args_info.like_arg); - Write(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 index a3d9d5e..0000000 --- a/tools/clitkCoeffsToDVF.ggo +++ /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 - diff --git a/tools/clitkComposeVFGenericFilter.txx b/tools/clitkComposeVFGenericFilter.txx index 5cb6da8..0e6d1a4 100644 --- a/tools/clitkComposeVFGenericFilter.txx +++ b/tools/clitkComposeVFGenericFilter.txx @@ -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(m_InputName1, m_LikeImage, m_Verbose); - input2 = BLUTCoeffsToDVF(m_InputName2, m_LikeImage, m_Verbose); + typedef ConvertBLUTCoeffsToVFFilter 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 diff --git a/tools/clitkInvertVFGenericFilter.txx b/tools/clitkInvertVFGenericFilter.txx index c5b4717..812ed0c 100644 --- a/tools/clitkInvertVFGenericFilter.txx +++ b/tools/clitkInvertVFGenericFilter.txx @@ -19,7 +19,7 @@ #define clitkInvertVFGenericFilter_txx #include "itkVectorResampleImageFilter.h" -#include "clitkCoeffsToDVF.h" +#include "clitkConvertBLUTCoeffsToVFFilter.h" /* ================================================= * @file clitkInvertVFGenericFilter.txx @@ -177,7 +177,13 @@ InvertVFGenericFilter::UpdateWithDimAndPixelType() typedef clitk::InvertVFFilter FilterType; typename FilterType::Pointer filter =FilterType::New(); if (m_ArgsInfo.like_given) { - filter->SetInput(BLUTCoeffsToDVF(m_InputFileName, m_ArgsInfo.like_arg)); + typedef ConvertBLUTCoeffsToVFFilter 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); diff --git a/tools/clitkWarpImageGenericFilter.txx b/tools/clitkWarpImageGenericFilter.txx index 4c30c4c..cc3b17d 100644 --- a/tools/clitkWarpImageGenericFilter.txx +++ b/tools/clitkWarpImageGenericFilter.txx @@ -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(m_ArgsInfo.coeff_arg, m_InputFileName, m_Verbose); + typedef ConvertBLUTCoeffsToVFFilter 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 -- 2.47.1