I had this question was because if I resample the image and displacement field to 1.035003662109375, 1.035003662109375, 3, the displacement field will not deform the moving image to overlap with fix image. Two images and displacement field deformed to 1.035003662109375, 1.035003662109375, 2.5 works ok. However, since my fix and moving image has the original spacing x, x, 3, I am wondering if 3 will be a better option for resampling than 2.5.
You do not need to resample the displacement field. Construct a DisplacementFieldTransform from the displacement field image and use that for resampling. The DisplacementFieldTransform uses an interpolator, so the resampling will work even if the image spacing and deformation field spacings differ.
For more details about transformations in general and bounded transformation in particular, see this jupyter notebook.
My goal is using the moving and fix images as the input data, and the dvf as the output. So I was wondering that my model may need to have the dvfs all have the same spacing.
It isn’t clear what you are asking for (beyond the details given in the previous answer). Possibly take a look at the Demons registration notebook and that will address your needs.
Thank you for the reply and the jupyter notebook of registration.
I want to change the size and the spacing of the deformation vector field, so the dvf would have the same spacing and size as my fixed image and moving image.
Since the deformation vector field contains the displacement information, and the resample filter are usually used for change the size and spacing of scalar, so I want to ask if I use sitk.Resample(dvf, reference, Transforms(), sitk.sitkLinear) will return a correct dvf which could deform the image just like the original dvf does.
I am not deforming my image or registration, just resampling. The deforming I mentioned is just a method for me to check if the new dvf works correctly as the old dvf. I need fixed image, moving image and dvf all in same spacing and size, so I could send them into my model.
I found the document of interpolation mentioned that sitkLinear works for both vector and scalar, so I think the sitk.Resample() with sitk.sitkLinear do return a correct dvf with new spacing and size?
Thanks for the clarification, that helped. Resampling the dvf will return an approximately similar transformation. Most likely this will be sufficiently accurate for your use case.
There will be differences between the original and resampled field because of the discrete nature of resampling and interpolation. You should compare the differences by applying the two transformations to the same set of points and computing the differences (|| T_{old}(p_i) - T_{new}(p_i)||). You can use higher order interpolation (see documentation for the various options).
If you want to verify that you correctly process or apply a transform (displacement field or any other types or combination of those) to an image then you may try it in 3D Slicer. It can load any ITK transform and can apply it to any object (images, segmentations, meshes, other transforms, etc.). All necessary interpolation, inversion, reordering, etc. are automatically performed and you can see the results in real-time in both 2D slice and 3D views. You can also create a displacement field from any transform that matches the geometry of a a chosen image (in Transforms module / Convert section) by a few clicks.