Skip to content

Commit

Permalink
make random inverse affine matrix (#1621)
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
  • Loading branch information
rijobro authored Feb 23, 2021
1 parent 3e7f53f commit a894adc
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,19 @@ def make_nifti_image(array, affine=None):
return image_name


def make_rand_affine(ndim: int = 3, random_state: Optional[np.random.RandomState] = None):
"""Create random affine transformation (with values == -1, 0 or 1)."""
rs = np.random if random_state is None else random_state

vals = rs.choice([-1, 1], size=ndim)
positions = rs.choice(range(ndim), size=ndim, replace=False)
af = np.zeros([ndim + 1, ndim + 1])
af[ndim, ndim] = 1
for i, (v, p) in enumerate(zip(vals, positions)):
af[i, p] = v
return af


class DistTestCase(unittest.TestCase):
"""
testcase without _outcome, so that it's picklable.
Expand Down

0 comments on commit a894adc

Please sign in to comment.