TotalSegmentator icon indicating copy to clipboard operation
TotalSegmentator copied to clipboard

difference in nifti headers between CT files and label maps for training data

Open deepakri201 opened this issue 2 years ago • 2 comments

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, image and the label map: image 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

deepakri201 avatar Dec 04 '22 20:12 deepakri201

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.

wasserth avatar Dec 05 '22 10:12 wasserth

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)

ccosmin97 avatar Dec 05 '22 17:12 ccosmin97