Data transforms#

The transforms in this Python package generally built on the core library. The classes defined by these modules can be used, for example, in a data input pipeline which is attached to a data loader. The spatial transforms defined in the spatial library, on the other hand, can be used to implement either a traditional or machine learning based co-registration approach.

Note that data transforms are included in the data library to avoid cyclical imports between modules defining specialized tensor types such as data.image and datasets defined in data.dataset, which also use these transforms to read and preprocess the loaded data.

Following torchvision’s lead, data transform classes which operate on tensors and do not require lambda functions are derived from torch.nn.Module. Use torch.nn.Sequential to compose transforms instead of torchvision.transforms.Compose. This is to support torch.jit.script.

See also: pytorch/vision.

Item transforms#

ItemTransform

Transform only specified item/field of dict, named tuple, tuple, list, or dataclass.

ItemwiseTransform

Mix-in for data preprocessing and augmentation transforms.

Image transforms#

AvgPoolImage

Downsample image using average pooling.

CastImage

Cast image data to specified type.

CenterCropImage

Crop image to specified maximum output size.

CenterPadImage

Pad image to specified minimum output size.

ClampImage

Clamp image intensities to specified minimum and/or maximum value.

ImageToTensor

Convert image to data tensor.

NarrowImage

Return image with data tensor narrowed along specified dimension.

NormalizeImage

Normalize and clamp image intensities in [min, max].

ReadImage

Read image data from file path.

ResampleImage

Resample image to specified voxel size.

RescaleImage

Linearly rescale image data.

ResizeImage

Resample image to specified image size.

Image transforms can also be instantiated based on a configuration, e.g., in YAML format:

image_transforms(config: ImageTransformConfig, key: Optional[str] = None)[source]

Create image data transforms from configuration.

A sequence of image transforms can be configured using names:

Parameters can be passed to the data transform as keyword arguments, e.g.,

transforms:
- read: {dtype: float32}
- avgpool: {kernel_size: 2}
- normalize: {min: 0, max: 255, mode: unit}