# VTK to simpleITK conversion in Python

**URL:** <https://discourse.itk.org/t/vtk-to-simpleitk-conversion-in-python/4028>\
**Category:** Beginner Questions\
**Created:** [April 12, 2021, 7:23pm UTC](https://discourse.itk.org/t/vtk-to-simpleitk-conversion-in-python/4028 "2021-04-12T19:23:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrea\_Borsic](https://discourse.itk.org/user_avatar/discourse.itk.org/andrea_borsic/32/2016_2.png) [@Andrea\_Borsic](https://discourse.itk.org/u/Andrea_Borsic)\
**Post date:** [April 12, 2021, 7:23pm UTC](https://discourse.itk.org/t/vtk-to-simpleitk-conversion-in-python/4028/1 "2021-04-12T19:23:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dchen](https://discourse.itk.org/user_avatar/discourse.itk.org/dchen/32/34_2.png) [@dchen](https://discourse.itk.org/u/dchen)\
**Post date:** [April 13, 2021, 1:10am UTC](https://discourse.itk.org/t/vtk-to-simpleitk-conversion-in-python/4028/2 "2021-04-13T01:10:23Z")

</div>

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

> **[dave3d/dicom2stl](https://github.com/dave3d/dicom2stl/tree/main/utils)**
>
> main/utils

The files are sitk2vtk.py and vtk2sitk.py.

---

<div class="post-metadata">

**Author:** ![Andrea\_Borsic](https://discourse.itk.org/user_avatar/discourse.itk.org/andrea_borsic/32/2016_2.png) [@Andrea\_Borsic](https://discourse.itk.org/u/Andrea_Borsic)\
**Post date:** [April 13, 2021, 2:18am UTC](https://discourse.itk.org/t/vtk-to-simpleitk-conversion-in-python/4028/3 "2021-04-13T02:18:39Z")

</div>

Hi Dave,

Thank you for sharing !

Best Regards,

Andrea

---

<div class="post-metadata">

**Author:** ![lassoan](https://discourse.itk.org/user_avatar/discourse.itk.org/lassoan/32/27_2.png) [@lassoan](https://discourse.itk.org/u/lassoan)\
**Post date:** [April 15, 2021, 6:39pm UTC](https://discourse.itk.org/t/vtk-to-simpleitk-conversion-in-python/4028/4 "2021-04-15T18:39:15Z")

</div>

@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).

---

<div class="post-metadata">

**Author:** ![dchen](https://discourse.itk.org/user_avatar/discourse.itk.org/dchen/32/34_2.png) [@dchen](https://discourse.itk.org/u/dchen)\
**Post date:** [April 15, 2021, 6:49pm UTC](https://discourse.itk.org/t/vtk-to-simpleitk-conversion-in-python/4028/5 "2021-04-15T18:49:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dchen](https://discourse.itk.org/user_avatar/discourse.itk.org/dchen/32/34_2.png) [@dchen](https://discourse.itk.org/u/dchen)\
**Post date:** [April 19, 2021, 4:28pm UTC](https://discourse.itk.org/t/vtk-to-simpleitk-conversion-in-python/4028/6 "2021-04-19T16:28:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dchen](https://discourse.itk.org/user_avatar/discourse.itk.org/dchen/32/34_2.png) [@dchen](https://discourse.itk.org/u/dchen)\
**Post date:** [July 3, 2023, 8:35pm UTC](https://discourse.itk.org/t/vtk-to-simpleitk-conversion-in-python/4028/7 "2023-07-03T20:35:23Z")

</div>

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.

> **[GitHub - SimpleITK/SimpleITKUtilities: A collection of utilities and...](https://github.com/SimpleITK/SimpleITKUtilities)**
>
> A collection of utilities and integration tools to enhance SimpleITK in Python. - GitHub - SimpleITK/SimpleITKUtilities: A collection of utilities and integration tools to enhance SimpleITK in Python.

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