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

Function make_rand_affine

tests/test_utils.py:421–431  ·  view source on GitHub ↗

Create random affine transformation (with values == -1, 0 or 1).

(ndim: int = 3, random_state: np.random.RandomState | None = None)

Source from the content-addressed store, hash-verified

419
420
421def make_rand_affine(ndim: int = 3, random_state: np.random.RandomState | None = None):
422 """Create random affine transformation (with values == -1, 0 or 1)."""
423 rs = np.random.random.__self__ if random_state is None else random_state # type: ignore
424
425 vals = rs.choice([-1, 1], size=ndim)
426 positions = rs.choice(range(ndim), size=ndim, replace=False)
427 af = np.zeros([ndim + 1, ndim + 1])
428 af[ndim, ndim] = 1
429 for i, (v, p) in enumerate(zip(vals, positions)):
430 af[i, p] = v
431 return af
432
433
434def get_arange_img(size, dtype=np.float32, offset=0):

Callers 2

setUpMethod · 0.90
setUpClassMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…