Deforming with NiftyReg is different than deforming in Slicer

I’m integrating NiftyReg into an extension. (one of the goals is to get the computed transformation/deformation into Slicer)

I registered two images with reg_f3d and saved the control point grid (to later get the deformation).

reg_f3d -ref fixed.nii -flo moving.nii -res warped.nii -cpp controlPointGrid.nii



I then used reg_transform to get the displacement field as a .nii

reg_transform -ref fixed.nii -disp controlPointGrid.nii displacement.nii



I then loaded the displacement.nii into Slicer as a Transform. I got the following warning, but I’m not sure if it is relevant:

Warning: Loading /Desktop/volumes/niftyreg/displacement.nii - NIFTI file may not contain valid displacement field, the transform may be incorrect. Intent code is expected to be ‘1006’ (displacement vector), but the file contained: ‘1007’. Filename: ‘/Desktop/volumes/niftyreg/displacement.nii’.



Then I applied the transformation in Slicer to the moving image, but the result was very different (‘clearly wrong’) from the moving image transformed by NiftyReg.
First screenshot is a 50/50 overlay of the NiftyReg warped image (purple) over the fixed image (green)
First screenshot is a 50/50 overlay of the Slicer transformed image (purple) over the fixed image (green)




I’m not sure if the displacement field is somehow encoded differently/incorrectly or if I’m missing some steps in between. (the author of NiftyReg mentioned that “Note that the transformation are encoded from the reference to the floating space and all is stored in physical space (mm) rather than voxel space.” - not sure if this is relevant here)



Here’s a link to all the volumes

Due to using a wrong intent code, the ITK reader does not know that the vectors store spatial displacement and therefore the vectors are not converted to the correct coordinate system.

VoxelMorph had a similar issue. If niftyreg developers cannot fix the problem quickly then you can patch the nifti file similarly to how it is described in the voxelmorph issue.

1 Like

The problem was a bit simpler - the displacement field from NiftiReg already had the correct shape, I only had to change the intent code

Great! Please report the issue to NiftyReg maintainers and copy the link to the issue here for future reference. Thank you!