Plastimatch from Python Interactor returns incorrect vector field

Dear Community,

I am working to a project about contrast-enhanced CT images registration using Slicer Pyhton Interactor to perform Plastimatch B-spline deformable registration. Following this link, I was able to write these lines to perform it:

import vtkSlicerPlastimatchPyModuleLogicPython

reg = vtkSlicerPlastimatchPyModuleLogicPython.vtkPlmpyRegistration()
reg.SetMRMLScene(slicer.mrmlScene)
reg.SetFixedImageID(getNode('Fixed_img').GetID())
reg.SetMovingImageID(getNode('Moving_img').GetID())

output = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLScalarVolumeNode', 'Output volume_PythonInteractor')
displayNode = slicer.vtkMRMLScalarVolumeDisplayNode()
slicer.mrmlScene.AddNode(displayNode)

output_VectorField = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLGridTransformNode', 'Output vector field_PythonInteractor')

reg.SetOutputVolumeID(output.GetID())
reg.SetOutputVectorFieldID(output_VectorField.GetID())

par = "[STAGE]\nxform = bspline"
reg.SetRegistrationParameters(par)
reg.RunRegistration()

Once I invert “Output vector field_PythonInteractor” and apply it to “Output volume_PythonInteractor”, I should obtain the original image “Moving_img”: however, the result is not correct.
Then, I tried to perform the same steps (i.e. plastimatch b-spline deformable registration + inverse transform) from GUI and it worked as expected.
Thus, I am supposing that the vector field obtained from Python Interactor is incorrect.

You can dowload from here the bundle file with the following nodes:

  • Moving_img
  • Fixed_img
  • Output volume_GUI
  • Output vector field_GUI
  • Output volume_PythonInteractor

“Output vector field_PythonInteractor” is not included because I cannot save the file if it is in the scene: the error is

vtkITKTransformConverter::CreateITKTransformFromVTK failed: conversion of transform type vtkGridTransform is not supported.
WriteTransform failed: cannot to convert VTK transform to ITK transform

but you can get that variable by running the previous lines.

Furthermore, I find that the vector field from GUI contains a vtkOrientedGridTransform, while the one from Python Interactor includes a vtkGridTransform. I read about the LPS/IJK/RAS problem but I did not figure out if it is the correct hint and, in case, how to impement it.

Do you have any suggestion?

Thanks in advance,
Luca

I believe the vtOrientedGrid should just be a vtkGrid with a vtkTransform

Slicer’s standard is RAS so the identityMatrixn matches that directions, first column is R and so on, forth column is the origin, forth row is 0s, but the last item can be a 1 if you want to transformna poikt, 0 otherwise for a vector

Hopenit helps

Thank you Mauro for the hint. However, I know basics of orientation matrices and reference systems but I cannot find out which matrix/matrices should I use in this case. For sure, It was my fault but I was not able to reach a solution yet.

Any other suggestions?