# Plastimatch from Python Interactor returns incorrect vector field

**URL:** https://discourse.slicer.org/t/plastimatch-from-python-interactor-returns-incorrect-vector-field/23768
**Category:** Development
**Tags:** registration, transforms, slicerrt, python
**Created:** [June 8, 2022, 2:27pm UTC](https://discourse.slicer.org/t/plastimatch-from-python-interactor-returns-incorrect-vector-field/23768 "2022-06-08T14:27:45Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Luca](https://avatars.discourse-cdn.com/v4/letter/l/51bf81/32.png) [@Luca](https://discourse.slicer.org/u/Luca)
#### Post date: [June 8, 2022, 2:27pm UTC](https://discourse.slicer.org/t/plastimatch-from-python-interactor-returns-incorrect-vector-field/23768/1 "2022-06-08T14:27:45Z")

</div>

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](https://groups.google.com/g/plastimatch/c/Muc24iX3X3I/m/PQoelmpkDAAJ), I was able to write these lines to perform it:

```auto
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](https://we.tl/t-Y0qfJUxkJq) 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

---

<div class="post-metadata">

### Author: ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)
#### Post date: [June 8, 2022, 2:38pm UTC](https://discourse.slicer.org/t/plastimatch-from-python-interactor-returns-incorrect-vector-field/23768/2 "2022-06-08T14:38:00Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Luca](https://avatars.discourse-cdn.com/v4/letter/l/51bf81/32.png) [@Luca](https://discourse.slicer.org/u/Luca)
#### Post date: [June 10, 2022, 4:12pm UTC](https://discourse.slicer.org/t/plastimatch-from-python-interactor-returns-incorrect-vector-field/23768/3 "2022-06-10T16:12:45Z")

</div>

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?
