I am using SimpleITK to perform non rigid registration (bsplines). I am also using 3d Slicer to visualize the produced transform. Now the transform .tfm file is only read by slicer if it’s a 3d transform and not 2d. What I am currently doing is to compute the dense displacement field and then saving it as an image which slicers accepts. However I am wondering if there is a better way by using only the .tfm file? something like converting the 2d bspline transform to a 3d version of it so that slicer is able to read it?
Hello @rogertrullo ,
Please see code below (haven’t tested it beyond seeing that it doesn’t crash). Basically, the idea is to convert the transformation to a 3D one, where the displacements for the BSpline control points in the z direction are all zeros.
import SimpleITK as sitk bspline_2d_file_name = 'bspline_example.tfm' tx = sitk.BSplineTransform(sitk.ReadTransform(bspline_2d_file_name)) coefficient_images = tx.GetCoefficientImages() new_coeffs =  for img in coefficient_images: new_image = sitk.Image(img.GetSize() + (1,), img.GetPixelID()) new_image.SetOrigin(img.GetOrigin() + (0,)) new_image.SetSpacing(img.GetSpacing() + (1,)) new_image[:,:,0] = img new_coeffs.append(new_image) # Add zero displacements in z direction. new_coeffs.append(sitk.Image(new_coeffs.GetSize(),new_coeffs.GetPixelID())) bspline3d = sitk.BSplineTransform(new_coeffs, tx.GetOrder()) sitk.WriteTransform(bspline3d, '3d_'+bspline_2d_file_name)
Thank you very much @zivy vy
I am having an issue in this line:
new_image[:,:,0] = img
SimpleITK/SimpleITK.py in setitem(self, idx, value)
#the index parameter was an invalid set of objects
raise IndexError(“invalid index”)
The shapes seem to correspond well:
print(new_image.GetSize()) (63, 51, 1) print(img.GetSize()) (63, 51)
Do you have any idea what can be the issue?
I am working with the latest version of SimpleITK, 2.0.2. Support for this assignment style was added in the 2.x releases.
I have this version:
I will update and try again
it works now! thank you so much!