Hi all,
I have a displacement field “field.nii
” that I need to convert from RAS to LPS so that I can use it in Slicer. What I’m doing now is:
- Read the file with SimpleITK
- Modify the data
- Save it
- Load it with slicer.util.loadTransform()
Is there a way to create a vtkMRMLGridTransformNode
and set the vector data or to modify the data of the transform node directly?
My code:
def getRASFieldFromLPSField(self, displacementFieldPath):
image = sitk.ReadImage(displacementFieldPath)
arr = sitk.GetArrayFromImage(image)
arr[..., :2] *= -1 # RAS to LPS
# Create new image
newImage = sitk.GetImageFromArray(arr)
newImage.SetOrigin(image.GetOrigin())
newImage.SetDirection(image.GetDirection())
newImage.SetSpacing(image.GetSpacing())
sitk.WriteImage(newImage, displacementFieldPath)
transformNode = slicer.util.loadTransform(displacementFieldPath, returnNode=True)[1]
return transformNode
Best,
Fernando