Are numpy arrays supported in the object-oriented API?

Input in the form of numpy arrays works with the procedural API but doesn’t work with the object-oriented API (I get “itk.ElastixRegistrationMethod is not wrapped for input type None”).
Is that a known limitation or am I doing something wrong?

(I need to switch to the object-oriented API to do multi-image registration, which is only supported by the object-oriented API)

Code sample:

import imageio
import itk
import numpy as np

fixed = imageio.imread('CT_2D_head_fixed.mha')
fixed = np.asarray(fixed).astype(np.float32)

moving = imageio.imread('CT_2D_head_moving.mha')
moving = np.asarray(moving).astype(np.float32)

if False:
    # procedural interface
    registered, parameters = itk.elastix_registration_method(fixed, moving)
else:
    parameter_object = itk.ParameterObject.New()
    default_rigid_parameter_map = parameter_object.GetDefaultParameterMap('rigid')
    parameter_object.AddParameterMap(default_rigid_parameter_map)

    # Load Elastix Image Filter Object
    elastix_object = itk.ElastixRegistrationMethod.New(fixed, moving)
    # elastix_object.SetFixedImage(fixed_image)
    # elastix_object.SetMovingImage(moving_image)
    elastix_object.SetParameterObject(parameter_object)

    # Set additional options
    elastix_object.SetLogToConsole(False)

    # Update filter object (required)
    elastix_object.UpdateLargestPossibleRegion()

    # Results of Registration
    result_image = elastix_object.GetOutput()
    result_transform_parameters = elastix_object.GetTransformParameterObject()

If you move these two lines
fixed = np.asarray(fixed).astype(np.float32)
moving = np.asarray(moving).astype(np.float32)
into # procedural interface, it should work.

Yes, but then the Object-oriented interface would work with these “mha” images rather than numpy arrays. These filenames in my code snippet are placeholders from the documentation (to make reproduction simpler), my actual images are .png (which I convert to numpy arrays).

Then use ITK/numpy conversion functions, as per the documentation, and pass proper ITK images to ITK object interface.

1 Like

Thank you, that was precisely what I needed!