Converters

Converter registry – maps Python types to NRRD I/O operations.

Functions:

register_converter: Register a new ImageConverter for a custom type. find_image_converter: Look up the converter for a given object by type. find_converter_for_type: Reverse lookup – find converter that produces a target type.

Built-in converters (registered at import time):

NumpyConverter: numpy.ndarray (always available). SitkConverter: SimpleITK.Image (registered if SimpleITK is installed). MLArrayConverter: mlarray.MLArray (registered if mlarray is installed).

class mitk_workbench_remote.converters.ImageConverter(*args, **kwargs)

Bases: Protocol

Protocol for converting between external image types and Image.

can_handle(obj)

Return True if this converter can handle the given object.

Return type:

bool

extract_geometry(obj)

Extract spatial geometry (spacing, origin, direction) from the object.

Return type:

dict[str, Any]

extract_properties(obj)

Extract custom properties from the object.

Return type:

dict[str, Any]

to_ndarray(obj)

Convert the object’s pixel data to a numpy array.

Return type:

ndarray

to_nrrd_bytes(obj)

Serialize the object to NRRD bytes for upload.

Return type:

bytes

from_image(image)

Convert an Image to the target type.

Return type:

Any

property target_type: type | None

The type this converter produces via from_image, or None.

mitk_workbench_remote.converters.register_converter(converter)

Register a new ImageConverter.

Thread-safe. Converters should be registered before any concurrent image operations; registrations that race with lookups may not be visible immediately.

Return type:

None

mitk_workbench_remote.converters.find_image_converter(obj)

Find the first converter that can handle the given object.

Return type:

ImageConverter | None

mitk_workbench_remote.converters.find_converter_for_type(target_type)

Find a converter that produces the given target type via from_image.

Return type:

ImageConverter | None

Interop with the mitk package

MitkImageConverter is auto-registered whenever the mitk package is importable. It enables transparent use of mitk.Image objects with DataNode.get_data() / DataNode.set_data() and Image.to_mitk(). See Interop with the mitk package for the full guide.

class mitk_workbench_remote.converters._mitk.MitkImageConverter

Bases: object

Converter for mitk.Image objects (native MITK Python binding).

Auto-registered when the mitk package is importable. Provides round-trip fidelity for geometry (spacing, origin, direction) and pixel data. Properties are extracted via the binding’s get_property() coercion path (propertyToPythonValue) for known types, falling back to BaseProperty.to_json() for unknown types.

property target_type: type
can_handle(obj)
Return type:

bool

extract_geometry(obj)
Return type:

dict[str, Any]

extract_properties(obj)
Return type:

dict[str, Any]

to_ndarray(obj)
Return type:

ndarray

to_nrrd_bytes(obj)
Return type:

bytes

from_image(image)
Return type:

Image