*
===================================================*/
+#include "itkVectorResampleImageFilter.h"
+#include "clitkBSplineDeformableTransform.h"
+#if ITK_VERSION_MAJOR >= 4
+#include "itkTransformToDisplacementFieldSource.h"
+#else
+#include "itkTransformToDeformationFieldSource.h"
+#endif
namespace clitk
{
}
}
+//-------------------------------------------------------------------
+// Convert Coefficient image to DVF
+//-------------------------------------------------------------------
+template<class DisplacementFieldType>
+typename DisplacementFieldType::Pointer
+WarpImageGenericFilter::CoeffsToDVF(std::string fileName, std::string likeFileName)
+{
+ 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();
+
+ typename TransformType::Pointer transform = TransformType::New();
+ transform->SetCoefficientImage(reader->GetOutput());
+
+#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 < DisplacementFieldType::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 < DisplacementFieldType::ImageDimension; j++)
+ output_direction[i][j] = imageIO->GetDirection(i)[j];
+ }
+
+ if (m_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();
+}
//-------------------------------------------------------------------
// Update with the number of dimensions and the pixeltype
typedef itk::Image<PixelType, Dimension> OutputImageType;
typedef itk::Vector<float, Dimension> DisplacementType;
typedef itk::Image<DisplacementType, Dimension> DeformationFieldType;
-
-
+
// Read the input
typedef itk::ImageFileReader<InputImageType> InputReaderType;
typename InputReaderType::Pointer reader = InputReaderType::New();
reader->SetFileName( m_InputFileName);
reader->Update();
typename InputImageType::Pointer input= reader->GetOutput();
-
- //Read the deformation field
- typedef itk::ImageFileReader<DeformationFieldType> DeformationFieldReaderType;
- typename DeformationFieldReaderType::Pointer deformationFieldReader= DeformationFieldReaderType::New();
- deformationFieldReader->SetFileName(m_ArgsInfo.vf_arg);
- deformationFieldReader->Update();
- typename DeformationFieldType::Pointer deformationField =deformationFieldReader->GetOutput();
+
+ typename DeformationFieldType::Pointer deformationField;
+ if (m_ArgsInfo.coeff_given) {
+ deformationField = CoeffsToDVF<DeformationFieldType>(m_ArgsInfo.coeff_arg, m_InputFileName);
+ }
+ else {
+ //Read the deformation field
+ typedef itk::ImageFileReader<DeformationFieldType> DeformationFieldReaderType;
+ typename DeformationFieldReaderType::Pointer deformationFieldReader= DeformationFieldReaderType::New();
+ deformationFieldReader->SetFileName(m_ArgsInfo.vf_arg);
+ deformationFieldReader->Update();
+ deformationField =deformationFieldReader->GetOutput();
+ }
// Intensity interpolator
typedef clitk::GenericVectorInterpolator<args_info_clitkWarpImage, DeformationFieldType, double> GenericInterpolatorType;
// -------------------------------------------
// Spacing like input
// -------------------------------------------
- else {
+ else if (!m_ArgsInfo.coeff_given) {
// Get size
typename DeformationFieldType::SizeType newSize;
for (unsigned int i=0 ; i <Dimension; i++)