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

Function _create_shear

monai/transforms/utils.py:986–1012  ·  view source on GitHub ↗
(spatial_dims: int, coefs: Sequence[float] | float, eye_func=np.eye)

Source from the content-addressed store, hash-verified

984
985
986def _create_shear(spatial_dims: int, coefs: Sequence[float] | float, eye_func=np.eye) -> NdarrayOrTensor:
987 if spatial_dims == 2:
988 coefs = ensure_tuple_size(coefs, dim=2, pad_val=0.0)
989 rank = 3
990 shear_indices = [(0, 1, coefs[0]), (1, 0, coefs[1])]
991 elif spatial_dims == 3:
992 coefs = ensure_tuple_size(coefs, dim=6, pad_val=0.0)
993 rank = 4
994 shear_indices = [
995 (0, 1, coefs[0]),
996 (0, 2, coefs[1]),
997 (1, 0, coefs[2]),
998 (1, 2, coefs[3]),
999 (2, 0, coefs[4]),
1000 (2, 1, coefs[5]),
1001 ]
1002 else:
1003 raise NotImplementedError("Currently only spatial_dims in [2, 3] are supported.")
1004 # Compose individual single-axis shear matrices so that the result is a
1005 # proper (area/volume-preserving) shear with determinant 1. Each elementary
1006 # shear is pre-multiplied, so the first coefficient is applied first.
1007 out = eye_func(rank)
1008 for i, j, c in shear_indices:
1009 s = eye_func(rank)
1010 s[i, j] = c
1011 out = s @ out
1012 return out # type: ignore
1013
1014
1015def create_scale(

Callers 1

create_shearFunction · 0.85

Calls 1

ensure_tuple_sizeFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…