CSV Slices mismatch with Segmentation

Hi,

I am finding the CSAs from a number of t1 brain and spinal cord scans. I’m specifically trying to look at C2 and what slice C2 Ends at. According to the Quality Control, the labelling is going very well, e.g.:
image

However, When I look at the CSV files generated and check the slices, the values given for example for vertebrae Level 3 do not match up to the scan.
image
slice 327:


slice 334:

And I don’t get any values for vertebrae Level 2. This has happened with all my files…

Below is my script:
#!/bin/bash

declare -a files=(“SC1” “SC2” “SC3” “K1” “K2” “K3” )

cd data

for center in */ ; do
mkdir …/newoutput/$center
cd $center
for file in “${files[@]}” ; do
sct_deepseg_sc -i ${file}.nii -c t1 -qc …/…/output/qc
sct_label_vertebrae -i ${file}.nii -s ${file}_seg.nii -c t1 -qc …/…/newoutput/qc
sct_label_utils -i ${file}_seg_labeled.nii -vert-body 2,3 -o ${file}_labels_vert.nii
sct_register_to_template -i ${file}.nii -s ${file}_seg.nii -l ${file}_labels_vert.nii -c t1 -qc …/…/newoutput/qc
sct_warp_template -d ${file}.nii -w …/…/warp_template2anat.nii.gz -a 0 -qc …/…/newoutput/qc
sct_process_segmentation -i ${file}seg.nii -vert 2:8 -perlevel 1 -o …/…/newoutput/$center/CervLevel${file}.csv
sct_process_segmentation -i ${file}seg.nii -perslice 1 -o …/…/newoutput/$center/perslice${file}.csv
done
cd …
done

Hello!

I may shed some light with the slices problem. You are using sct_process_segmentation without the -vertfile flag, so then, SCT uses the ./label/template/PAM50_levels.nii.gz file which probably will be a little bit different from the _seg_labeled file that you calculated before.

So, if you want to try this and let’s see how it goes. Maybe the outputs are more similar to what you expect

sct_process_segmentation -i ${file} *seg.nii -vert 2:8 -vertfile ${file}_seg_labeled.nii -perlevel 1 -o …/…/newoutput/$center/CervLevel_2_* ${file}.csv

Check the spelling for mistakes since i am not used to shell.

Although, all your results look weird… The mean areas should not be that different one from another, that’s if the numbers are correct, and it looks like the vertebrae 7 and 8 are located from slices 146 to 223 and from 436 to 51? This shouldn’t be.

With the “no values for Level 2” I can’t help you… Hopefully someone else can.
And if he can check what I’ve just said is right also!

good luck!

Aran

Hi @ambaf,

I’m very sorry for the late response. As @Aran rightfully pointed out, the default vertebral level file used by sct_process_segmentation is ./label/template/PAM50_levels.nii.gz, which is slightly different than ${file}_seg_labeled.nii. That being said, the slight different should not explain the large discrepancy you are observing, and especially the strange split of z-slices for level 7, as pointed out by @Aran.

The first thing I noticed is that the script uses “…” instead of “…”, which is wrong syntax in shell. Instead of pointing to the parent directory, “…” results in an error, example:

**julien-macbook:** ~ $ cd ...

-bash: cd: ...: No such file or directory

**julien-macbook:** ~ $ cd ..

**julien-macbook:** /Users $

So, let’s try to debug step-by-step. First, could you please select the subject that gave the output CSV file you attached in your post above, and upload for this subject the following files:

  • ${file}_seg.nii
  • ./label/template/PAM50_levels.nii.gz

These are only segmentations, so there should not be any privacy issue.

Also: in the future, if you want to embed code, please use “~~~”, so that your code is not formatted, which could result in some of the mistakes mentioned above ("…" instead of “…”).

Hi Julien,

Thank you! I’ll try to attach the files mentioned in the next comments. The “…” is a formatting error from the site. Below is the script unformatted:

#!/bin/bash

# script for analysing the 6 centre data for the 3mm piece from C2 to C3
# outputting CSA and Volume. 

declare -a files=("SC1" "SC2" "SC3" "K1" "K2" "K3" )

cd data

for center in */ ; do
	mkdir ../output/$center
	cd $center
	for file in "${files[@]}" ; do
		sct_deepseg_sc -i ${file}.nii -c t1 -qc ../../output/qc
		sct_label_vertebrae -i ${file}.nii -s ${file}_seg.nii -c t1 -qc ../../output/qc
		sct_label_utils -i ${file}_seg_labeled.nii -vert-body 2,3 -o ${file}_labels_vert.nii
		sct_register_to_template -i ${file}.nii -s ${file}_seg.nii -l ${file}_labels_vert.nii -c t1 -qc ../../output/qc
		sct_warp_template -d ${file}.nii -w ../../warp_template2anat.nii.gz -a 0 -qc ../../output/qc
		sct_process_segmentation -i ${file}_seg.nii -vert 1:24 -perlevel 1 -o ../../output/$center/levelC2C3_${file}.csv
		sct_process_segmentation -i ${file}_seg.nii -perslice 1 -o ../../output/$center/perslice_${file}.csv
	done
	cd ..
done

PAM50_levels.nii.gz (85.6 KB)

Hi Julien,

I wasn’t able to attach the Segmentation file, so I sent it via email instead.

Thank you!

Hi Julien and Aran,

Thank you both for your help! Using the -vertfile flag has made the results accurate and also fixed the strange vertebrae slice locations, so this was definitely the solution. I am also getting values for C2 now instead of “None”.

Thank you and best wishes,
Amba

1 Like