Corrected fallback handling for sform and qform
@@ -38,13 +38,14 @@ def rectify_header_sform_qform(img_nii):
if not np.array_equal(norm_qform, np.asarray(pixdim)):
flag_qform_problem = True
- if not flag_qform_problem and not flag_sform_problem:
- return img_nii
-
- if flag_sform_problem and img_nii.get_header()['sform_code'] > 0:
- if not flag_qform_problem:
- img_nii.set_sform(np.copy(img_nii.get_qform()))
- return img_nii
+ if img_nii.get_header()['sform_code'] > 0 and not noflag_sform_problem:
+ pass
+ elif img_nii.get_header()['sform_code'] > 0 and flag_sform_problem and not flag_qform_problem:
+ img_nii.set_sform(np.copy(img_nii.get_qform())) # recover by copying the qform over the sform
+ elif img_nii.get_header()['sform_code'] == 0 and img_nii.get_header()['qform_code'] > 0 and not flag_qform_problem:
+ pass
+ elif img_nii.get_header()['sform_code'] == 0 and img_nii.get_header()['qform_code'] > 0 and flag_qform_problem and not flag_sform_problem:
+ img_nii.set_qform(np.copy(img_nii.get_sform())) # recover by copying the sform over the qform
else:
affine = img_nii.affine
pixdim = img_nii.header.get_zooms()
@@ -52,9 +53,6 @@ def rectify_header_sform_qform(img_nii):
img_nii.set_sform(new_affine)
img_nii.set_qform(new_affine)
return img_nii
- else:
- img_nii.set_qform(np.copy(img_nii.get_sform()))
- return img_nii
#### end of utilities for file headers
