Take a look in the following results. This first image is the overlapped images (CT and T1) before any registration.
After the firs stage is concluded we have the following alignment:
This image obtained after the first stage (Almost perfect alignment) is used as the input for the rotation stage. An the setting code is the following:
registrationR->SetFixedImage( fixedImageReader->GetOutput() );
registrationR->SetMovingImage( resampledMovingImage );
// Setting initial transform configuration::
using RotationTransformInitializerType = itk::CenteredTransformInitializer<
RotationTransformType,
FixedImageType,
MovingImageType >;
RotationTransformType::Pointer initialTransformRotation = RotationTransformType::New();
// initialTransformRotation->SetIdentity();
RotationTransformInitializerType::Pointer rotationInitializer = RotationTransformInitializerType::New();
rotationInitializer->SetTransform( initialTransformRotation );
rotationInitializer->SetFixedImage( fixedImageReader->GetOutput() );
rotationInitializer->SetMovingImage( resampledMovingImage );
rotationInitializer->MomentsOn();
rotationInitializer->InitializeTransform();
// Angular componet of initial transform
//
using VersorType = RotationTransformType::VersorType;
using VectorType = VersorType::VectorType;
VersorType rotation;
VectorType axis;
axis[0] = 0.0;
axis[1] = 0.0;
axis[2] = 1.0;
constexpr double angle = 0;
rotation.Set( axis, angle );
initialTransformRotation->SetRotation( rotation );
registrationR->SetInitialTransform( initialTransformRotation );
registrationR->InPlaceOn();
But I am still getting the same initial misoverlapping error:
itk::ERROR: itk::ERROR: MattesMutualInformationImageToImageMetricv4(0x55d901657c60): All samples map outside
moving image buffer. The images do not sufficiently overlap. They need to be initialized to
have more overlap before this metric will work. For instance, you can align the image centers by translation.
Very strange, I believe.