Skip to content

Commit cdbd778

Browse files
committed
fix: set new zooms in inherited header, set s/q-forms if both were zero-code
1 parent 682b9da commit cdbd778

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

niworkflows/utils/images.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ def resample_by_spacing(in_file, zooms, order=3, clip=True):
181181
if clip:
182182
resampled = np.clip(resampled, a_min=data.min(), a_max=data.max())
183183

184+
hdr.set_zooms(zooms)
184185
# Prepare output x-forms
185186
sform, scode = hdr.get_sform(coded=True)
186187
qform, qcode = hdr.get_qform(coded=True)
@@ -196,6 +197,9 @@ def resample_by_spacing(in_file, zooms, order=3, clip=True):
196197
hdr.set_sform(new_affine.dot(np.linalg.inv(affine).dot(sform)), code=int(scode))
197198
if qcode != 0:
198199
hdr.set_qform(new_affine.dot(np.linalg.inv(affine).dot(qform)), code=int(qcode))
200+
if (scode, qcode) == (0, 0):
201+
hdr.set_qform(new_affine, code=1)
202+
hdr.set_sform(new_affine, code=1)
199203

200204
# Create a new x-form affine, aligned with cardinal axes, 1mm3 and centered.
201205
return nb.Nifti1Image(resampled, new_affine, hdr)

0 commit comments

Comments
 (0)