# VTK vs ITK metadata (size, origin, spacing, direction)

**URL:** https://discourse.vtk.org/t/vtk-vs-itk-metadata-size-origin-spacing-direction/13041
**Category:** Support
**Tags:** python
**Created:** [January 9, 2024, 6:41pm UTC](https://discourse.vtk.org/t/vtk-vs-itk-metadata-size-origin-spacing-direction/13041 "2024-01-09T18:41:47Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![CharNamIII](https://discourse.vtk.org/user_avatar/discourse.vtk.org/charnamiii/32/7808_2.png) [@CharNamIII](https://discourse.vtk.org/u/CharNamIII)
#### Post date: [January 9, 2024, 6:41pm UTC](https://discourse.vtk.org/t/vtk-vs-itk-metadata-size-origin-spacing-direction/13041/1 "2024-01-09T18:41:47Z")

</div>

Hi all,

I’m trying to convert a polydata and place it in the same space as image X using the code below:

```auto
def polydata_to_imagedata(polydata, direction, dimensions, origin, spacing):
    dx, dy, dz = dimensions
    ox,oy,oz = origin
    sx, sy, sz = spacing

    image = vtk.vtkImageData()
    image.SetDirectionMatrix(direction)
    image.SetSpacing((sx, sy, sz))
    image.SetDimensions((dx, dy, dz))
    image.SetExtent(0, dx - 1, 0, dy - 1, 0, dz - 1)
    image.SetOrigin((ox, oy, oz))
    image.AllocateScalars(vtk.VTK_UNSIGNED_CHAR, 1)
    inval = 255
    outval = 0

    for i in range(image.GetNumberOfPoints()):
        image.GetPointData().GetScalars().SetTuple1(i, inval)

    pol2stenc = vtk.vtkPolyDataToImageStencil()
    pol2stenc.SetInputData(polydata)
    pol2stenc.SetOutputOrigin((ox, oy, oz))
    pol2stenc.SetOutputSpacing((sx, sy, sz))
    pol2stenc.Update()

    imgstenc = vtk.vtkImageStencil()
    imgstenc.SetInputData(image)
    imgstenc.SetStencilConnection(pol2stenc.GetOutputPort())
    imgstenc.ReverseStencilOff()
    imgstenc.SetBackgroundValue(outval)
    imgstenc.Update()

    return imgstenc.GetOutput()

```

However, when I do the same thing in ITK,

```auto
    filter= itk.TriangleMeshToBinaryImageFilter[MeshType, ImageType].New()
    filter.SetInput(mesh)
    filter.SetSize(size)
    filter.SetOrigin(origin)
    filter.SetSpacing(spacing)
    filter.SetDirection(direction)
    filter.Update()
    image= filter.GetOutput()

```

the outputs are different in that they both have the same size,origin,spacing,direction but are in different locations in space as (exported and) viewed in 3DSlicer. The correct mesh-image goes to ITK since when I put up the original image X, it is situated in the correct location. What am I missing in VTK?

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [January 9, 2024, 9:19pm UTC](https://discourse.vtk.org/t/vtk-vs-itk-metadata-size-origin-spacing-direction/13041/2 "2024-01-09T21:19:20Z")

</div>

Many filters in VTK (including vtkPolyDataToImageStencil) do not support “Direction”. It is not implemented yet.

---

<div class="post-metadata">

### Author: ![CharNamIII](https://discourse.vtk.org/user_avatar/discourse.vtk.org/charnamiii/32/7808_2.png) [@CharNamIII](https://discourse.vtk.org/u/CharNamIII)
#### Post date: [January 10, 2024, 2:48pm UTC](https://discourse.vtk.org/t/vtk-vs-itk-metadata-size-origin-spacing-direction/13041/3 "2024-01-10T14:48:29Z")

</div>

Thanks David,

That makes sense. Even the origins stop making sense due to the direction being absent. Will support be implemented anytime soon?
