SimpleITK: demons registration filter requere the size of fixed/moving image to be the same

I want to use the demons registration method of SimpleITK between two images with different image size. For example, a 64X64X64 (moving image) and 128X128X128 (fixed image).

import SimpleITK as sitk
import numpy as np
fixedImg = sitk.GetImageFromArray(np.random.random(size=[128, 128, 128]))
movingImg = sitk.GetImageFromArray(np.random.random(size=[64, 64, 64]))
demons_filter = sitk.FastSymmetricForcesDemonsRegistrationFilter()
demons_filter.SetNumberOfIterations(20)
# Regularization (update field - viscous, total field - elastic).
demons_filter.SetSmoothDisplacementField(True)
demons_filter.SetStandardDeviations(2.0)

displacement_field = demons_filter.Execute(fixedImg,
                                           movingImg)

However, a bug is reported:

Traceback (most recent call last):
  File "C:/Users/MLoong/Desktop/medpro/Demo/test.py", line 12, in <module>
    movingImg)
  File "D:\Anaconda3\envs\gitlab_medpro\lib\site-packages\SimpleITK\SimpleITK.py", line 25809, in Execute
    return _SimpleITK.FastSymmetricForcesDemonsRegistrationFilter_Execute(self, *args)
RuntimeError: Exception thrown in SimpleITK FastSymmetricForcesDemonsRegistrationFilter_Execute: D:\a\1\sitk\Code\BasicFilters\src\sitkImageFilter.cxx:63:
sitk::ERROR: Input "movingImage" for "FastSymmetricForcesDemonsRegistrationFilter" has size of [ 64, 64, 64 ] which does not match the primary input's size of [ 128, 128, 128 ]!

Should I resample the moving image to be the same size of fixed image before demons_filter.Execute?

Hello @zhang-qiang-github,

Yes, you need to resample. Please see “Warning” in the FastSymmetricForcesDemonsRegistrationFilter documentation.