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#
Transform only specified item/field of dict, named tuple, tuple, list, or dataclass. |
|
Mix-in for data preprocessing and augmentation transforms. |
Image transforms#
Downsample image using average pooling. |
|
Cast image data to specified type. |
|
Crop image to specified maximum output size. |
|
Pad image to specified minimum output size. |
|
Clamp image intensities to specified minimum and/or maximum value. |
|
Convert image to data tensor. |
|
Return image with data tensor narrowed along specified dimension. |
|
Normalize and clamp image intensities in [min, max]. |
|
Read image data from file path. |
|
Resample image to specified voxel size. |
|
Linearly rescale image data. |
|
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:
avgpool
:AvgPoolImage
cast
:CastImage
centercrop
:CenterCropImage
centerpad
:CenterPadImage
clamp
:ClampImage
narrow
:NarrowImage
normalize
:NormalizeImage
read
:ReadImage
rescale
:RescaleImage
resample
:ResampleImage
resize
:ResizeImage
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}