|
7 | 7 |
|
8 | 8 | from ..eulerangles import euler2mat
|
9 | 9 | from ..affines import (AffineError, apply_affine, append_diag, to_matvec,
|
10 |
| - from_matvec, dot_reduce, voxel_sizes, obliquity) |
| 10 | + from_matvec, dot_reduce, voxel_sizes, obliquity, rescale_affine) |
| 11 | +from ..orientations import aff2axcodes |
11 | 12 |
|
12 | 13 |
|
13 | 14 | import pytest
|
@@ -192,3 +193,22 @@ def test_obliquity():
|
192 | 193 | assert_almost_equal(obliquity(aligned), [0.0, 0.0, 0.0])
|
193 | 194 | assert_almost_equal(obliquity(oblique) * 180 / pi,
|
194 | 195 | [0.0810285, 5.1569949, 5.1569376])
|
| 196 | + |
| 197 | + |
| 198 | +def test_rescale_affine(): |
| 199 | + rng = np.random.RandomState(20200415) |
| 200 | + orig_shape = rng.randint(low=20, high=512, size=(3,)) |
| 201 | + orig_aff = np.eye(4) |
| 202 | + orig_aff[:3, :] = rng.normal(size=(3, 4)) |
| 203 | + orig_zooms = voxel_sizes(orig_aff) |
| 204 | + orig_axcodes = aff2axcodes(orig_aff) |
| 205 | + orig_centroid = apply_affine(orig_aff, (orig_shape - 1) // 2) |
| 206 | + |
| 207 | + for new_shape in (None, tuple(orig_shape), (256, 256, 256), (64, 64, 40)): |
| 208 | + for new_zooms in ((1, 1, 1), (2, 2, 3), (0.5, 0.5, 0.5)): |
| 209 | + new_aff = rescale_affine(orig_aff, orig_shape, new_zooms, new_shape) |
| 210 | + assert aff2axcodes(new_aff) == orig_axcodes |
| 211 | + if new_shape is None: |
| 212 | + new_shape = tuple(orig_shape) |
| 213 | + new_centroid = apply_affine(new_aff, (np.array(new_shape) - 1) // 2) |
| 214 | + assert_almost_equal(new_centroid, orig_centroid) |
0 commit comments