final registration results

Hello everyone,

can someone of you explain to me why every time i run this program it gives me differents results (see picture) image

Cordially

===================================================================
def multires_registration(fixed_image, moving_image, initial_transform):
registration_method = sitk.ImageRegistrationMethod()
registration_method.SetMetricAsMattesMutualInformation(numberOfHistogramBins=50)
registration_method.SetMetricSamplingStrategy(registration_method.RANDOM)
registration_method.SetMetricSamplingPercentage(0.01)
registration_method.SetInterpolator(sitk.sitkLinear)
registration_method.SetOptimizerAsGradientDescent(learningRate=1.0, numberOfIterations=100, estimateLearningRate=registration_method.Once)
registration_method.SetOptimizerScalesFromPhysicalShift()
registration_method.SetInitialTransform(initial_transform, inPlace=False)
registration_method.SetShrinkFactorsPerLevel(shrinkFactors = [4,2,1])
registration_method.SetSmoothingSigmasPerLevel(smoothingSigmas = [2,1,0])
registration_method.SmoothingSigmasAreSpecifiedInPhysicalUnitsOn()

final_transform = registration_method.Execute(fixed_image, moving_image)
print('Final metric value: {0}'.format(registration_method.GetMetricValue()))
print('Optimizer\'s stopping condition, {0}'.format(registration_method.GetOptimizerStopConditionDescription()))
return (final_transform, registration_method.GetMetricValue())

fixed_image_name =‘data_t1_ref.hdr’
moving_image_name= ‘data_t1_4_inh.hdr’
fixed_image = sitk.ReadImage(fixed_image_name, sitk.sitkFloat32)
moving_image = sitk.ReadImage(moving_image_name, sitk.sitkFloat32)

initial_transform = sitk.CenteredTransformInitializer(fixed_image,
moving_image,
sitk.Euler3DTransform(),
sitk.CenteredTransformInitializerFilter.GEOMETRY)

moving_resampled = sitk.Resample(moving_image, fixed_image, initial_transform, sitk.sitkLinear, 0.0, moving_image.GetPixelID())

final_transform,_ = multires_registration(fixed_image, moving_image, initial_transform)

=================================================================

You need to set a fixed pseudo-random seed to have reproducible results. See this discussion.

1 Like

i’m using python and SimpleITK for the first time so please can you show what should i add ?
Thank you :blush:

Hello @Dodox,

The random seed is set in the SetMetricSamplingPercentage.

A quick way of becoming familiar with SimpleITK is to go over our tutorials, primarily based on Jupyter notebooks. The latest is available online. We also maintain a large notebook repository on github, and our read-the-docs site.

hello @zivy
thank you for your clarification, I have one last question , how much should be the value of the random seed in the SetMetricSamplingPercentage in odrer to get always the same results ?

Cordially

Any constant value will do. 1 is a good choice.