deepali.utils.simpleitk.torch#

Auxiliary functions for conversion between SimpleITK and PyTorch.

Module Contents#

Functions#

image_from_tensor(→ SimpleITK.Image)

Create SimpleITK.Image from image data tensor.

tensor_from_image(→ torch.Tensor)

Create image data tensor from SimpleITK.Image.

image_from_tensor(data: torch.Tensor, origin: Optional[Sequence[float]] = None, spacing: Optional[Sequence[float]] = None, direction: Optional[Sequence[float]] = None) SimpleITK.Image[source]#

Create SimpleITK.Image from image data tensor.

Parameters
  • data – Image tensor of shape (C, ..., X).

  • origin – World coordinates of center of voxel with zero indices.

  • spacing – Voxel size in world units in each dimension.

  • direction – Flattened image orientation cosine matrix.

Returns

SimpleITK image.

tensor_from_image(image: SimpleITK.Image, dtype: Optional[torch.dtype] = None, device: Optional[torch.device] = None) torch.Tensor[source]#

Create image data tensor from SimpleITK.Image.