Error in 'sct_process_segmentation': Slices and Vertebrae labels: CSA wrong

Dear experts,

I am processing my T2 images of spinal cord and when I run:

sct_process_segmentation -i ${base}-T2_SAG_seg.nii -vert 1:14 -perlevel 1 -o csa_test.csv

I obtain rare values in the csv (attached). However, when I run:

sct_process_segmentation -i ${base}-T2_SAG_seg.nii  -o csa.csv

I obtain correct values but without the vertebrae labels (attached also).

My image has 530 slices, however, the csv specify the C1 between the slices 140 and 146 (in the image it corresponds to T3).

What could be wrong in the process ???

Thank you in advance

csa.csv (195.0 KB)
csa_test.csv (6.7 KB)

Hi @Javier_Navas

There is likely a problem with your vertebral labeling. Notably, the fact that level T1 (=8) appears at slices 0:2;4;68:81 while level T2 appears at slices 3;52:67, with T5 in between (slices 8:21) does not make sense. Could you upload the files ${base}-T2_SAG_seg.nii and ${base}-T2_SAG_seg_labeled.nii files?

No problem, here you have both files

01-T2_SAG_resize_seg_labeled.nii.gz (199.7 KB) 01-T2_SAG_resize_seg.nii.gz (63.2 KB)

indeed, this looks pretty clean. So you likely have a problem in the warped template levels (which is used by sct_process_segmentation). Could you upload your file ./label/template/PAM50_levels.nii.gz?

Of course.

PAM50_levels.nii.gz (8.5 KB)

I send you the complete ‘script.sh’ also. Maybe in other step I could be doing wrong the workflow.

script.sh (2.3 KB)

Your sct_warp_template in line 18 will overwrite the label/ folder that you created at line 10. You should specify another output for your warped template, e.g.:

sct_warp_template -d /media/Data/PEH/SPINE/FA/axial/${base}_eddy_fa.nii -w warp_template2dmri.nii.gz -qc ../QControl -ofolder label_diff

Please also note that SCT now features a batch script that loops across subjects, outputs log files, etc. I would recommend you use that new feature. More info in the latest SCT course section Analysis pipelines with SCT.

Thank you very much !!

:slight_smile:

One Question more,
as you said, I run:
sct_warp_template -d ${base}_eddy_fa_crop.nii -w …/warp_template2dmri.nii.gz -qc QControl_s01 -ofolder label_diff

However, when I’m going to extract the FA values, I have to copy the info_labels.txt from the ./label/atlas/ folder to the new label_diff/atlas folder. Indeed, I obtain this error:

"Spinal Cord Toolbox (git-master-0ab51b7d97eaecd539ac11b6fdb07a6ea6fb7548*)

Traceback (most recent call last):
File “/home/jnavas/sct/scripts/sct_extract_metric.py”, line 425, in
perlevel=perlevel, verbose=verbose, combine_labels=combine_labels)
File “/home/jnavas/sct/scripts/sct_extract_metric.py”, line 280, in main
= read_label_file(path_label, param_default.file_info_label)
File “/home/jnavas/sct/spinalcordtoolbox/metadata.py”, line 167, in read_label_file
il.load(fname_label)
File “/home/jnavas/sct/spinalcordtoolbox/metadata.py”, line 82, in load
raise ValueError(“Unexpected at line {}, specifying file {} which doesn’t exist: {}”.format(idx_line+1, _filename, line))
ValueError: Unexpected at line 4, specifying file spinal_level_01.nii.gz which doesn’t exist: 0, Spinal level C1, spinal_level_01.nii.gz"

In the new "label_diff"folder I do not have the “spinal_level” subfolder

you should absolutely not copy the info_label.txt file, but instead point to the proper vertebral level file when calling sct_process_segmentation. Example:

sct_process_segmentation -i ${base}-T2_SAG_resize_seg.nii -vertfile ${base}-T2_SAG_resize_seg_labeled.nii -vert 1:14 -perlevel 1 -o csa_spinalcord.csv

alternatively, you can point to the warped labeled segmentation:

sct_process_segmentation -i ${base}-T2_SAG_resize_seg.nii -vertfile label_diff/template/PAM50_levels.nii.gz -vert 1:14 -perlevel 1 -o csa_spinalcord.csv

This is explained in the SCT course page 67.