# SpatialObjectToImageFilter is missing SetReferenceImage method in ITK Python

**URL:** <https://discourse.itk.org/t/spatialobjecttoimagefilter-is-missing-setreferenceimage-method-in-itk-python/7334>\
**Category:** Engineering\
**Created:** [December 1, 2024, 5:58am UTC](https://discourse.itk.org/t/spatialobjecttoimagefilter-is-missing-setreferenceimage-method-in-itk-python/7334 "2024-12-01T05:58:35Z")\
**Posts on this page:** 6\
**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:** [December 1, 2024, 5:58am UTC](https://discourse.itk.org/t/spatialobjecttoimagefilter-is-missing-setreferenceimage-method-in-itk-python/7334/1 "2024-12-01T05:58:35Z")

</div>

Hello Everyone.

While tinkering with ITK in Python, I’ve come across this curious circumstance:

`AttributeError: 'itkSpatialObjectToImageFilterSO2IUC2' object has no attribute 'SetReferenceImage'. Did you mean: 'GetReferenceCount'?`

To ensure my own sanity I did check Doxygen for `itk::SpatialObjectImageToImageFilter` — `SetReferenceImage` appears to be there as expected.

I’m wondering… is it a bug, a feature, or yet something else?

---

<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:** [December 2, 2024, 2:48pm UTC](https://discourse.itk.org/t/spatialobjecttoimagefilter-is-missing-setreferenceimage-method-in-itk-python/7334/2 "2024-12-02T14:48:28Z")

</div>

Do you have repro code for this?

---

<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:** [December 9, 2024, 12:34am UTC](https://discourse.itk.org/t/spatialobjecttoimagefilter-is-missing-setreferenceimage-method-in-itk-python/7334/3 "2024-12-09T00:34:28Z")

</div>

Hi Dženan,

No, I don’t have a repo for this one, but here’s all you’d want to see in this instance:

 ![image](https://discourse.itk.org/uploads/default/original/2X/d/ddd77842e8edcc5b8f88108cba91a7713830c776.png)

What do you think?

It seems other filters (in Python ITK) have this method available…

---

<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:** [December 9, 2024, 4:12pm UTC](https://discourse.itk.org/t/spatialobjecttoimagefilter-is-missing-setreferenceimage-method-in-itk-python/7334/4 "2024-12-09T16:12:01Z")

</div>

Can you copy this as a text/code instead of a screenshot?

---

<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:** [December 9, 2024, 11:47pm UTC](https://discourse.itk.org/t/spatialobjecttoimagefilter-is-missing-setreferenceimage-method-in-itk-python/7334/5 "2024-12-09T23:47:18Z")

</div>

Sure thing!

```auto
spo_filter = itk.SpatialObjectToImageFilter[itk.SpatialObject[2], itk.Image[itk.UC, 2]].New()
spo_filter.SetReferenceImage(img_moving) # Oddly enough, this method is missing.
# Instead, we can set size and spacing.
spo_filter.SetSize(img_moving.GetLargestPossibleRegion().GetSize())
spo_filter.SetSpacing(img_moving.GetSpacing())
spo_filter.SetUseObjectValue(True)
spo_filter.SetInput(b_balls)
spo_filter.Update()

```

and…

```auto
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2024.3\plugins\python-ce\helpers\pydev\pydevd.py", line 1570, in _exec
    pydev_imports.execfile(file, globals, locals) # execute the script
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\JetBrains\PyCharm 2024.3\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:\Users\cza14\GitRepos\HyoidTrack\PhantomAs2.py", line 38, in <module>
    spo_filter.SetReferenceImage(img_moving) # Oddly enough, this method is missing.
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'itkSpatialObjectToImageFilterSO2IUC2' object has no attribute 'SetReferenceImage'. Did you mean: 'GetReferenceCount'?

```

---

<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:** [December 10, 2024, 2:01pm UTC](https://discourse.itk.org/t/spatialobjecttoimagefilter-is-missing-setreferenceimage-method-in-itk-python/7334/6 "2024-12-10T14:01:56Z")

</div>

I confirm this. A quick analysis does not answer the question why this method is missing from wrapping. Method is defined:

> <https://github.com/InsightSoftwareConsortium/ITK/blob/v5.4.0/Modules/Core/SpatialObjects/include/itkSpatialObjectToImageFilter.h#L95-L106>

and wrapping specification looks normal:

> <https://github.com/InsightSoftwareConsortium/ITK/blob/v5.4.0/Modules/Core/SpatialObjects/wrapping/itkSpatialObjectToImageFilter.wrap>
