Skip to content

To

To

Bases: IntensityTransform

Convert the image tensor data type and/or device.

This transform is a thin wrapper around torch.Tensor.to().

Parameters:

Name Type Description Default
target str | dtype | device

First argument to torch.Tensor.to().

required
to_kwargs dict[str, Any] | None

Additional keyword arguments to pass to torch.Tensor.to().

None

Examples:

>>> import torchio as tio
>>> ct = tio.datasets.Slicer('CTChest').CT_chest
>>> clamp = tio.Clamp(out_min=-1000, out_max=1000)
>>> ct_clamped = clamp(ct)
>>> rescale = tio.RescaleIntensity(in_min_max=(-1000, 1000), out_min_max=(0, 255))
>>> ct_rescaled = rescale(ct_clamped)
>>> to_uint8 = tio.To(torch.uint8)
>>> ct_uint8 = to_uint8(ct_rescaled)

__call__(data)

__call__(data: Subject) -> Subject
__call__(data: ImageT) -> ImageT
__call__(data: torch.Tensor) -> torch.Tensor
__call__(data: np.ndarray) -> np.ndarray
__call__(data: sitk.Image) -> sitk.Image
__call__(data: dict[str, object]) -> dict[str, object]
__call__(data: nib.Nifti1Image) -> nib.Nifti1Image

Transform data and return a result of the same type.

Parameters:

Name Type Description Default
data TypeTransformInput

Instance of torchio.Subject, 4D torch.Tensor or numpy.ndarray with dimensions \((C, W, H, D)\), where \(C\) is the number of channels and \(W, H, D\) are the spatial dimensions. If the input is a tensor, the affine matrix will be set to identity. Other valid input types are a SimpleITK image, a torchio.Image, a NiBabel Nifti1 image or a dict. The output type is the same as the input type.

required

to_hydra_config()

Return a dictionary representation of the transform for Hydra instantiation.

arguments_are_dict()

Check if main arguments are dict.

Return True if the type of all attributes specified in the args_names have dict type.