int
main(int argc, char * argv[])
{
if (argc < 3)
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " fixedImage movingImage" << std::endl;
return EXIT_FAILURE;
}
using PixelType = float;
ReaderType::Pointer fixedReader = ReaderType::New();
ReaderType::Pointer movingReader = ReaderType::New();
fixedReader->SetFileName(argv[1]);
movingReader->SetFileName(argv[2]);
try
{
fixedReader->Update();
movingReader->Update();
}
catch (const itk::ExceptionObject & excep)
{
std::cerr << "Exception catched !" << std::endl;
std::cerr << excep << std::endl;
}
using MetricType =
MetricType::Pointer metric = MetricType::New();
TransformType::Pointer transform = TransformType::New();
using InterpolatorType =
InterpolatorType::Pointer interpolator = InterpolatorType::New();
transform->SetIdentity();
ImageType::ConstPointer fixedImage = fixedReader->GetOutput();
ImageType::ConstPointer movingImage = movingReader->GetOutput();
metric->SetTransform(transform);
metric->SetMovingInterpolator(interpolator);
metric->SetFixedImage(fixedImage);
metric->SetMovingImage(movingImage);
metric->SetVirtualDomainFromImage(fixedImage);
try
{
metric->Initialize();
}
catch (const itk::ExceptionObject & excep)
{
std::cerr << "Exception catched !" << std::endl;
std::cerr << excep << std::endl;
return EXIT_FAILURE;
}
MetricType::MovingTransformParametersType displacement(
Dimension);
constexpr int rangex = 50;
constexpr int rangey = 50;
for (int dx = -rangex; dx <= rangex; dx++)
{
for (int dy = -rangey; dy <= rangey; dy++)
{
displacement[0] = dx;
displacement[1] = dy;
metric->SetParameters(displacement);
const double value = metric->GetValue();
std::cout << dx << " " << dy << " " << value << std::endl;
}
}
return EXIT_SUCCESS;
}