int
main(int argc, char * argv[])
{
if (argc != 6)
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " fixedImageFile movingImageFile ";
std::cerr << "outputImagefile [differenceImageAfter]";
std::cerr << "[differenceImageBefore]" << std::endl;
return EXIT_FAILURE;
}
const char * fixedImageFile = argv[1];
const char * movingImageFile = argv[2];
const char * outputImageFile = argv[3];
const char * differenceImageAfterFile = argv[4];
const char * differenceImageBeforeFile = argv[5];
using PixelType = float;
const auto fixedImage = itk::ReadImage<FixedImageType>(fixedImageFile);
const auto movingImage = itk::ReadImage<MovingImageType>(movingImageFile);
optimizer->SetLearningRate(4);
optimizer->SetMinimumStepLength(0.001);
optimizer->SetRelaxationFactor(0.5);
optimizer->SetNumberOfIterations(200);
registration->SetInitialTransform(initialTransform);
registration->SetMetric(metric);
registration->SetOptimizer(optimizer);
registration->SetFixedImage(fixedImage);
registration->SetMovingImage(movingImage);
TransformType::ParametersType initialParameters(movingInitialTransform->GetNumberOfParameters());
initialParameters[0] = 0.0;
initialParameters[1] = 0.0;
movingInitialTransform->SetParameters(initialParameters);
registration->SetMovingInitialTransform(movingInitialTransform);
identityTransform->SetIdentity();
registration->SetFixedInitialTransform(identityTransform);
constexpr unsigned int numberOfLevels = 1;
registration->SetNumberOfLevels(numberOfLevels);
RegistrationType::ShrinkFactorsArrayType shrinkFactorsPerLevel;
shrinkFactorsPerLevel.SetSize(1);
shrinkFactorsPerLevel[0] = 1;
registration->SetShrinkFactorsPerLevel(shrinkFactorsPerLevel);
RegistrationType::SmoothingSigmasArrayType smoothingSigmasPerLevel;
smoothingSigmasPerLevel.SetSize(1);
smoothingSigmasPerLevel[0] = 0;
registration->SetSmoothingSigmasPerLevel(smoothingSigmasPerLevel);
try
{
registration->Update();
std::cout << "Optimizer stop condition: " << registration->GetOptimizer()->GetStopConditionDescription()
<< std::endl;
}
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
auto transform = registration->GetTransform();
auto finalParameters = transform->GetParameters();
auto translationAlongX = finalParameters[0];
auto translationAlongY = finalParameters[1];
auto numberOfIterations = optimizer->GetCurrentIteration();
auto bestValue = optimizer->GetValue();
std::cout << "Result = " << std::endl;
std::cout << " Translation X = " << translationAlongX << std::endl;
std::cout << " Translation Y = " << translationAlongY << std::endl;
std::cout << " Iterations = " << numberOfIterations << std::endl;
std::cout << " Metric value = " << bestValue << std::endl;
outputCompositeTransform->AddTransform(movingInitialTransform);
outputCompositeTransform->AddTransform(registration->GetModifiableTransform());
resampler->SetInput(movingImage);
resampler->SetTransform(outputCompositeTransform);
resampler->SetUseReferenceImage(true);
resampler->SetReferenceImage(fixedImage);
resampler->SetDefaultPixelValue(100);
using OutputPixelType = unsigned char;
caster->SetInput(resampler->GetOutput());
difference->SetInput1(fixedImage);
difference->SetInput2(resampler->GetOutput());
intensityRescaler->SetInput(difference->GetOutput());
resampler->SetDefaultPixelValue(1);
resampler->SetTransform(identityTransform);
itk::WriteImage(intensityRescaler->GetOutput(), differenceImageBeforeFile);
return EXIT_SUCCESS;
}