KeyError: 'ITKSmoothing' when initializing RegularStepGradientDescentOptimizerv4

Hi,
I have a fresh pip install of 5.1.1 and get this error when creating an ImageRegistrationMethodv4

 object:
    registration = itk.ImageRegistrationMethodv4.REGv4F3F3.New(FixedImage=fixed,
                                                               MovingImage=moving,
                                                               Metric=metric,
                                                               Optimizer=optimizer,
                                                               InitialTransform=identityTransform)

My metric is using raycastinterpolater as interpolater I saw another post from last year with the same error message for the SiddonJacobRayCastInterpolateImageFunction filter but there were no replies to that post.
Any ideas appreciated!
Thanks!
Soren

Traceback (most recent call last):
  File "/home/sorenc/CODE/reg/reg_sandbox.py", line 45, in <module>
    register(itk_image,dsa_itk_img,beam_location.tolist())
  File "/register.py", line 14, in register
    optimizer = itk.RegularStepGradientDescentOptimizerv4.New(
  File "/home/sorenc/.virtualenvs/sitk/lib/python3.6/site-packages/itkLazy.py", line 52, in __getattribute__
    itkBase.LoadModule(module, namespace)
  File "/home/sorenc/.virtualenvs/sitk/lib/python3.6/site-packages/itkBase.py", line 91, in LoadModule
    LoadModule(dep, namespace)
  File "/home/sorenc/.virtualenvs/sitk/lib/python3.6/site-packages/itkBase.py", line 91, in LoadModule
    LoadModule(dep, namespace)
  File "/home/sorenc/.virtualenvs/sitk/lib/python3.6/site-packages/itkBase.py", line 87, in LoadModule
    data = module_data[name]
KeyError: 'ITKSmoothing'

Does the error go away if you import ITK like this:

# disable lazy loading first and then import itk
import itkConfig
itkConfig.LazyLoading = False
import itk

Thank you Dzenanz!
Yes, that takes care of it.

Soren

1 Like

We can avoid the error and automatically get the correct filter type by omitting .REGv4F3F3 (tested with itk-5.2rc3):

registration = itk.ImageRegistrationMethodv4.New(fixed_image=fixed_image,
    moving_image=moving_image,
    metric=metric,
    optimizer=optimizer,
    initial_transform=identityTransform)

A full example with the modern, Pythonic itk style:

1 Like

Thanks!
I upgraded to 5.2 but I seem to still have issues with the types:
itk.version
‘5.2.0’
fixed_image
<itk.itkImagePython.itkImageF3; proxy of <Swig Object of type ‘itkImageF3 *’ at 0x7f15a6bbe3f0> >
moving_image
<itk.itkImagePython.itkImageF3; proxy of <Swig Object of type ‘itkImageF3 *’ at 0x7f15b8ed2f30> >
registration = itk.ImageRegistrationMethodv4.New(fixed_image=fixed_image,
moving_image=moving_image,)
TypeError: in method ‘itkImageRegistrationMethodv4REGv4F2F2_SetFixedImage’, argument 2 of type ‘itkImageF2 const *’
Additional information:
Wrong number or type of arguments for overloaded function ‘itkImageRegistrationMethodv4REGv4F2F2_SetFixedImage’.
Possible C/C++ prototypes are:
itkImageRegistrationMethodv4REGv4F2F2::SetFixedImage(itkImageF2 const *)
itkImageRegistrationMethodv4REGv4F2F2::SetFixedImage(unsigned long,itkImageF2 const *)

What code was used?

itkImageF3

itkImageF2

it appears that we are trying to use 3D images in a 2D image filter.