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.

2 Likes

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.

2 Likes

Updating for anyone that may find this thread: We have created a new repo, SimpleITKUtilities, that incorporates my SITK<->VTK functions plus other useful routines.

I’m going to remove those functions from my dicom2stl repo, since it now uses SimpleITKUtilities.

3 Likes