Skip to content

Commit

Permalink
Ensure consistent NIfTI header information
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yw7 committed Aug 31, 2024
1 parent 1f60738 commit 96c0ca8
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions totalspineseg/utils/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 96c0ca8

Please sign in to comment.