From 96c0ca8258e0640b6e5da7efd9a41a633817bcae Mon Sep 17 00:00:00 2001 From: Yehuda Warszawer <36595323+yw7@users.noreply.github.com> Date: Sat, 31 Aug 2024 03:21:12 +0300 Subject: [PATCH] Ensure consistent NIfTI header information Double setting of qform to avoid header pixdim inconsistencies. This change prevents potential issues arising from subsequent image edits, ensuring reliability in image resampling processes. --- totalspineseg/utils/resample.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/totalspineseg/utils/resample.py b/totalspineseg/utils/resample.py index 48837b2..8fd51d3 100644 --- a/totalspineseg/utils/resample.py +++ b/totalspineseg/utils/resample.py @@ -241,6 +241,11 @@ def resample( output_image_data = subject.image.data.numpy()[0, ...].astype(np.float64) output_image = nib.Nifti1Image(output_image_data, subject.image.affine, image.header) + # Set qform twice to ensure consistent header information + # This addresses an issue where the second call to set_qform may alter output_image.header['pixdim'] + # Applying it here prevents inconsistencies that could arise from later image edits + output_image.set_qform(output_image.affine) + output_image.set_qform(output_image.affine) return output_image