# Different points after conversion from SITK image to VTK Image

**URL:** https://discourse.vtk.org/t/different-points-after-conversion-from-sitk-image-to-vtk-image/14122
**Category:** Support
**Tags:** python
**Created:** [June 26, 2024, 6:36pm UTC](https://discourse.vtk.org/t/different-points-after-conversion-from-sitk-image-to-vtk-image/14122 "2024-06-26T18:36:43Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![bkusuma](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/96bed5/32.png) [@bkusuma](https://discourse.vtk.org/u/bkusuma)
#### Post date: [June 26, 2024, 6:36pm UTC](https://discourse.vtk.org/t/different-points-after-conversion-from-sitk-image-to-vtk-image/14122/1 "2024-06-26T18:36:44Z")

</div>

I am trying to convert a SITK Image with its corresponding spacing, origin, and direction metadata into a VTK Image, with a conversion to a numpy array in between.

However, when I try to grab a point within the VTK Image ( for reference, ( 0, 0, 0 ) ), I am finding a discrepancy of where that point is located. Is there something that I’m not doing properly when converting to the VTK Image?

```auto
image = vtkImageData()
image.SetDimensions( sitkDimensions )
image.SetSpacing( sitkSpacing )
image.SetDirectionMatrix( sitkDirectionMatrix )
image.SetOrigin( sitkOrigin )
image.GetPointData().SetScalars( numpy_to_vtk( array.ravel() ) )
image.Modified()

```

When I print the spacing, origin, and direction matrix, they are the same between SITK and VTK, so I am really confused as to where I went wrong.

---

<div class="post-metadata">

### Author: ![rexthor](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rexthor/32/6481_2.png) [@rexthor](https://discourse.vtk.org/u/rexthor)
#### Post date: [June 26, 2024, 8:30pm UTC](https://discourse.vtk.org/t/different-points-after-conversion-from-sitk-image-to-vtk-image/14122/2 "2024-06-26T20:30:30Z")

</div>

Hello! Welcome to the support forum. I think you might have set the point data incorrectly. Try this instead:

```python
image.GetPointData().AddArray(numpy_to_vtk(array))
# If you have only one data array in the image, this next step is NOT NECESSARY.
image.GetPointData().SetActiveScalars("your array name here")

```

---

<div class="post-metadata">

### Author: ![bkusuma](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/96bed5/32.png) [@bkusuma](https://discourse.vtk.org/u/bkusuma)
#### Post date: [June 28, 2024, 12:11pm UTC](https://discourse.vtk.org/t/different-points-after-conversion-from-sitk-image-to-vtk-image/14122/3 "2024-06-28T12:11:25Z")

</div>

Hi, when I tried to do `image.GetPointData().AddArray( numpy_to_vtk( array ) )`, it gives me a Segmentation Fault. Is there a step that I forgot?

---

<div class="post-metadata">

### Author: ![rexthor](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rexthor/32/6481_2.png) [@rexthor](https://discourse.vtk.org/u/rexthor)
#### Post date: [June 28, 2024, 1:42pm UTC](https://discourse.vtk.org/t/different-points-after-conversion-from-sitk-image-to-vtk-image/14122/4 "2024-06-28T13:42:55Z")

</div>

Here’s a trivial example on my system:

```python
from vtkmodules.vtkCommonDataModel import vtkImageData
from vtk.util.numpy_support import numpy_to_vtk
import numpy as np

img = vtkImageData()
img.SetDimensions(2, 2, 2)
img.SetSpacing(1, 1, 1)

# Just some data I made up to store:
NUM_POINTS = img.GetNumberOfPoints()
data = np.arange(NUM_POINTS)

img.GetPointData().AddArray(numpy_to_vtk(data))

```
