spinalcordtoolbox / disc-labeling-hourglass

Labeling of intervertebral discs using the Hourglass deep learning architecture.
GNU Lesser General Public License v2.1
1 stars 0 forks source link

How to generate new NIfTI file that has labels #5

Open jcohenadad opened 1 year ago

jcohenadad commented 1 year ago

example:

import nibabel as nib

nifti_volume = nib.load(FILE_REFERENCE)
# create new nibabel object
segmented_nifti = nib.Nifti1Image(NUMPY_ARRAY, nifti_volume.affine)
# save
nib.save(segmented_nifti, "prediction.nii.gz")
NathanMolinier commented 1 year ago

Where do we store the discs numbers ?

jcohenadad commented 1 year ago

Where do we store the discs numbers ?

In a file called *_seg_labeled_discs.nii.gz, see SCT tutorial.

NathanMolinier commented 1 year ago

Actually, I was already working with this file, but I figured out the disc number is stored as an intensity parameter in the numpy array.

nifti_labeled_discs = nib.load(FILE_REFERENCE)
print(nifti_labeled_discs.data[np.nonzero(nifti_labeled_discs.data)])

out --> array([10,  9,  8,  7,  6,  5,  3,  2,  1,  4], dtype=uint8)
jcohenadad commented 1 year ago

ah! yes indeed, sorry i didn't get your question in the first place