Skip to content

cornucopia.io

This module contains transforms that load data from disk.

ToTensorTransform

ToTensorTransform(ndim=None, dtype=None, device=None, **kwargs)

Bases: FinalTransform

Convert to Tensor (or to other dtype/device)

Parameters:

Name Type Description Default
ndim int

Number of spatial dimensions (default: guess from data)

None
dtype dtype

Returned data type (default: keep same)

None
device device

Returned device (default: keep same)

None

LoadTransform

LoadTransform(ndim=None, dtype=None, *, device=None, returns=None, append=False, include=None, exclude=None, **kwargs)

Bases: FinalTransform

Load data from disk.

Available loaders are: - BabelLoader: for medical image formats (nifti, mgz, minc, etc.) - TiffLoader: for TIFF files (including multi-page) - PillowLoader: for common image formats (png, jpg, etc., with optional rot90) - NumpyLoader: for .npy and .npz files (with optional field name)

Custom loaders can be added by registering them in cornucopia.utils.io.loaders.

Parameters:

Name Type Description Default
ndim int | None

Number of spatial dimensions (default: guess from file)

None
dtype dtype | str | None

Data type (default: guess from file)

None
device device | str | None

Device on which to load data (default: cpu)

None

Other Parameters:

Name Type Description
to_ras bool

Reorient data so that it has a RAS layout. Only used by `BabelLoader``.

rot90 bool

Rotate by 90 degrees in-plane. Only used by PillowLoader.

field str

Field to load from a npz file. Only used by NumpyLoader.