Hello, everyone.
I am implementing a pipeline to load a LinearTransform.h5
and convert that into a displacement field. However, I am having a problem loading the transform into a real transform object-pointer to proceed. Please take a look into (part of) code:
#include "itkVersorRigid3DTransform.h"
#include <iostream>
#include <fstream>
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkTransformFileReader.h"
#include "itkImageRegionIterator.h"
> // Writing Transform
> using TransformReaderType = itk::TransformFileReaderTemplate<double>;
> TransformReaderType::Pointer transformReader = TransformReaderType::New();
> transformReader->SetFileName(argv[3]);
> transformReader->Update();
>
> TransformReaderType::TransformListType * transforms = transformReader->GetTransformList();
> auto it = transforms->begin();
> std::cout<< "Size:" << (*it). << std::endl;
>
> // Creating and writing the displacement vector image
> // Based on example: https://itk.org/Doxygen/html/Examples_2RegistrationITKv3_2DeformableRegistration8_8cxx-example.html
>
> using VectorType = itk::Vector<float, Dimension>;
> using DisplacementFieldType = itk::Image<VectorType, Dimension>;
> DisplacementFieldType::Pointer field = DisplacementFieldType::New();
> field->SetRegions(fixedImageReader->GetOutput()->GetBufferedRegion());
> field->SetSpacing(fixedImageReader->GetOutput()->GetSpacing());
> field->SetOrigin(fixedImageReader->GetOutput()->GetOrigin());
> field->SetDirection(fixedImageReader->GetOutput()->GetDirection());
> field->Allocate();
>
> using FieldIteratorType = itk::ImageRegionIterator<DisplacementFieldType>;
> FieldIteratorType fi( field, movingImageReader->GetOutput()->GetBufferedRegion());
> fi.GoToBegin();
>
> using TransformType = itk::VersorRigid3DTransform<double>;
> TransformType::InputPointType movingPoint;
> TransformType::OutputPointType transformedPoint;
> DisplacementFieldType::IndexType index;
> TransformType::Pointer transform = TransformType::New();
>
>
> VectorType displacement;
>
> while( !fi.IsAtEnd()){
> index = fi.GetIndex();
> field->TransformIndexToPhysicalPoint( index, movingPoint );
> transforms->begin();
> transformedPoint = transforms-> ->TransformPoint( movingPoint );
> displacement = transformedPoint - movingPoint;
> fi.Set(displacement);
> ++fi;
> }
>
> using FieldWriterType = itk::ImageFileWriter<DisplacementFieldType>;
> FieldWriterType::Pointer fieldWriter = FieldWriterType::New();
> fieldWriter->SetInput(field);
> fieldWriter->SetFileName(imagePath + "dispField-q=" + id + ".nrrd");
> fieldWriter->Update();
>
Thanks in advance!