How to deal with DTI data and the problem of conversion from dicom to nii

The labeling is done for template registration.

The extraction of metrics uses vertebral levels (not disc levels) to extract metrics at specific vertebral levels.

So, if you want values at C3 mid-vertebral body, C3-C4 disc, C4 mid-vertebral body, etc. you could do the following:

sct_extract_metric -i dti_FA.nii.gz -f label/atlas -l 51,52 -vert 3:5 -perlevel 1 -o DWI_FA.csv

This will give you ONE value per mid-vertebral body level. Then, you average adjacent values (e.g. C3 and C4), which will give you the disc value (C3-C4).

dear jcohenadad , I have get the result of the dwi I want . but I think the fa value is much lower than the normal value. why this will happened?
could you check my code for a while ?

> file_dwi="TANG_WING_KUN_WIP_DTI_thk7_breath_1_5_1"
> 
> file_bvec=${file_dwi}.bvec
> 
> file_bval=${file_dwi}.bval
> 
> Separate b=0 and DW images
> 
> sct_dmri_separate_b0_and_dwi -i ${file_dwi}.nii.gz -bvec ${file_bvec}
> 
> sct_propseg -i ${file_dwi}_dwi_mean.nii.gz -c dwi
> 
> sct_create_mask -i ${file_dwi}_dwi_mean.nii.gz -p centerline,${file_dwi}_dwi_mean_seg.nii.gz -size 30mm
> 
> sct_crop_image -i ${file_dwi}.nii.gz -m mask_${file_dwi}_dwi_mean.nii.gz -o ${file_dwi}_crop.nii.gz
> 
> sct_dmri_moco -i ${file_dwi}_crop.nii.gz -bvec ${file_dwi}.bvec -x spline
> 
> file_dwi=${file_dwi}_crop_moco
> 
> file_dwi_mean=${file_dwi}_dwi_mean
> 
> # # Segment spinal cord (only if it does not exist)
> 
> sct_deepseg_sc -i ${file_dwi_mean}.nii.gz -c dwi -qc qc
> 
> file_dwi_seg=${file_dwi_mean}_seg
> 
> # # # Create labels, assuming that the mid-FOV is centered at C6 vertebral level
> 
> # sct_label_utils -i ${file_dwi_seg}.nii.gz -create-seg 6,8 -o label_C6.nii.gz
> 
> sct_label_utils -i ${file_dwi_seg}.nii.gz -vert-body 6,8 -o label_C6.nii.gz
> 
> sct_register_to_template -i ${file_dwi_mean}.nii.gz -s ${file_dwi_seg}.nii.gz -l label_C6.nii.gz -ref subject -c t1 -param step=1,type=seg,algo=centermassrot:step=2,type=im,algo=syn,metric=CC,slicewise=0,smooth=0,iter=3 -qc qc
> 
> mv warp_template2anat.nii.gz warp_template2dwi.nii.gz
> 
> mv warp_anat2template.nii.gz warp_dwi2template.nii.gz
> 
> sct_warp_template -d ${file_dwi_mean}.nii.gz -w warp_template2dwi.nii.gz -qc qc
> 
> sct_dmri_compute_dti -i ${file_dwi}.nii.gz -bvec ${file_bvec} -bval ${file_bval} -method standard
> 
> sct_maths -i label/atlas/PAM50_atlas_00.nii.gz -add $(for i in `seq -w 2 2 36`; do echo "label/atlas/PAM50_atlas_${i}.nii.gz"; done) -o label/atlas/PAM50_atlas_left.nii.gz
> 
> sct_maths -i label/atlas/PAM50_atlas_01.nii.gz -add $(for i in `seq -w 3 2 35`; do echo "label/atlas/PAM50_atlas_${i}.nii.gz"; done) -o label/atlas/PAM50_atlas_right.nii.gz
> 
> # sct_extract_metric -i dti_FA.nii.gz -f label/atlas -l 51,52 -vert 3:5 -perlevel 1 -o DWI_FA.csv
> 
> sct_extract_metric -i label/atlas/PAM50_atlas_left.nii.gz -f label/atlas -l 52,53,54,55 -vert 6:8 -perlevel 1 -o DWI_FA.csv -append 1
> 
> sct_extract_metric -i label/atlas/PAM50_atlas_right.nii.gz -f label/atlas -l 52,53,54,55 -vert 6:8 -perlevel 1 -o DWI_FA.csv -append 1
> 
> # sct_extract_metric -i label/atlas/PAM50_atlas_left.nii.gz -f label/atlas -l 52,53,54,55 -vert 6:8 -o DWI_FA.csv -append 1
> 
> # sct_extract_metric -i label/atlas/PAM50_atlas_right.nii.gz -f label/atlas -l 52,53,54,55 -vert 6:8 -o DWI_FA.csv -append 1

Two issues.

Issue 1:
with this line:

> sct_maths -i label/atlas/PAM50_atlas_00.nii.gz -add $(for i in `seq -w 2 2 36`; do echo "label/atlas/PAM50_atlas_${i}.nii.gz"; done) -o label/atlas/PAM50_atlas_left.nii.gz

you are including the CSF in your mask, so it is expected that FA would be abnormally low.

instead of using this approach of creating a mask by adding labels, i suggest you stick to my instructions here, i.e., ONLY change the file info_label.txt by adding the tracts you like.

Issue 2:
with this line:

> sct_extract_metric -i label/atlas/PAM50_atlas_left.nii.gz -f label/atlas -l 52,53,54,55 -vert 6:8 -perlevel 1 -o DWI_FA.csv -append 1

you are quantifying the value of a binary mask (instead of the FA).

Dear jcohenadad.
Thank you for your reply, but could you help me to change the code ?I am afraid I do it wrong again!
Thank you!

i already instructed here. What is it you don’t understand?

dear jcohenadad
with this line:

> sct_extract_metric -i label/atlas/PAM50_atlas_left.nii.gz -f label/atlas -l 52,53,54,55 -vert 6:8 -perlevel 1 -o DWI_FA.csv -append 1

you are quantifying the value of a binary mask (instead of the FA).
I don’t know how to change this line. it is a little difficult for me.

I don’t know how to change this line. it is a little difficult for me.

You should not use that line. Just modify the file info_label.txt by adding those two lines:

56, left funiculi, 4,6,8,10,12
57, right funiculi, 5,7,9,11,13

For information, here is the modified file: info_label.txt (2.8 KB)

Copy the file under your SCT installation folder (let’s call it $SCT_DIR): $SCT_DIR/data/PAM50/atlas/ (replace the existing one)

Then re-run this code, but replace the last lines (everything below “# Compute FA, MD and RD in WM…”) with:

sct_extract_metric -i dti_FA.nii.gz -f label/atlas -l 51,52,56,57 -vert 5:7 -o DWI_FA.csv -append 1
sct_extract_metric -i dti_MD.nii.gz -f label/atlas -l 51,52,56,57 -vert 5:7 -o DWI_MD.csv -append 1
sct_extract_metric -i dti_RD.nii.gz -f label/atlas -l 51,52,56,57 -vert 5:7 -o DWI_RD.csv -append 1

Dear jcohenadad .
Your code will result a outcome like this.


But I want a result like this
Not just the left and right result. But also a result including left dorsal , ventral ,and lateral.and right dorsal ,ventral, and lateral.
Could you help me?

dear jcohenadad , maybe I expressed myself not clearly. could you tell me where is my mistake ?

Dear jcohenadad,
could you provide the help to me for this problem?
Thank you.

Hi
You can use other labels and specify them with the flag -l
To see the list of labels available run: sct_extract_metric

dear jcohenadad
these are list of labels
0, WM left fasciculus gracilis, PAM50_atlas_00.nii.gz

1, WM right fasciculus gracilis, PAM50_atlas_01.nii.gz

2, WM left fasciculus cuneatus, PAM50_atlas_02.nii.gz

3, WM right fasciculus cuneatus, PAM50_atlas_03.nii.gz

4, WM left lateral corticospinal tract, PAM50_atlas_04.nii.gz

5, WM right lateral corticospinal tract, PAM50_atlas_05.nii.gz

6, WM left ventral spinocerebellar tract, PAM50_atlas_06.nii.gz

7, WM right ventral spinocerebellar tract, PAM50_atlas_07.nii.gz

8, WM left rubrospinal tract, PAM50_atlas_08.nii.gz

9, WM right rubrospinal tract, PAM50_atlas_09.nii.gz

10, WM left lateral reticulospinal tract, PAM50_atlas_10.nii.gz

11, WM right lateral reticulospinal tract, PAM50_atlas_11.nii.gz

12, WM left spinal lemniscus (spinothalamic and spinoreticular tracts), PAM50_atlas_12.nii.gz

13, WM right spinal lemniscus (spinothalamic and spinoreticular tracts), PAM50_atlas_13.nii.gz

14, WM left spino-olivary tract, PAM50_atlas_14.nii.gz

15, WM right spino-olivary tract, PAM50_atlas_15.nii.gz

16, WM left ventrolateral reticulospinal tract, PAM50_atlas_16.nii.gz

17, WM right ventrolateral reticulospinal tract, PAM50_atlas_17.nii.gz

18, WM left lateral vestibulospinal tract, PAM50_atlas_18.nii.gz

19, WM right lateral vestibulospinal tract, PAM50_atlas_19.nii.gz

20, WM left ventral reticulospinal tract, PAM50_atlas_20.nii.gz

21, WM right ventral reticulospinal tract, PAM50_atlas_21.nii.gz

22, WM left ventral corticospinal tract, PAM50_atlas_22.nii.gz

23, WM right ventral corticospinal tract, PAM50_atlas_23.nii.gz

24, WM left tectospinal tract, PAM50_atlas_24.nii.gz

25, WM right tectospinal tract, PAM50_atlas_25.nii.gz

26, WM left medial reticulospinal tract, PAM50_atlas_26.nii.gz

27, WM right medial reticulospinal tract, PAM50_atlas_27.nii.gz

28, WM left medial longitudinal fasciculus, PAM50_atlas_28.nii.gz

29, WM right medial longitudinal fasciculus, PAM50_atlas_29.nii.gz

30, GM left ventral horn, PAM50_atlas_30.nii.gz

31, GM right ventral horn, PAM50_atlas_31.nii.gz

32, GM left intermediate zone, PAM50_atlas_32.nii.gz

33, GM right intermediate zone, PAM50_atlas_33.nii.gz

34, GM left dorsal horn, PAM50_atlas_34.nii.gz

35, GM right dorsal horn, PAM50_atlas_35.nii.gz

36, CSF contour, PAM50_atlas_36.nii.gz

50, spinal cord, 0:35

51, white matter, 0:29

52, gray matter, 30:35

53, dorsal columns, 0:3

54, lateral funiculi, 4:13

55, ventral funiculi, 14:29

56, left hemi-cord, 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34

57, right hemi-cord, 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35

there is no label for gm left lateral and gm right lateral . if there are other labels ?

you can easily create a label for GM lateral as I showed you for labels 56 and 57. Just add the line:

58, left GM, 30,32,34
59, right GM, 31,33,35

Dear jcohenadad this is my new script for GM.but I think the value is lower than normal .do you think what is the problem?

#!/usr/bin/env bash 

file_dwi="TANG_WING_KUN_WIP_DTI_thk7_breath_1_5_1"
file_bvec=${file_dwi}.bvec
file_bval=${file_dwi}.bval
Separate b=0 and DW images
sct_dmri_separate_b0_and_dwi -i ${file_dwi}.nii.gz -bvec ${file_bvec}
sct_propseg -i ${file_dwi}_dwi_mean.nii.gz -c dwi
sct_create_mask -i ${file_dwi}_dwi_mean.nii.gz -p centerline,${file_dwi}_dwi_mean_seg.nii.gz -size 30mm
sct_crop_image -i ${file_dwi}.nii.gz -m mask_${file_dwi}_dwi_mean.nii.gz -o ${file_dwi}_crop.nii.gz
sct_dmri_moco -i ${file_dwi}_crop.nii.gz -bvec ${file_dwi}.bvec -x spline

file_dwi=${file_dwi}_crop_moco
file_dwi_mean=${file_dwi}_dwi_mean
# # Segment spinal cord (only if it does not exist)
sct_deepseg_sc -i ${file_dwi_mean}.nii.gz -c dwi -qc qc
file_dwi_seg=${file_dwi_mean}_seg
# # # Create labels, assuming that the mid-FOV is centered at C6 vertebral level

# sct_label_utils -i ${file_dwi_seg}.nii.gz -create-seg 6,8 -o label_C6.nii.gz
sct_label_utils -i ${file_dwi_seg}.nii.gz -create-seg -1,6 -o label_C6.nii.gz

sct_register_to_template -i ${file_dwi_mean}.nii.gz -s ${file_dwi_seg}.nii.gz -l label_C6.nii.gz -ref subject -c t1 -param step=1,type=seg,algo=centermassrot:step=2,type=im,algo=syn,metric=CC,slicewise=0,smooth=0,iter=3 -qc qc
mv warp_template2anat.nii.gz warp_template2dwi.nii.gz
mv warp_anat2template.nii.gz warp_dwi2template.nii.gz
sct_warp_template -d ${file_dwi_mean}.nii.gz -w warp_template2dwi.nii.gz -qc qc
sct_dmri_compute_dti -i ${file_dwi}.nii.gz -bvec ${file_bvec} -bval ${file_bval} -method standard
# sct_maths -i label/atlas/PAM50_atlas_00.nii.gz -add $(for i in `seq -w 2 2 36`; do echo "label/atlas/PAM50_atlas_${i}.nii.gz"; done) -o label/atlas/PAM50_atlas_left.nii.gz
# sct_maths -i label/atlas/PAM50_atlas_01.nii.gz -add $(for i in `seq -w 3 2 35`; do echo "label/atlas/PAM50_atlas_${i}.nii.gz"; done) -o label/atlas/PAM50_atlas_right.nii.gz
sct_extract_metric -i dti_FA.nii.gz -f label/atlas -l 30,31,32,33,34,35,58,59 -vert 6:8  -perlevel 1 -o DWI_FA.csv -append 1
# sct_extract_metric -i dti_MD.nii.gz -f label/atlas -l 30,32,34 -vert 6:8  -o DWI_MD.csv -append 1
# sct_extract_metric -i dti_RD.nii.gz -f label/atlas -l 30,32,34 -vert 6:8  -o DWI_RD.csv -append 1

could be due to your data (artifact, low SNR), segmentation or mis-registration with the template. I suggest you check all that. Uploading the QC report could help us review what could go wrong in your analysis.

qc.zip (519.2 KB)
Dear jcohenadad, this is my QC report , can you check for a while ?

you might want to exclude this first slice from your analyses:
Screen Shot 2020-02-03 at 10.21.05 AM

The rest looks good to me.
Best
Julien

Dear jcohenadad , last time I used the 4.1.0version . The script ran well, however,I have to used another 4.1.1version in other computer.The same script always shows error.


What is the matter?

hi,

can you please post this as a new thread (with specific title)?

this thread is getting extremely long, and includes a lot of issues that have nothing to do with the subject of the thread “How to deal with DTI data and the problem of conversion from dicom to nii”, which makes it extremely difficult for others to follow.

thanks

Ok,thank you very much.