create a 2D or 3D rotation matrix Args: spatial_dims: {``2``, ``3``} spatial rank radians: rotation radians when spatial_dims == 3, the `radians` sequence corresponds to rotation in the 1st, 2nd, and 3rd dim respectively. device: device to co
(
spatial_dims: int,
radians: Sequence[float] | float,
device: torch.device | None = None,
backend: str = TransformBackends.NUMPY,
)
| 860 | |
| 861 | |
| 862 | def create_rotate( |
| 863 | spatial_dims: int, |
| 864 | radians: Sequence[float] | float, |
| 865 | device: torch.device | None = None, |
| 866 | backend: str = TransformBackends.NUMPY, |
| 867 | ) -> NdarrayOrTensor: |
| 868 | """ |
| 869 | create a 2D or 3D rotation matrix |
| 870 | |
| 871 | Args: |
| 872 | spatial_dims: {``2``, ``3``} spatial rank |
| 873 | radians: rotation radians |
| 874 | when spatial_dims == 3, the `radians` sequence corresponds to |
| 875 | rotation in the 1st, 2nd, and 3rd dim respectively. |
| 876 | device: device to compute and store the output (when the backend is "torch"). |
| 877 | backend: APIs to use, ``numpy`` or ``torch``. |
| 878 | |
| 879 | Raises: |
| 880 | ValueError: When ``radians`` is empty. |
| 881 | ValueError: When ``spatial_dims`` is not one of [2, 3]. |
| 882 | |
| 883 | """ |
| 884 | _backend = look_up_option(backend, TransformBackends) |
| 885 | if _backend == TransformBackends.NUMPY: |
| 886 | return _create_rotate( |
| 887 | spatial_dims=spatial_dims, radians=radians, sin_func=np.sin, cos_func=np.cos, eye_func=np.eye |
| 888 | ) |
| 889 | if _backend == TransformBackends.TORCH: |
| 890 | return _create_rotate( |
| 891 | spatial_dims=spatial_dims, |
| 892 | radians=radians, |
| 893 | sin_func=lambda th: torch.sin(torch.as_tensor(th, dtype=torch.float32, device=device)), |
| 894 | cos_func=lambda th: torch.cos(torch.as_tensor(th, dtype=torch.float32, device=device)), |
| 895 | eye_func=lambda rank: torch.eye(rank, device=device), |
| 896 | ) |
| 897 | raise ValueError(f"backend {backend} is not supported") |
| 898 | |
| 899 | |
| 900 | def _create_rotate( |
searching dependent graphs…