Calculate CSA of the spinal canal and cord

Hi!

  1. A description of the problem. (What are trying to do? What did you expect to happen? What actually happened?)

I’m trying to calculate the CSA of the spinal cord and the spinal canal using both segmentations (canal.nii.gz and cord.nii.gz), the vertebral label from totalspineseg and the same centerline (from the canal).

sct_process_segmentation -i canal.nii.gz -z 1:1684 -angle-corr-centerline canal.nii.gz -vertfile SPINE_110_step1_levels.nii.gz -perslice 1 -o csv_canal.csv

--
Spinal Cord Toolbox (6.5)

sct_process_segmentation -i canal.nii.gz -z 1:1684 -angle-corr-centerline canal.nii.gz -vertfile SPINE_110_step1_levels.nii.gz -perslice 1 -o csv_canal.csv
--

Converting image from type 'int16' to type 'float64' for linear interpolation
Converting image from type 'int16' to type 'float64' for linear interpolation
Compute shape analysis: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 1386/1386 [00:17<00:00, 81.48iter/s]
Aggregating metrics:   0%|                              | 0/9 [00:00<?, ?iter/s]/Users/fkmp/sct_6.5/python/envs/venv_sct/lib/python3.9/site-packages/numpy/core/fromnumeric.py:3504: RuntimeWarning: Mean of empty slice.
  return _methods._mean(a, axis=axis, dtype=dtype,
/Users/fkmp/sct_6.5/python/envs/venv_sct/lib/python3.9/site-packages/numpy/core/_methods.py:129: RuntimeWarning: invalid value encountered in scalar divide
  ret = ret.dtype.type(ret / rcount)
Aggregating metrics: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 9/9 [00:05<00:00,  1.72iter/s]

Done!
sct_process_segmentation -i cord.nii.gz -z 1:1684 -angle-corr-centerline canal.nii.gz -vertfile SPINE_110_step1_levels.nii.gz -perslice 1 -o csv_cord.csv

--
Spinal Cord Toolbox (6.5)

sct_process_segmentation -i cord.nii.gz -z 1:1684 -angle-corr-centerline canal.nii.gz -vertfile SPINE_110_step1_levels.nii.gz -perslice 1 -o csv_cord.csv
--

Converting image from type 'int16' to type 'float64' for linear interpolation
Converting image from type 'int16' to type 'float64' for linear interpolation
Compute shape analysis: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 1063/1063 [00:07<00:00, 142.72iter/s]
Aggregating metrics:   0%|                              | 0/9 [00:00<?, ?iter/s]/Users/fkmp/sct_6.5/python/envs/venv_sct/lib/python3.9/site-packages/numpy/core/fromnumeric.py:3504: RuntimeWarning: Mean of empty slice.
  return _methods._mean(a, axis=axis, dtype=dtype,
/Users/fkmp/sct_6.5/python/envs/venv_sct/lib/python3.9/site-packages/numpy/core/_methods.py:129: RuntimeWarning: invalid value encountered in scalar divide
  ret = ret.dtype.type(ret / rcount)
Aggregating metrics: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 9/9 [00:05<00:00,  1.79iter/s]

Done!

I obtained the results but then when I was verifying the correctness of the results, I realized that the angles are misplaced which I understand that implies that the results are not correct.

  1. System information. (Please run the command β€œsct_check_dependencies” in your terminal, then copy and paste the output.)
--

Spinal Cord Toolbox (6.5)

sct_check_dependencies

--

SYSTEM INFORMATION

------------------

SCT info:

- version: 6.5

- path: /Users/fkmp/sct_6.5

OS: osx (macOS-10.16-x86_64-i386-64bit)

CPU cores: Available: 8, Used by ITK functions: 8

RAM: Total: 8192MB, Used: 4867MB, Available: 2400MB
  1. File upload. (Please upload any data or scripts needed to reproduce your issue, if there are any.) β†’

canal.nii.gz (700.6 KB)
cord.nii.gz (562.1 KB)
SPINE_110_step1_levels.nii.gz (250.0 KB)

Dear @fkmp,

We are currently discussing this internally (along with the developer of totalspineseg), and will provide a reply for you shortly. :slight_smile:

Thank you for your patience and understanding!

Kind regards,
Joshua

2 Likes

Hi !

I think I found your problem ! First, thank you for using SCT and our new totalspineseg model ! Even though I would like to warn you that totalspineseg may not yet be the most suitable model for CSA evaluations, as its segmentation quality for the canal is still imperfect and often leads to over-segmentation. So maybe you could try with our other segmentation model for canal T2w segmentation if your contrast is T2w for sure.

Now that you are aware of this limitation, you need to change the file you input for the flag -vertfile:

  1. Use the function sct_label_vertebrae with the flag -discfile
sct_label_vertebrae -i $image_file -s -i $canal_seg -c t? -discfile SPINE_110_step1_levels.nii.gz
  1. Use the file generated with the suffix _seg_labeled.nii.gz
sct_process_segmentation -i canal.nii.gz -z 1:1684 -angle-corr-centerline canal.nii.gz -vertfile *_seg_labeled.nii.gz -perslice 1 -o csv_canal.csv

Also I think the flag -z is not necessary here

Hoping it solves your issue.

Thank you both for your quick response. I’m going to try it right now and tell you more about it.

I actually did used canal_t2w for the canal segmentation, but thank you for the information!!

Hi!

So I tried @Nathan_Molinier solution and it perfectly solved the Vertlevel, as now it indicates all the values of the vertebrae along the slices.

However, I still have an issue. I understand that if the same centerline (as in this case) is used; the angles RL and AP calculated during the sct_process_segmentation should be the same for both canal and spinal cord CSA. To make sure I used the example t2.nii.gz data from the sct webpage and graphed the angles vs the slices and also the area. As you can see, the segmentation of the cord is longer than the canal, therefore the angles match all the way from the canal segmentation until the end.
csa example - graph_t2.csv (12.5 KB)

However, when I apply the same process of CSA calculation, using the same centerline and now with the updated vertebrae label for my data, the angles do not match. Actually they do match, but somehow the cord is displaced. In this case, the segmentation of the canal is longer and the cord ends first. But I think that the angles should match from the start until the spinal cord ends.
csa example - graph_SPINE.csv (73.7 KB)

pd: I edited the csv and screenshot bc I realized there was an error

Thank you!

Hi @fkmp! Thank you for the investigations! Could you please share the exact commands you’re using? Also, if you could provide the sample image you’re working with, I’d be able to debug the issue on my end (if the image can’t be shared here, feel free to email it to jan.valosek@polymtl.ca). Thank you!

1 Like

Hi @fkmp! Thanks for sharing the files; I can reproduce your outputs. I’ve opened an issue (#4807) to investigate it further.

1 Like