# Convert VTK image to ITK image without itk-vtkglue

**URL:** https://discourse.itk.org/t/convert-vtk-image-to-itk-image-without-itk-vtkglue/3009
**Category:** Beginner Questions
**Created:** [April 27, 2020, 8:07am UTC](https://discourse.itk.org/t/convert-vtk-image-to-itk-image-without-itk-vtkglue/3009 "2020-04-27T08:07:31Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![finetjul](https://discourse.itk.org/user_avatar/discourse.itk.org/finetjul/32/538_2.png) [@finetjul](https://discourse.itk.org/u/finetjul)
#### Post date: [April 27, 2020, 8:07am UTC](https://discourse.itk.org/t/convert-vtk-image-to-itk-image-without-itk-vtkglue/3009/1 "2020-04-27T08:07:31Z")

</div>

How can I convert a VTK image into an ITK image without itk-vtkglue in Python ? (see [current issue](https://github.com/InsightSoftwareConsortium/ITK/issues/1787))

Is there a solution as simple as converting from ITK to VTK ?

```auto
        data = itk.GetArrayViewFromImage(myITKImage).tostring()

        dataImporter = vtk.vtkImageImport()
        dataImporter.CopyImportVoidPointer(data, len(data))
        dataImporter.SetDataExtent(volumeExtent)
        dataImporter.SetWholeExtent(volumeExtent)
        dataImporter.SetDataOrigin(volumeOrigin)
        dataImporter.SetDataScalarType(volumeDataType)
        dataImporter.SetDataSpacing(spacing)
        dataImporter.SetNumberOfScalarComponents(volumeComponents)
        dataImporter.Update()  

```

Thanks,  
Julien.

---

<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 27, 2020, 1:28pm UTC](https://discourse.itk.org/t/convert-vtk-image-to-itk-image-without-itk-vtkglue/3009/2 "2020-04-27T13:28:26Z")

</div>

There’s a corresponding function `itk.GetImageViewFromArray` that converts a numpy array to an ITK image. Here’s a blog post about that:

> **[Convert ITK Data Structures to NumPy Arrays - Kitware Blog](https://blog.kitware.com/convert-itk-data-structures-to-numpy-arrays/)**
>
> We previously announced that the ITK Python wrapping is now available in the Python Package Index (PyPI) \[1\]. Starting to develop Python scripts using ITK ... Read More

To get from a VTK image to NumPy array you can use the `vtk_to_numpy` in `numpy_support`. Here’s stackoverflow thread describing that process:

> <https://stackoverflow.com/questions/25230541/how-to-convert-a-vtkimage-into-a-numpy-array>

I wrote a function that goes from VTK to SimpleITK that is essentially the same thing:

> <https://github.com/dave3d/dicom2stl/blob/master/utils/vtk2sitk.py>

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [April 28, 2020, 3:27pm UTC](https://discourse.itk.org/t/convert-vtk-image-to-itk-image-without-itk-vtkglue/3009/3 "2020-04-28T15:27:31Z")

</div>

Yes, NumPy can be used as a bridge.

Here is a patch to add `itk.vtk_image_from_image` and `itk.image_from_vtk_image`:

> <https://github.com/InsightSoftwareConsortium/ITK/pull/1790>

without _itk-vtkglue_.
