# Image Spacing Value Interactions in ITK Python Wrapping

**URL:** <https://discourse.itk.org/t/image-spacing-value-interactions-in-itk-python-wrapping/6707>\
**Category:** Uncategorized\
**Tags:** itk, python\
**Created:** [June 17, 2024, 11:49pm UTC](https://discourse.itk.org/t/image-spacing-value-interactions-in-itk-python-wrapping/6707 "2024-06-17T23:49:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![constantine](https://discourse.itk.org/user_avatar/discourse.itk.org/constantine/32/3915_2.png) [@constantine](https://discourse.itk.org/u/constantine)\
**Post date:** [June 17, 2024, 11:49pm UTC](https://discourse.itk.org/t/image-spacing-value-interactions-in-itk-python-wrapping/6707/1 "2024-06-17T23:49:42Z")

</div>

Dear, esteemed… Here’s an easy question for your consideration. Say, I’m having this sort of interaction with ITK in Python console:

```auto
oif = itk.SpatialObjectToImageFilter[itk.SpatialObject[2], itk.Image[itk.UC, 2]].New()
s = oif.GetSpacing()
print(s)
<Swig Object of type 'double *' at 0x0000025E090D45D0>

```

The spacing value returned by the filter seems utterly opaque. `dir(s)` or `help(s)` don’t get me much further either.

What is the way to examine the values for individual spacing dimensions in this case, please?

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [June 18, 2024, 1:07pm UTC](https://discourse.itk.org/t/image-spacing-value-interactions-in-itk-python-wrapping/6707/2 "2024-06-18T13:07:48Z")

</div>

@Stephen_Aylward might have something to say.

---

<div class="post-metadata">

**Author:** ![constantine](https://discourse.itk.org/user_avatar/discourse.itk.org/constantine/32/3915_2.png) [@constantine](https://discourse.itk.org/u/constantine)\
**Post date:** [June 19, 2024, 2:07am UTC](https://discourse.itk.org/t/image-spacing-value-interactions-in-itk-python-wrapping/6707/3 "2024-06-19T02:07:42Z")

</div>

Sounds promising. 🙂

---

<div class="post-metadata">

**Author:** ![Stephen\_Aylward](https://discourse.itk.org/user_avatar/discourse.itk.org/stephen_aylward/32/654_2.png) [@Stephen\_Aylward](https://discourse.itk.org/u/Stephen_Aylward)\
**Post date:** [June 19, 2024, 1:57pm UTC](https://discourse.itk.org/t/image-spacing-value-interactions-in-itk-python-wrapping/6707/4 "2024-06-19T13:57:15Z")

</div>

SpatialObjects are using an old ITK interface style (e.g., returning const double \*) that currently does not wrap well into python.

I’ve been going thru and updating the API to better support wrapping. I’ve added this to the list. I’m burried in a MetaIO issue right now, but I’ll get to this within a few weeks…or you could do it…

Would be great if you could create a new GetSpacing() function that returns a itk::Image::SpacingType variable (a vector). Since we’ll have a name collision with the old/existing function, the new function should probably be named GetSpacingVector(). Same update is needed for GetOrigin() → GetOriginVector() and perhaps others in that class.

Would be great if we could simply fix the interface and not worry about backward compatibility…but that’s a great way to make enemies… 🙂

---

<div class="post-metadata">

**Author:** ![constantine](https://discourse.itk.org/user_avatar/discourse.itk.org/constantine/32/3915_2.png) [@constantine](https://discourse.itk.org/u/constantine)\
**Post date:** [June 20, 2024, 5:24am UTC](https://discourse.itk.org/t/image-spacing-value-interactions-in-itk-python-wrapping/6707/5 "2024-06-20T05:24:28Z")

</div>

@Stephen_Aylward — thank you for the informative response. Yes, I suspected this was the case — those are to be Python-Wrapped yet.

I do like the idea of going ahead and wrapping those, and I’ll put this on my ToDo list. I did contribute a bit in the past, and would love to do this again in the near future.

First need to get some other (older) monkeys off my back though. 🐒

---

<div class="post-metadata">

**Author:** ![constantine](https://discourse.itk.org/user_avatar/discourse.itk.org/constantine/32/3915_2.png) [@constantine](https://discourse.itk.org/u/constantine)\
**Post date:** [June 24, 2024, 6:02am UTC](https://discourse.itk.org/t/image-spacing-value-interactions-in-itk-python-wrapping/6707/6 "2024-06-24T06:02:50Z")

</div>

@Stephen_Aylward — is there an official page somewhere on getting started with Python wrapping apart from this: [ITK/Python Wrapping - KitwarePublic](https://vtk.org/Wiki/ITK/Python_Wrapping)?

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [June 24, 2024, 1:29pm UTC](https://discourse.itk.org/t/image-spacing-value-interactions-in-itk-python-wrapping/6707/7 "2024-06-24T13:29:24Z")

</div>

Have you seen this?

> **[GitHub - InsightSoftwareConsortium/ITKPythonPackage: A setup script to...](https://github.com/InsightSoftwareConsortium/ITKPythonPackage#building-with-itkpythonpackage)**
>
> A setup script to generate ITK Python Wheels. Contribute to InsightSoftwareConsortium/ITKPythonPackage development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![constantine](https://discourse.itk.org/user_avatar/discourse.itk.org/constantine/32/3915_2.png) [@constantine](https://discourse.itk.org/u/constantine)\
**Post date:** [June 25, 2024, 12:51am UTC](https://discourse.itk.org/t/image-spacing-value-interactions-in-itk-python-wrapping/6707/8 "2024-06-25T00:51:50Z")

</div>

No, I haven’t. And yes, this is what I had in mind. Thank you!

---

<div class="post-metadata">

**Author:** ![Stephen\_Aylward](https://discourse.itk.org/user_avatar/discourse.itk.org/stephen_aylward/32/654_2.png) [@Stephen\_Aylward](https://discourse.itk.org/u/Stephen_Aylward)\
**Post date:** [July 12, 2024, 8:48pm UTC](https://discourse.itk.org/t/image-spacing-value-interactions-in-itk-python-wrapping/6707/9 "2024-07-12T20:48:49Z")

</div>

Hi,

Sorry for the delay. I’ve finally made a pull request to address this:

> <https://github.com/InsightSoftwareConsortium/ITK/pull/4775>
>
> itk::SpatialObjectToImageFilter provided GetSpacing() and GetOrigin() calls that… returned double \* objects. That return type is not well supported by SWIG for python wrapping.
> 
> Herein we provide GetSpacingVector() and GetOriginPoint() functions that return VectorType and PointType objects from the itk::Image class definition which are nicely wrapped by SWIG for python.
> 
> See: https://discourse.itk.org/t/image-spacing-value-interactions-in-itk-python-wrapping/6707
