MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / create_translate

Function create_translate

monai/transforms/utils.py:1047–1073  ·  view source on GitHub ↗

create a translation matrix Args: spatial_dims: spatial rank shift: translate pixel/voxel for every spatial dim, defaults to 0. device: device to compute and store the output (when the backend is "torch"). backend: APIs to use, ``numpy`` or ``torch``.

(
    spatial_dims: int,
    shift: Sequence[float] | float,
    device: torch.device | None = None,
    backend=TransformBackends.NUMPY,
)

Source from the content-addressed store, hash-verified

1045
1046
1047def create_translate(
1048 spatial_dims: int,
1049 shift: Sequence[float] | float,
1050 device: torch.device | None = None,
1051 backend=TransformBackends.NUMPY,
1052) -> NdarrayOrTensor:
1053 """
1054 create a translation matrix
1055
1056 Args:
1057 spatial_dims: spatial rank
1058 shift: translate pixel/voxel for every spatial dim, defaults to 0.
1059 device: device to compute and store the output (when the backend is "torch").
1060 backend: APIs to use, ``numpy`` or ``torch``.
1061 """
1062 _backend = look_up_option(backend, TransformBackends)
1063 spatial_dims = int(spatial_dims)
1064 if _backend == TransformBackends.NUMPY:
1065 return _create_translate(spatial_dims=spatial_dims, shift=shift, eye_func=np.eye, array_func=np.asarray)
1066 if _backend == TransformBackends.TORCH:
1067 return _create_translate(
1068 spatial_dims=spatial_dims,
1069 shift=shift,
1070 eye_func=lambda x: torch.eye(torch.as_tensor(x), device=device), # type: ignore
1071 array_func=lambda x: torch.as_tensor(x, device=device),
1072 )
1073 raise ValueError(f"backend {backend} is not supported")
1074
1075
1076def _create_translate(

Callers 8

spatial_resampleFunction · 0.90
rotateFunction · 0.90
rotate90Function · 0.90
__call__Method · 0.90
compute_w_affineMethod · 0.90
pad_funcFunction · 0.90
crop_funcFunction · 0.90

Calls 3

look_up_optionFunction · 0.90
_create_translateFunction · 0.85
as_tensorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…