Image

class mitk_workbench_remote.image.Image(data, *, spacing=None, origin=None, direction=None, properties=None)

Bases: object

Spatial image wrapper backed by a numpy array with spacing, origin, and direction.

Accepts any type handled by the converter registry (ndarray, SimpleITK.Image, mlarray.MLArray, file path). Pixel data conversion is lazy – the array is only materialized on first access to array.

Parameters:
  • data (Any) – Pixel data or an object convertible via the converter registry.

  • spacing (Sequence[float] | ndarray | None (default: None)) – Voxel spacing. Overrides converter-extracted values. Defaults to (1.0, ...) per dimension.

  • origin (Sequence[float] | ndarray | None (default: None)) – World-space origin. Overrides converter-extracted values. Defaults to (0.0, ...).

  • direction (Sequence[Any] | ndarray | None (default: None)) – Direction cosine matrix. Overrides converter-extracted values. Defaults to the identity matrix.

  • properties (dict[str, Any] | None (default: None)) – Data-scope properties dict. If None and a converter is used, properties are extracted from the source object.

property array: ndarray

Pixel data as a numpy array. Materialized lazily on first access.

property spacing: tuple[float, ...]

Voxel spacing per dimension.

property origin: tuple[float, ...]

World-space origin.

property direction: ndarray

Direction cosine matrix (ndim x ndim, float64).

property ndim: int

Number of spatial dimensions.

For vector or multichannel images, ndim is the number of spatial axes (e.g. 3 for a 3-D volume), while shape may have an additional channel axis. ndim equals len(spacing) and always matches the geometry, not the array rank.

property shape: tuple[int, ...]

Array shape.

property dtype: dtype[Any]

Array data type.

property properties: dict[str, Any]

Data-scope properties dict.

property property_keys: list[str]

List of property keys.

get_property(key)

Get a property by key.

Parameters:

key (str) – Property key.

Return type:

Any

Returns:

The property value, or None if not found.

set_property(key, value)

Set a property by key.

Parameters:
  • key (str) – Property key.

  • value (Any) – Property value.

Return type:

None

remove_property(key)

Remove a property by key.

Parameters:

key (str) – Property key.

Raises:

KeyError – If the key does not exist.

Return type:

None

to_numpy()

Return pixel data as a numpy array.

Return type:

ndarray

to_simpleitk()

Convert to a SimpleITK Image.

Raises:

ImportError – If SimpleITK is not installed.

Return type:

Any

to_mlarray()

Convert to an mlarray.MLArray.

Raises:

ImportError – If mlarray is not installed.

Return type:

Any

to_mitk()

Convert to a mitk.Image (native MITK Python binding).

Requires the mitk package. Geometry and pixel data are copied into the native image; properties are not transferred by this call (use DataNode.get_data() with include_properties=True or DataNode.set_data() with include_properties=True for metadata round-tripping).

Raises:

ImportError – If mitk is not installed.

Return type:

Any