Python, NumPy interopΒΆ
itkwasm
interface types, used in function calls, are standard Python dataclasses
. These interface types are composed of standard Python datatypes, dict
, list
, float
, int
, and NumPy arrays.
Convert from itkwasm
to dict
ΒΆ
To convert from an itkwasm
dataclass interface type to a Python dictionary, use asdict
from the Python standard library.
An example with itkwasm.Image
:
from itkwasm import Image
image = Image()
from dataclasses import asdict
image_dict = asdict(image)
Convert from dict
to itkwasm
ΒΆ
To convert back to an itkwasm
interface type, use the **
Python operator to expand the dictionary into keyword arguments for the dataclass constructor.
from itkwasm import Image
image = Image(**image_dict)