SpatialObjectToImageFilter is missing SetReferenceImage method in ITK Python

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::SpatialObjectImageToImageFilterSetReferenceImage appears to be there as expected.

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

Do you have repro code for this?

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:

What do you think?

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

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

Sure thing!

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…

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'?

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

and wrapping specification looks normal:

1 Like