mitk.IOUtil#
- class mitk.IOUtil#
Bases:
pybind11_objectFile I/O for MITK objects.
IOUtilis a namespace-style class with static methods for loading and saving the data types currently bound in Python (ImageandMultiLabelSegmentation). The wheel bundles auto-load modules for the common image formats (NRRD, NIfTI, MetaImage, DICOM, and others); no further setup is required.The
Imageconstructor and the shortcut methodsImage.load/Image.saveultimately 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
Imageor aMultiLabelSegmentation, depending on what the MITK I/O system chose to produce.BaseDatasubclasses that are not yet exposed to Python are silently skipped.Reader selection can be steered with
reader_preferences(preferred reader description strings) andreader_blacklist(readers to skip). When either is provided, aPreferenceListReaderOptionsFunctoris 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
ImageorMultiLabelSegmentation.path – Output file path. Accepts
str,pathlib.Path, or any object with a__fspath__method.
- Raises:
TypeError – If
datais not a supported type.ValueError – If
datais null.