@@ -162,8 +162,9 @@ def _afni_to_oblique(oblique, plumb, inverse=False):
162
162
163
163
"""
164
164
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
167
168
168
169
169
170
def _ras2afni (ras , moving = None , reference = None , inverse = False ):
@@ -175,6 +176,7 @@ def _ras2afni(ras, moving=None, reference=None, inverse=False):
175
176
onto oblique (AFNI's ``WARPDRIVE_MATVEC_INV_000000``);
176
177
if ``True``, return the matrix to rotate oblique onto
177
178
plumb (AFNI's ``WARPDRIVE_MATVEC_FOR_000000``).
179
+
178
180
"""
179
181
ras = ras .copy ()
180
182
pre = LPS .copy ()
@@ -183,17 +185,18 @@ def _ras2afni(ras, moving=None, reference=None, inverse=False):
183
185
warnings .warn ('Reference affine axes are oblique.' )
184
186
M = reference .affine
185
187
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 )
189
190
190
191
if moving is not None and _is_oblique (moving .affine ):
191
192
warnings .warn ('Moving affine axes are oblique.' )
192
193
M = moving .affine
193
194
plumb = shape_zoom_affine (moving .shape , voxel_sizes (M ))
194
195
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
197
200
198
201
# Combine oblique/deoblique matrices into RAS+ matrix
199
202
return np .swapaxes (post .dot (ras .dot (pre )), 0 , 1 ).T
0 commit comments