TotalSegmentator
TotalSegmentator copied to clipboard
difference in nifti headers between CT files and label maps for training data
Hi Jakob,
I'm working with the training data you've provided, but noticed some potential issues in the NifTi headers. The sform parameters between the ct.nii.gz,
and the label map:
are slightly different.
I can still load your NifTi files in viewers such as Mango and ITK-Snap, but am having an issue (similar to before) with loading them into the latest stable version of Slicer. The ct.nii.gz file is unable to be loaded and results in errors. It looks like the label map can be loaded successfully as a volume.
Thank you!
Deepa
I would recommend the following solution: Overwrite the sform from the label map with the sform from the ct image. Thus they will be identical and Slicer should be happy. The alignment of the two is still fine since the difference is only minimal.
Overwriting the ct volume affine form with the one from the labelmaps, while preserving the ct volume header, allowed the ct file to be loaded into slicer :
import nibabel as nib
def ct_change_affine(input_volume, input_labelmap, output_path):
"""
input_volume : ct volume path
input_labelmap : labelmap path
output : new nifti image saved to output_path
"""
vol_image = nib.load(input_volume)
label_image = nib.load(input_labelmap)
new_image = vol_image.__class__(vol_image.dataobj[:], label_image.affine, vol_image.header)#overwrite affine only -- preserve header from ct volume
nib.save(new_image, output_path)