VTK to simpleITK conversion in Python

Hello All,

Does anyone has any tip or code snippet for converting a vtk image to simpleITK and vice-versa in memory using python?

Thanks in advance for any tip / advice.

Best Regards,

Andrea

Yeah, I wrote a couple routines to convert images back and forth. You can see them here:

The files are sitk2vtk.py and vtk2sitk.py.

1 Like

Hi Dave,

Thank you for sharing !

Best Regards,

Andrea

1 Like

@dchen thanks for sharing these scripts. Please add copying of the axis directions as well, to make sure no information is lost during conversion. You can add a warning message for the case when you convert an ITK image that has non-trivial directions and VTK < 9 is used (vtkImageData prior to VTK9 did not have directions field).

I can do that. Yeah, I hadn’t really updated it for VTK 9.

1 Like

FYI, I have updated the code to set/get the direction matrix for vtkImageData in VTK version 9.

1 Like