registration is too slow and changing sample rate seems not working

Hello everyone,
I’m using ITK for 3D brain image registration, but the registration is too slow. I try to change the sample rate but it seems not working, reducing sample rate does not affect the registration speed. It really confused me and I’m trying to get some help.
Here is part of the code

using ImageType = itk::Image<float, K_DIM>;
using TransformType = itk::VersorRigid3DTransform<double>;
using MetricType = itk::MattesMutualInformationImageToImageMetricv4<ImageType, ImageType>;
using OptimizerType = itk::RegularStepGradientDescentOptimizerv4<double>;
using RegistrationType = itk::ImageRegistrationMethodv4<ImageType, ImageType, TransformType>;

RegistrationType::Pointer registration = RegistrationType::New();
registration->SetFixedImage(fixed);
registration->SetMovingImage(moving);
MetricType::Pointer metric = MetricType::New();
registration->SetMetric(metric);
OptimizerType::Pointer optimizer = OptimizerType::New();
registration->SetOptimizer(optimizer);

metric->SetNumberOfHistogramBins(histogram_bins);
metric->SetUseMovingImageGradientFilter(false);
metric->SetUseFixedImageGradientFilter(false);

if (sample_rate < 1) {
    registration->SetMetricSamplingStrategy(RegistrationType::RANDOM);
    registration->SetMetricSamplingPercentage(sample_rate);
    registration->MetricSamplingReinitializeSeed(42);
}
else {
    metric->SetUseSampledPointSet(false);
}

Make sure you are compiling in release mode. Debug is usually many times slower. But changing the sampling percentage should have made some difference in the speed. Have you tried setting sample_rate to 0.1, 0.01 or 0.001?

Hi dzenanz, thank you for your help. I’v found the error, calling SetNumberOfLevels will reset the sampling percentage to 1, after rearrange the code, problem solved.

1 Like