Skip to content

Commit 9ab6f28

Browse files
committed
FIX: Reorient target images during unwarping to match coefficients
1 parent 5f82c3b commit 9ab6f28

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

sdcflows/interfaces/bspline.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,18 +622,24 @@ def _b0_resampler(in_file, coeffs, pe, ro, hmc_xfm=None, unwarp=None, newpath=No
622622
# Load distorted image
623623
distorted_img = nb.load(in_file)
624624

625-
if unwarp.fit(distorted_img):
625+
# Reorient to RAS to ensure consistency with coefficients
626+
# The b-spline weight matrix is sensitive to orientation
627+
ornt = nb.io_orientation(distorted_img.affine)
628+
distorted_ras = distorted_img.as_reoriented(ornt)
629+
pe_ras = reorient_pedir(pe, ornt)
630+
631+
if unwarp.fit(distorted_ras):
626632
unwarp.mapped.to_filename(retval[2])
627633
else:
628634
retval[2] = None
629635

630636
# Unwarp
631-
unwarped_img = unwarp.apply(distorted_img, ro_time=ro, pe_dir=pe)
637+
unwarped_img = unwarp.apply(distorted_ras, ro_time=ro, pe_dir=pe_ras)
632638

633639
# Write out to disk
634640
unwarped_img.to_filename(retval[0])
635641

636642
# Store the corresponding spatial transformation
637-
unwarp.to_displacements(ro_time=ro, pe_dir=pe).to_filename(retval[1])
643+
unwarp.to_displacements(ro_time=ro, pe_dir=pe_ras).to_filename(retval[1])
638644

639645
return retval

0 commit comments

Comments
 (0)