It seems that FastSymmetricForcesDemonsRegistrationFilter.SetUseImageSpacing()
does not work, I get the same result when setting it to True
or False
, and same thing with FastSymmetricForcesDemonsRegistrationFilter.UseImageSpacingOn()
.
Here is a script which demonstrates the behavior:
standard_deviations = 1.0
num_iterations = 200
def demons_registration(fixed_path, moving_path, displacement_field_path, use_image_spacing=True, image_spacing_on=True):
# Open images with SimpleITK
fixed = sitk.ReadImage(str(fixed_path), sitk.sitkFloat64)
moving = sitk.ReadImage(str(moving_path), sitk.sitkFloat64)
print(' Demons registration...')
# The fast symmetric forces Demons Registration Filter
# Note there is a whole family of Demons Registration algorithms included in
# SimpleITK (https://itk.org/Doxygen/html/group__DeformableImageRegistration.html)
demons = sitk.FastSymmetricForcesDemonsRegistrationFilter()
demons.SetUseImageSpacing(use_image_spacing)
if image_spacing_on:
demons.UseImageSpacingOn()
else:
demons.UseImageSpacingOff()
demons.SetNumberOfIterations(num_iterations)
# Standard deviation for Gaussian smoothing of displacement field
demons.SetStandardDeviations(standard_deviations)
displacement_field = demons.Execute(fixed, moving)
displacement_field_data = sitk.GetArrayFromImage(displacement_field)
sitk.WriteImage(displacement_field, str(displacement_field_path))
return displacement_field_path
flair1 = '/data/SEL/emisepTesting0/rennes_20170112_05/flair_time01_normalized.nii.gz'
flair2 = '/data/SEL/emisepTesting0/rennes_20170112_05/flair_time02_normalized.nii.gz'
df = '/data/amasson/test/df/df_spacing11.nii.gz'
demons_registration(flair1, flair2, df, True, True)
df11_image = sitk.ReadImage(df)
df11_data = sitk.GetArrayFromImage(df11_image)
df = '/data/amasson/test/df/df_spacing10.nii.gz'
demons_registration(flair1, flair2, df, False, True)
df10_image = sitk.ReadImage(df)
df10_data = sitk.GetArrayFromImage(df10_image)
print(np.all(df11_data == df10_data))
df = '/data/amasson/test/df/df_spacing01.nii.gz'
demons_registration(flair1, flair2, df, True, False)
df01_image = sitk.ReadImage(df)
df01_data = sitk.GetArrayFromImage(df01_image)
print(np.all(df01_data == df10_data))
df = '/data/amasson/test/df/df_spacing00.nii.gz'
demons_registration(flair1, flair2, df, False, False)
df00_image = sitk.ReadImage(df)
df00_data = sitk.GetArrayFromImage(df00_image)
print(np.all(df01_data == df00_data))
And here is the output showing that all images are equal:
Demons registration...
Demons registration...
True
Demons registration...
True
Demons registration...
True