Skip to content

Commit 6fc3af4

Browse files
committed
BF+TEST: float affine truncation in make_xyz_image
Satra noticed via Alexis' realign4d that image voxel sizes were being truncated to integers during make_xyz_image. Fix and test.
1 parent d6fed32 commit 6fc3af4

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

nipy/core/image/image_spaces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ def make_xyz_image(data, xyz_affine, world, metadata=None):
369369
world_cm = rsp.get_world_cs(world, N)
370370
voxel_cm = rsp.voxel_csm(N)
371371
if N > 3:
372-
affine = np.diag((1, 1, 1) + added_zooms + (1,))
372+
affine = np.diag((1., 1, 1) + added_zooms + (1,))
373373
affine[:3, :3] = xyz_affine[:3, :3]
374374
affine[:3, -1] = xyz_affine[:3, 3]
375375
else:

nipy/core/image/tests/test_image_spaces.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,9 @@ def test_make_xyz_image():
158158
assert_true(is_xyz_affable(img))
159159
# Need at least 3 dimensions in data
160160
assert_raises(ValueError, make_xyz_image, np.zeros((2,3)), aff, 'mni')
161+
# Check affines don't round / floor floating point
162+
aff = np.diag([2.1, 3, 4, 1])
163+
img = make_xyz_image(np.zeros((2, 3, 4)), aff, 'scanner')
164+
assert_array_equal(img.coordmap.affine, aff)
165+
img = make_xyz_image(np.zeros((2, 3, 4, 5)), aff, 'scanner')
166+
assert_array_equal(img.coordmap.affine, np.diag([2.1, 3, 4, 1, 1]))

0 commit comments

Comments
 (0)