Skip to content

Commit 1b1958a

Browse files
committed
fix: does AFNI use the translation part of WARPDRIVE_FOR?
1 parent da00997 commit 1b1958a

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

nitransforms/io/afni.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,9 @@ def _afni_to_oblique(oblique, plumb, inverse=False):
162162
163163
"""
164164
R = np.linalg.inv(plumb[:3, :3]).dot(oblique[:3, :3])
165-
origin = oblique[:3, 3] - R.dot(oblique[:3, 3])
166-
return from_matvec(R, origin) * AFNI_SIGNS
165+
# origin = oblique[:3, 3] - R.dot(oblique[:3, 3])
166+
origin = np.zeros(3)
167+
return from_matvec(R, origin) # * AFNI_SIGNS
167168

168169

169170
def _ras2afni(ras, moving=None, reference=None, inverse=False):
@@ -175,6 +176,7 @@ def _ras2afni(ras, moving=None, reference=None, inverse=False):
175176
onto oblique (AFNI's ``WARPDRIVE_MATVEC_INV_000000``);
176177
if ``True``, return the matrix to rotate oblique onto
177178
plumb (AFNI's ``WARPDRIVE_MATVEC_FOR_000000``).
179+
178180
"""
179181
ras = ras.copy()
180182
pre = LPS.copy()
@@ -183,17 +185,18 @@ def _ras2afni(ras, moving=None, reference=None, inverse=False):
183185
warnings.warn('Reference affine axes are oblique.')
184186
M = reference.affine
185187
plumb = shape_zoom_affine(reference.shape, voxel_sizes(M))
186-
pre = pre.dot(_afni_to_oblique(M, plumb))
187-
if inverse is True:
188-
pre = np.linalg.inv(pre)
188+
pre = _afni_to_oblique(M, plumb)
189+
pre = pre.dot(LPS)
189190

190191
if moving is not None and _is_oblique(moving.affine):
191192
warnings.warn('Moving affine axes are oblique.')
192193
M = moving.affine
193194
plumb = shape_zoom_affine(moving.shape, voxel_sizes(M))
194195
post = post.dot(_afni_to_oblique(M, plumb))
195-
if inverse is False:
196-
post = np.linalg.inv(post)
196+
197+
if inverse:
198+
ras = np.swapaxes(
199+
pre.dot(np.linalg.inv(ras).dot(post)), 0, 1).T
197200

198201
# Combine oblique/deoblique matrices into RAS+ matrix
199202
return np.swapaxes(post.dot(ras.dot(pre)), 0, 1).T

nitransforms/tests/test_linear.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ def test_linear_save(tmpdir, data_path, get_testdata, image_orientation, sw_tool
5757
assert_affines_by_filename(xfm_fname1, xfm_fname2)
5858

5959

60-
@pytest.mark.parametrize('image_orientation', [
61-
'RAS', 'LAS', 'LPS', 'oblique',
62-
])
60+
@pytest.mark.parametrize('image_orientation', ['RAS', 'LAS', 'LPS', 'oblique'])
6361
@pytest.mark.parametrize('sw_tool', ['itk', 'fsl', 'afni'])
6462
def test_apply_linear_transform(
6563
tmpdir,

0 commit comments

Comments
 (0)