mitk.IOUtil#

class mitk.IOUtil#

Bases: pybind11_object

File I/O for MITK objects.

IOUtil is a namespace-style class with static methods for loading and saving the data types currently bound in Python (Image and MultiLabelSegmentation). The wheel bundles auto-load modules for the common image formats (NRRD, NIfTI, MetaImage, DICOM, and others); no further setup is required.

The Image constructor and the shortcut methods Image.load / Image.save ultimately call into this class.

__init__(*args, **kwargs)#

Methods

__init__(*args, **kwargs)

load(path[, reader_preferences, ...])

Load a file and return a list of bound objects.

save(data, path)

Save an MITK object to disk.

static load(path: os.PathLike | str | bytes, reader_preferences: collections.abc.Sequence[str] | None = None, reader_blacklist: collections.abc.Sequence[str] | None = None) list#

Load a file and return a list of bound objects.

Each element of the returned list is either an Image or a MultiLabelSegmentation, depending on what the MITK I/O system chose to produce. BaseData subclasses that are not yet exposed to Python are silently skipped.

Reader selection can be steered with reader_preferences (preferred reader description strings) and reader_blacklist (readers to skip). When either is provided, a PreferenceListReaderOptionsFunctor is built and passed to the underlying C++ loader.

Parameters:
  • path – Path to the file or directory to load. Accepts str, pathlib.Path, or any object with a __fspath__ method. DICOM series accept a directory path.

  • reader_preferences – Optional list of reader description strings to prefer.

  • reader_blacklist – Optional list of reader description strings to skip.

Returns:

A list of loaded objects (possibly empty).

Examples

>>> [img] = mitk.IOUtil.load("input.nrrd")
>>> objs = mitk.IOUtil.load("DICOMSeries/")
static save(data: object, path: os.PathLike | str | bytes) None#

Save an MITK object to disk.

The output format is inferred from the file extension.

Parameters:
  • data – An Image or MultiLabelSegmentation.

  • path – Output file path. Accepts str, pathlib.Path, or any object with a __fspath__ method.

Raises: