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

Function create_shear

monai/transforms/utils.py:947–983  ·  view source on GitHub ↗

create a shearing matrix Args: spatial_dims: spatial rank coefs: shearing factors, a tuple of 2 floats for 2D, a tuple of 6 floats for 3D). Individual single-axis shear matrices are composed (multiplied) in coefficient order so that the result is a p

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

Source from the content-addressed store, hash-verified

945
946
947def create_shear(
948 spatial_dims: int,
949 coefs: Sequence[float] | float,
950 device: torch.device | None = None,
951 backend=TransformBackends.NUMPY,
952) -> NdarrayOrTensor:
953 """
954 create a shearing matrix
955
956 Args:
957 spatial_dims: spatial rank
958 coefs: shearing factors, a tuple of 2 floats for 2D, a tuple of 6 floats for 3D).
959 Individual single-axis shear matrices are composed (multiplied) in
960 coefficient order so that the result is a proper shear with determinant 1.
961 For 2D with coefs ``(Sx, Sy)`` the composed matrix is::
962
963 [
964 [1.0, Sx, 0.0],
965 [Sy, 1.0 + Sx*Sy, 0.0],
966 [0.0, 0.0, 1.0],
967 ]
968
969 device: device to compute and store the output (when the backend is "torch").
970 backend: APIs to use, ``numpy`` or ``torch``.
971
972 Raises:
973 NotImplementedError: When ``spatial_dims`` is not one of [2, 3].
974
975 """
976 _backend = look_up_option(backend, TransformBackends)
977 if _backend == TransformBackends.NUMPY:
978 return _create_shear(spatial_dims=spatial_dims, coefs=coefs, eye_func=np.eye)
979 if _backend == TransformBackends.TORCH:
980 return _create_shear(
981 spatial_dims=spatial_dims, coefs=coefs, eye_func=lambda rank: torch.eye(rank, device=device)
982 )
983 raise ValueError(f"backend {backend} is not supported")
984
985
986def _create_shear(spatial_dims: int, coefs: Sequence[float] | float, eye_func=np.eye) -> NdarrayOrTensor:

Calls 2

look_up_optionFunction · 0.90
_create_shearFunction · 0.85

Used in the wild real call sites across dependent graphs

searching dependent graphs…