Create random affine transformation (with values == -1, 0 or 1).
(ndim: int = 3, random_state: np.random.RandomState | None = None)
| 419 | |
| 420 | |
| 421 | def 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 | |
| 434 | def get_arange_img(size, dtype=np.float32, offset=0): |
no outgoing calls
no test coverage detected
searching dependent graphs…