Skip to content

Commit a14d51a

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

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
@@ -183,6 +183,7 @@ def resample_by_spacing(in_file, zooms, order=3, clip=True):
183183
if clip:
184184
resampled = np.clip(resampled, a_min=data.min(), a_max=data.max())
185185

186+
hdr.set_zooms(zooms)
186187
# Prepare output x-forms
187188
sform, scode = hdr.get_sform(coded=True)
188189
qform, qcode = hdr.get_qform(coded=True)
@@ -198,6 +199,9 @@ def resample_by_spacing(in_file, zooms, order=3, clip=True):
198199
hdr.set_sform(new_affine.dot(np.linalg.inv(affine).dot(sform)), code=int(scode))
199200
if qcode != 0:
200201
hdr.set_qform(new_affine.dot(np.linalg.inv(affine).dot(qform)), code=int(qcode))
202+
if (scode, qcode) == (0, 0):
203+
hdr.set_qform(new_affine, code=1)
204+
hdr.set_sform(new_affine, code=1)
201205

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

0 commit comments

Comments
 (0)