1 of 175

SCT Course, 2023-11-20, (Virtual)

Updated: 2023-11-20

Course material for SCT v6.1

2 of 175

Print these slides

If you wish to print these slides with presenter notes, do the following:

  1. File -> Print preview
  2. In the newly visible menu bar, click on "1 slide without notes" and change to "1 slide with notes"
  3. Uncheck "Include skipped slides".
  4. Download as PDF

3 of 175

Questions during the course

  • Zoom ‘general’ chat
  • Miro board

4 of 175

Outline

4

  1. Introduction
  2. Installation
  3. Segmentation
  4. Vertebral labeling
  5. Shape-based analysis
  6. Registration to template
  7. Register additional contrasts
  8. Gray matter segmentation
  9. Atlas-based analysis
  10. Diffusion-weighted MRI
  11. Functional MRI
  12. Other features
  13. Analysis pipelines with SCT
  14. What’s next?
  15. Conclusions

5 of 175

Introduction

5

6 of 175

Quantitative MRI of the spinal cord

  • Functional MRI, DTI, MTR, T1, T2, etc.
  • Diagnosis/prognosis traumas, neurological diseases, cancers
  • Objective biomarkers for testing new drugs

6

Magnetization transfer

Myelin integrity

Spectroscopy

Metabolism

Functional MRI

Neuronal activity

Conventional MRI

Pathology

Diffusion MRI

Axon integrity

7 of 175

Image processing

7

How to process spinal cord multi-parametric MRI data?

brain data

?

spinal cord data

8 of 175

SCT: Spinal Cord Toolbox

  • SCT is a comprehensive and open-source library of analysis tools for multi-parametric MRI of the spinal cord.
  • Download at:�https://spinalcordtoolbox.com/

8

9 of 175

Overview of SCT

9

Atlas-based analysis

Segmentation

  • 2D slice-by-slice
  • Regularized across slices & time
  • Robust for DWI (group-wise)

and many more features…

C1

C3

C5

T1

T2w

T1w

Registration framework

Template and atlas

SCT

Motion correction

10 of 175

Published methods

General SCT citation:

  • De Leener et al. SCT: Spinal Cord Toolbox, an open-source software for processing spinal cord MRI data. Neuroimage 2017.

�Template and Atlas

  • Fonov et al. Framework for integrated MRI average of the spinal cord white and gray matter: The MNI-Poly-AMU template. Neuroimage 2014
  • Taso et al. Construction of an in vivo human spinal cord atlas based on high-resolution MR images at cervical and thoracic levels: preliminary results. MAGMA, Magn Reson Mater Phy 2014
  • Cadotte et al. Characterizing the Location of Spinal and Vertebral Levels in the Human Cervical Spinal Cord. AJNR Am J Neuroradiol 2014
  • Lévy et al. White matter atlas of the human spinal cord with estimation of partial volume effect. Neuroimage 2015
  • De Leener et al. PAM50: Unbiased multimodal template of the brainstem and spinal cord aligned with the ICBM152 space. Neuroimage 2018

�Segmentation

  • De Leener et al. Robust, accurate and fast automatic segmentation of the spinal cord. Neuroimage 2014
  • Ullmann et al. Automatic labeling of vertebral levels using a robust template-based approach. Int J Biomed Imaging 2014
  • Dupont et al. Fully-integrated framework for the segmentation and registration of the spinal cord white and gray matter. Neuroimage 2017
  • Perone et al. Spinal cord gray matter segmentation using deep dilated convolutions. Sci Rep 2018
  • Gros et al. Automatic spinal cord localization, robust to MRI contrasts using global curve optimization. Med Image Anal 2017
  • Gros et al. Automatic segmentation of the spinal cord and intramedullary multiple sclerosis lesions with convolutional neural networks. Neuroimage 2019
  • Bedard et al. Towards contrast-agnostic soft segmentation of the spinal cord. Arxiv Preprint 2023

�Registration

  • De Leener et al. Topologically-preserving straightening of spinal cord MRI. J Magn Reson Imaging 2016
  • Cohen-Adad et al. Slice-by-slice regularized registration for spinal cord MRI: SliceReg. ISMRM 2015

10

11 of 175

Applications (150+ citations)

Quantitative structural MRI (diffusion, MT, etc.)

  • Samson et al., ZOOM or non-ZOOM? Assessing Spinal Cord Diffusion Tensor Imaging protocols for multi-centre studies. PLOS One 2016
  • Taso et al.Tract-specific and age-related variations of the spinal cord microstructure: a multi-parametric MRI study using diffusion tensor imaging (DTI) and inhomogeneous magnetization transfer (ihMT). NMR Biomed 2016
  • Massire A. et al. High-resolution multi-parametric quantitative magnetic resonance imaging of the human cervical spinal cord at 7T. Neuroimage 2016
  • Duval et al. g-Ratio weighted imaging of the human spinal cord in vivo. Neuroimage 2016
  • Ljungberg et al. Rapid Myelin Water Imaging in Human Cervical Spinal Cord. Magnetic Resonance in Medicine 2016
  • Battiston et al. An optimized framework for quantitative Magnetization Transfer imaging of the cervical spinal cord in vivo. Magnetic Resonance in Medicine 2017

�Functional MRI

  • Kong et al. Intrinsically organized resting state networks in the human spinal cord. PNAS 2014
  • Vahdat et al. Simultaneous Brain–Cervical Cord fMRI Reveals Intrinsic Spinal Cord Plasticity during Motor Sequence Learning. PLOS Biology 2015
  • Eippert F. et al. Investigating resting-state functional connectivity in the cervical spinal cord at 3T. NeuroImage 2016
  • Weber K.A. et al. Functional Magnetic Resonance Imaging of the Cervical Spinal Cord During Thermal Stimulation Across Consecutive Runs. Neuroimage 2016
  • Weber et al. Lateralization of cervical spinal cord activity during an isometric upper extremity motor task with functional magnetic resonance imaging. Neuroimage 2016
  • Eippert et al. Denoising spinal cord fMRI data: Approaches to acquisition and analysis. Neuroimage 2016
  • Weber et al. Thermal Stimulation Alters Cervical Spinal Cord Functional Connectivity in Humans. Neurocience 2017

�Application in patients

  • Yiannakas et al. Fully automated segmentation of the cervical cord from T1-weighted MRI using PropSeg: Application to multiple sclerosis. NeuroImage: Clinical 2015
  • Castellano et al., Quantitative MRI of the spinal cord and brain in adrenomyeloneuropathy: in vivo assessment of structural changes. Brain 2016
  • Grabher et al., Voxel-based analysis of grey and white matter degeneration in cervical spondylotic myelopathy. Sci Rep 2016;6:24636.
  • Talbott JF et al. An Imaging Based Approach to Spinal Cord Infection. Seminars in Ultrasound, CT and MRI. 2016
  • McCoy et al. MRI Atlas-Based Measurement of Spinal Cord Injury Predicts Outcome in Acute Flaccid Myelitis. AJNR 2016
  • Ventura et al. Cervical spinal cord atrophy in NMOSD without a history of myelitis or MRI-visible lesions. Neurol Neuroimmunol Neuroinflamm 2016
  • Martin et al. A Novel MRI Biomarker of Spinal Cord White Matter Injury: T2*-Weighted White Matter to Gray Matter Signal Intensity Ratio. AJNR 2017
  • Grabher et al. Neurodegeneration in the Spinal Ventral Horn Prior to Motor Impairment in Cervical Spondylotic Myelopathy. Journal of Neurotrauma 2017
  • Smith et al. Lateral corticospinal tract damage correlates with motor output in incomplete spinal cord injury. Archives of Physical Medicine and Rehabilitation 2017
  • Hori et al. Application of Quantitative Microstructural MR Imaging with Atlas-based Analysis for the Spinal Cord in Cervical Spondylotic Myelopathy. Sci Rep 2018
  • Huber et al. Dorsal and ventral horn atrophy is associated with clinical outcome after spinal cord injury. Neurology 2018

12 of 175

Cross-sectional area in MS

  • 120 subjects (21 CIS, 26 RRMS, 26 PPMS, 21 SPMS, 26 HC)
  • + 40 follow-up (10 HC, 10 RRMS, 10 PPMS, 10 SPMS)
  • Comparison with state-of-art method (Horsfield et al.)

Yiannakas et al., Neuroimage Clinical 2015

Application of SCT

12

Group

n

CSA (PropSeg5) (Mean ± SD, mm2)

Control

26

70.2 ± 7.5

CIS

21

75.9 ± 7.9

RRMS

23

68.7 ± 7.9

PPMS

22

60.4 ± 10

SPMS

20

56.1 ± 10.5

  • Results are consistent with previous literature
  • Fully automatic
    • No user-bias
    • Reproducible
    • Applicable to very-large databases

13 of 175

Multi-center DTI study

Samson et al., PLOS One 2017

Application of SCT

    • 3 sites
    • 5 subjects per site
    • Two MRI brands (Philips, Siemens)

13

Vanderbilt

Montreal

London

A

P

R

b=0

FA

0.1

0.9

L

Template

Atlas

London

Vanderbilt

Montreal

FA in fasciculus gracilis

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

L

R

L

R

L

R

14 of 175

Mapping MS lesions in the cord

Eden et al., Brain 2019

Application of SCT

14

Lesion Probability Map

N=642 (13 sites)

15 of 175

Gray matter atrophy in ALS

Paquin et al., AJNR 2017

Application of SCT

15

Automatic GM segmentation

GM atrophy is a better discriminator of ALS than cord atrophy

Prediction at 1 year

Perone, Sci. Reports 2018

16 of 175

Tract-based analysis in stroke patients

Karbasforoushan et al. Nat. Commun. 2019

16

17 of 175

Combining PET-MRI to study pain

Albrecht et al. Pain 2018

17

Patients suffering from a common chronic pain disorder (lumbar radiculopathy) exhibit elevated levels of the neuroinflammation marker 18 kDa translocator protein, in the dorsal root ganglion and spinal cord.

18 of 175

Consensus acquisition and dataset

  • Spine Generic: Related project that powers many SCT-based studies
  • Optimized acquisition parameters on a consensus study and available for GE, Philips and Siemens at:�https://spinalcordmri.org/protocols

Cohen-Adad et al., Nature Protocols 2021

18

19 of 175

Distribution

  • OS supported
    • MacOS (10.15+)
    • Linux
    • Windows
  • Interface
    • Command line
    • Fsleyes integration
  • Dependent software
    • None, but we recommend installing FSL for its viewer (fsleyes).
  • Programming languages
    • Python 3
    • C++ (uses ITK/VTK)
  • Testing
  • What is available?
    • Packages for OSX, Linux, Windows
      • Script-based installer
      • Includes pre-compiled binaries of ANTs, OptiC and PropSeg
    • Source code (github)
  • License
    • LGPLv3 License

19

20 of 175

Course convention

Links, references, etc. will go here

sct_function_name

20

Mandatory for this course

Try this at home

name of SCT function

Tips!

NEW

in v6.1

21 of 175

Installation

21

22 of 175

Recommended terminal

22

  • The SCT course will require you to enter commands into a terminal.
  • Here are our recommendations for which terminal program to use:
    • For Linux/macOS, you should be able to simply open the “Terminal” program that is built into your operating system
    • For Windows, we recommend using the “Git Bash” program that comes with Git. (Git will be installed during SCT’s installation instructions.)

23 of 175

Installation of stable release

sct_check_dependencies

echo $SCT_DIR

# For the “echo” command, you should see SCT’s installation directory in the output

23

24 of 175

Resize your terminal

24

100 chars

25 of 175

Basic Unix commands

Further reading: The Unix Shell

# Print text

echo "I <3 SCT"

# Check where you are

pwd

# List contents of current directory

ls

# Make a new directory

mkdir dir_name

# Go to directory

cd dir_name

# Make a new text file

touch example.txt

# Go to previous directory

cd ..

# List contents of ‘dir_name’

ls dir_name

# Cleanup files/directories

rm dir_name/example.txt

rm -r dir_name

25

Triple-click with left mouse button to select from this slide, then copy and paste in your Terminal

26 of 175

Download course material

sct_download_data

# Go to your home folder (or another if you prefer, such as “~/Desktop”)

cd ~

# Download course material (requires Internet and working SCT)

sct_download_data -d sct_course_data -o sct_course_data

# Go inside course data folder

cd sct_course_data

# Inspect contents using `ls`

ls

Output: multi_subject README.md single_subject tutorial-datasets.csv

# Go inside the ‘single_subject’ folder

cd single_subject

26

27 of 175

batch_single_subject.sh

sct_download_data

  • All commands run in this course are listed in the file batch_single_subject.sh which is present in the folder single_subject/. You can see it with ls:

27

  • You can treat this script as a quick reference for the course, if you wish to return to the material after the course has finished.

ls

Output: batch_single_subject.sh data

28 of 175

A little bit of background information before we begin

29 of 175

Quality Control (QC) Reports

  • Many commands in this course will allow you to visualize output images using an interface called Quality Control (QC) reports.
  • QC reports allow for quick keyboard-based navigation of processed subjects

29

30 of 175

Image Viewer

  • FSLeyes: Physical/Voxel-centric, good for making labels. (Recommended by SCT team)
  • ITKsnap: Physical-centric, open source, works on Windows, too! (Recommended by SCT team)
  • 3D Slicer: Physical-centric, good for visualizing mesh.
  • Horos: DICOM viewer for MacOSX, based on OsiriX

30

31 of 175

File formats: nii vs. nii.gz

  • .nii.gz is a compressed version of .nii.
  • When to use .nii.gz:
    • Saves a lot of space!
      • Warping fields: these files can be large and are stored as float
      • Segmentation and label files: these files are sparse therefore the compression is very efficient.
    • Easier to share with colleagues/collaborators
  • When to use .nii:
      • Can potentially save some processing time due to avoiding the need for decompression (e.g., for motion correction procedures that split a lot of of volumes along 4th dimension)
  • Recommendation: Use nii.gz in most cases

31

32 of 175

Spaces in file names

  • NEVER use “space” in folder or file names, as spaces increase the risk of unexpected errors in the terminal (e.g. one folder being interpreted as two)
  • So, instead of:

32

/home/Julien superduper folder/my file name.nii.gz

  • Use dashes (-) and underscores (_):

/home/Julien_superduper_folder/my_file_name.nii.gz

/home/Julien_superduper_folder/my-file-name.nii.gz

/home/Julien-superduper_folder/my_file-name.nii.gz

...

33 of 175

Segmentation

33

34 of 175

Theory

35 of 175

Spinal cord segmentation

Two main SC methods:

  • PropSeg (2014)
    • Command: sct_propseg
  • DeepSegSC (2019)
    • Command: sct_deepseg_sc�

Specialized models:

  • DeepSeg (2021-Present)
    • Command: sct_deepseg

36 of 175

Centerline detection (OptiC)

sct_get_centerline

36

  • Both PropSeg and DeepSegSC begin with OptiC, a centerline detection method

  • Centerline detection helps identify the region of interest for SC segmentation

Input image

Probabilistic localization map

Regularized SC centerline

1

0

1

2

A

S

I

P

A

S

I

P

A

S

I

P

37 of 175

PropSeg

sct_propseg

37

SC centerline detection (OptiC)

Low-resolution propagation

High-resolution global deformation

38 of 175

DeepSegSC

  • Uses a deep learning-based approach to augment OptiC

sct_deepseg_sc

38

Input 3D image

SC detection

SC centerline

Segmentation

Patch

Extraction

0

1

CNN1

OptiC

CNN2

  • Cascade of Convolutional Neural Network: CNN1+OptiC (cord detection) and CNN2 (cord segmentation)
  • Trained models on T1, T2, T2s and DWI contrasts
  • N=1554 from multi-center data, including various pathologies (compression, MS, ALS, etc.)

39 of 175

Other segmentation models

sct_deepseg

  • sct_deepseg provides access to models created by the ivadomed project (https://ivadomed.org)
  • In recent versions, new models for the segmentation of spinal tumors, human multi-class SC & GM at 7T, MS lesion segmentation on MP2RAGE, mouse SC, etc.

39

NEW

in v6.1

Tumor segmentation

WM/GM cord segmentation at 7T

# List of available models

sct_deepseg -h

MP2RAGE SC and lesion segmentation

40 of 175

Hands-on

41 of 175

Choose between contrasts

sct_deepseg_sc, sct_propseg

41

T1 “like”

T2 “like”

T1w

dwi

fmri

T2w

mt

-c t1

-c t2

DWI “like”

-c dwi

T2* “like”

-c t2s

T2*w

  • Specify the -c flag to select a contrast:
  • Used to detect the centerline with OptiC
  • Used to select the appropriate DeepSegSC model
  • Used to drive the gradient on PropSeg

42 of 175

Spinal cord segmentation

sct_deepseg_sc

# Go to T2 contrast

cd data/t2

# Try cord segmentation using deep learning. Note the flag "-qc" to generate a QC report of the segmentation.

sct_deepseg_sc -i t2.nii.gz -c t2 -qc ~/qc_singleSubj

42

t2

t2_seg

Output

Input

43 of 175

Inspecting results (QC)

open ~/qc_singleSubj/index.html # macOS

xdg-open ~/qc_singleSubj/index.html # Linux

start ~/qc_singleSubj/index.html # Windows

  • Because we specified the -qc flag, a QC report folder will be generated in your home directory
  • You can open the QC report by double-clicking the file ~/qc_singleSubj/index.html, or by running one of the following commands:
  • If you have an image viewer installed (FSLeyes, ITKSnap), you can also inspect the image there, too

44 of 175

What to do if segmentation fails?

sct_deepseg_sc, sct_propseg, sct_deepseg

  • Change kernel size

44

-kernel {2d,3d} # default value: 2d

-centerline {svm,cnn,viewer,file} # default value: svm

  • Change centerline detection method
  • Manually correct the segmentation (e.g. in FSLeyes)
  • Try legacy segmentation method based on mesh propagation: sct_propseg
  • Check the specialized models in sct_deepseg to see if one fits your use case
  • Ask for help on the SCT forum: https://forum.spinalcordmri.org/c/sct

45 of 175

Vertebral labeling

45

46 of 175

Theory

47 of 175

Vertebral/disc labeling

sct_label_vertebrae

47

Algorithm

  1. Find C2-C3 disc using OptiC [1].
  2. Spinal cord straightening [2].
  3. Sliding window of disc pattern, starting at initialization (intervertebral disc). Mutual information of adjacent disc weighted by probability of disc location from template. Scaling of template is adjusted after each identified disc [3].

Features

  • Contrast-independent
  • Robustness towards pathology/artifact: If correlation is too low, disc is placed based on probabilistic template

48 of 175

Types of vertebral labels

  • “Vertebral labels” can mean 2 different things:
    • Full body labels (used for CSA calculation, etc.)
    • Point (single voxel) labels (used as landmarks for registration)

Full body labels

Point labels

49 of 175

Conventions for point labels

49

NEW

in v6.1

50 of 175

Hands-on

51 of 175

Label vertebrae/discs

sct_label_vertebrae

# Vertebral labeling

sct_label_vertebrae -i t2.nii.gz -s t2_seg.nii.gz -c t2 -qc ~/qc_singleSubj

# Check QC report: Go to your browser and do "refresh".

# Note: Here, two files are output: t2_seg_labeled, which represents the labeled segmentation (i.e., the value corresponds to the vertebral level), and t2_seg_labeled_discs, which only has a single point for each intervertebral disc level. The convention is: Value 3 —> C2-C3 disc, Value 4 —> C3-C4 disc, etc.

51

t2

t2_seg

t2_seg_labeled

t2_seg_labeled_discs

Output

Input

52 of 175

Label vertebrae with manual initialization

sct_label_vertebrae

# If automatic labeling did not work, you can initialize with manual identification of C2-C3 disc:

sct_label_utils -i t2.nii.gz -create-viewer 3 -o label_c2c3.nii.gz -msg "Click at the posterior tip of C2/C3 intervertebral disc"

sct_label_vertebrae -i t2.nii.gz -s t2_seg.nii.gz -c t2 -initlabel label_c2c3.nii.gz -qc ~/qc_singleSubj

52

t2

t2_seg

C2/C3 disc identified with viewer

.

t2_seg_labeled

t2_seg_labeled_discs

Output

Input

53 of 175

Shape-based analysis

53

54 of 175

Compute CSA

sct_process_segmentation

# Compute cross-sectional area (CSA) of spinal cord and average it across levels C3 and C4

sct_process_segmentation -i t2_seg.nii.gz -vert 3:4 -vertfile t2_seg_labeled.nii.gz -o csa_c3c4.csv

54

Timestamp

SCT Version

Filename

Slice (I->S)

VertLevel

MEAN(area)

STD(area)

MEAN(angle_AP)

STD(angle_AP)

MEAN(angle_RL)

STD(angle_RL)

2023-10-20

6.1

/Users/julien

142:186

3:4

74.1357

2.2383

1.5198

0.2758

10.3055

1.9462

.csv files are easily imported in Excel, Numbers, Python, etc.

55 of 175

Compute CSA per level/slice

sct_process_segmentation

# Aggregate CSA value per level

sct_process_segmentation -i t2_seg.nii.gz -vert 3:4 -vertfile t2_seg_labeled.nii.gz -perlevel 1 -o csa_perlevel.csv

55

# Aggregate CSA value per slices

sct_process_segmentation -i t2_seg.nii.gz -z 30:35 -vertfile t2_seg_labeled.nii.gz -perslice 1 -o csa_perslice.csv

Slice (I->S)

VertLevel

MEAN(area)

STD(area)

142:164

4

74.9997

2.2291

165:186

3

73.2324

1.8593

Slice (I->S)

VertLevel

MEAN(CSA [mm^2])

STD(CSA [mm^2])

30

10

38.2313

0.0

31

10

38.2219

0.0

32

10

38.8292

0.0

33

9

40.0529

0.0

34

9

41.2764

0.0

35

9

38.1882

0.0

56 of 175

Compute CSA using PMJ

sct_process_segmentation

# First, detect the Pontomedullary Junction (PMJ)

sct_detect_pmj -i t2.nii.gz -c t2 -qc ~/qc_singleSubj

# Check the QC to make sure PMJ was properly detected, then compute CSA using the distance from the PMJ:

sct_process_segmentation -i t2_seg.nii.gz -pmj t2_pmj.nii.gz -pmj-distance 64 -pmj-extent 30 -o csa_pmj.csv -qc ~/qc_singleSubj -qc-image t2.nii.gz

56

Slice (I->S)

DistancePMJ

MEAN(area)

STD(area)

164:200

64.0

73.5988

1.9646

57 of 175

Shape analysis: Other metrics

sct_process_segmentation

57

MEAN(diameter_AP)

MEAN(diameter_RL)

MEAN(eccentricity)

MEAN(orientation)

MEAN(solidity)

5.1653

9.8062

0.9270

8.1536

0.9221

58 of 175

Shape analysis: normalization

sct_process_segmentation -normalize-PAM50

# Bring shape metrics to the PAM50 anatomical dimensions

sct_process_segmentation -i t2_seg.nii.gz -vertfile t2_seg_labeled.nii.gz -perslice 1 -normalize-PAM50 1 -o csa_PAM50.csv

58

Slice (I->S)

VertLevel

MEAN(area)

MEAN(diameter_AP)

MEAN(diameter_RL)

MEAN(eccentricity)

MEAN(solidity)

923

2

75.2831

8.3176

11.5629

0.6946

0.9674

NEW

in v6.0

  • The flag -normalize-PAM50 let you bring/normalize the shape metrics to the PAM50 anatomical dimensions

Notice that the slice numbering now corresponds to the PAM50 template!

59 of 175

Shape analysis: normalization

sct_process_segmentation -normalize-PAM50

59

Slice (I->S)

VertLevel

MEAN(area)

MEAN(diameter_AP)

MEAN(diameter_RL)

MEAN(eccentricity)

MEAN(solidity)

923

2

75.2831

8.3176

11.5629

0.6946

0.9674

NEW

in v6.0

  • Once the metrics are normalized into the PAM50 anatomical dimensions, you can compare them with a database of healthy normative values

👉 More info available at

Valošek, Bédard et al. NeuroLibre 2023

single subject

CSA

x

normalized CSA (n=203)

60 of 175

Quantify spinal cord compression

sct_compute_compression

60

NEW

in v6.0

👉 See the tutorial for more details.

61 of 175

Registration to template

61

62 of 175

Theory

63 of 175

PAM50: Template of the spinal cord

De Leener, NeuroImage, 2018 —> PAM50

Fonov, NeuroImage 2014 —> Methods for template creation

Taso, MAGMA 2014 —> White matter probabilistic template

Taso, NeuroImage 2015 —> White matter probabilistic template (updated)

Lévy, NeuroImage 2015 —> White matter atlas

63

Spinal cord and brainstem template

👉 More info available on SCT website

64 of 175

PAM50: registration pipeline

Anat (T2w or T1w)

Segmentation

Vertebral labeling

Template & forward/backward transform

Straightening

1. Affine

2. Non-rigid

Concatenate warping fields

.

  • C3

T3

65 of 175

Anat (T2w or T1w)

Segmentation

Vertebral labeling

.

  • C3

T3

66 of 175

Anat (T2w or T1w)

Segmentation

Vertebral labeling

Straightening

.

  • C3

T3

67 of 175

Spinal cord straightening

Internal distance is preserved (as opposed to slice-by-slice translations)

sct_straighten_spinalcord

67

68 of 175

Anat (T2w or T1w)

Segmentation

Vertebral labeling

Straightening

1. Affine

2. Non-rigid

.

  • C3

T3

69 of 175

What is a warping field?

69

  • 4D volume that contains displacement along x,y,z
  • Warning! ITK-based warping field are in composite format:
    • dim header (ANTs/SCT): x,y,z,t,v
    • dim header (FSL/SPM): x,y,z,v
  • To apply a warping field:

sct_apply_transfo -i <file> -d <file> -w <list of: file>

  • To concatenate several warping fields:

sct_concat_transfo -d <file> -w <list of: file>

Warping fields

  • To make warping field FSL/SPM-compatible:

# Convert ITK warping field to FSL warping field

sct_image -i warp_itk.nii.gz -to-fsl input_img.nii.gz -o warp_fsl.nii.gz

# NB: 'input_img.nii.gz' is the source image you will be applying the warping field to, and is used as a reference for the source voxel space

70 of 175

Anat (T2w or T1w)

DTI, MTR, ...

Segmentation

Vertebral labeling

Template & forward/backward transform

Straightening

1. Affine

2. Non-rigid

Concatenate warping fields

Warp template objects to metric

Concatenate warping fields

Register to template in anat space

.

  • C3

T3

Warp template objects to metric

Estimate metric in spinal pathway (accounts for partial volume effect)

spinothalamic

spinocerebellar

corticospinal

cuneatus

gracilis

White matter atlas (30 tracts)

Compute cross-sectional area

CSA (mm2)

MTR (%)

71 of 175

FA

MD

RD

MTR

CST_L

CST_R

MTR

[%]

FA

RD

[µm2/s]

MD

[µm2/s]

0.77

0.73

909

937

393

449

34

35

cuneatus_L

0.72

901

463

29

cuneatus_R

0.76

807

354

33

CSA (mm2)

20

90

Vertebral labeling

CSA (mm2)

CSA (mm2)

gray matter

white matter

spinal cord

Atlas-based analysis

Cross-sectional area (CSA) measurements

72 of 175

Hands-on

73 of 175

Selecting landmarks for registration

sct_label_utils

# Create labels at C3 and T2 mid-vertebral levels. These labels are needed for template registration.

sct_label_utils -i t2_seg_labeled.nii.gz -vert-body 3,9 -o t2_labels_vert.nii.gz

# Generate a QC report to visualize the two selected labels on the anatomical image

sct_qc -i t2.nii.gz -s t2_labels_vert.nii.gz -p sct_label_utils -qc ~/qc_singleSubj

73

t2_labels

t2_seg_labeled

value = 3

value = 9

.

.

Output

Input

74 of 175

Alternative: Manual disc labeling

# You might want to completely bypass sct_label_vertebrae and do the labeling manually. In that case, we provide a viewer to do so conveniently.

# In the example below, we will create labels at the intervertebral discs C2-C3 (value=3), C3-C4 (value=4) and C4-C5 (value=5).

sct_label_utils -i t2.nii.gz -create-viewer 3,4,5 -o labels_disc.nii.gz -msg "Place labels at the posterior tip of each intervertebral disc. E.g. Label 3: C2/C3, Label 4: C3/C4, etc."

74

t2

“viewer”

labels_disc

Output

Input

75 of 175

Register to template

sct_register_to_template

# Register t2->template.

sct_register_to_template -i t2.nii.gz -s t2_seg.nii.gz -l t2_labels_vert.nii.gz -c t2 -qc ~/qc_singleSubj

# Note: By default the PAM50 template is selected. You can also select your own template using flag -t.

75

t2

t2_seg

t2_labels

template2anat

anat2template

warp_anat2template

warp_template2anat

.

.

Output

Input

76 of 175

Registration results

76

PAM50 to t2

t2 to PAM50

77 of 175

Register to template: -ref

  • The flag -ref lets you select the destination for registration: either the template (default) or the subject’s native space.
  • The main difference is that when -ref template is selected, the cord is straightened, whereas with -ref subject, it is not.
  • When should you use -ref subject? If your image is acquired axially with highly anisotropic resolution (e.g. 0.7x0.7x5mm), the straightening will produce through-plane interpolation errors. In that case, it is better to register the template to the subject space to avoid such inaccuracies.

sct_register_to_template

77

78 of 175

Register to template: -param

  • The flag -param lets you select registration parameters at each step.
  • A good approach is to start with large deformation with low degree of freedom, and finish with local adjustment.
  • All transformations are constrained in Z direction, though estimation can be done slice-wise or volume-wise: -param slicewise={0, 1}
  • Another important parameter is the algorithm, which is set by -param algo=

sct_register_to_template, sct_register_multimodal

78

translation

rigid

affine

bsplinesyn[1]

syn[1]

slicereg[1,2]

centermassrot*

columnwise*

translation

PCA-based rotation

x-scaling

match segmentation borders for each y

dl[3]

Deep-learning registration

(*) Only use with type=seg

NEW

in v5.7

79 of 175

Register to template: -param

  • Registration can be done via multiple steps using the flag -param step=STEP_NUM
  • The default values for -param are:�step=1,type=imseg,algo=centermassrot,slicewise=0→ To deal with large deformations. Note that centermassrot can be used to account for cord rotations�step=2,type=seg,algo=bsplinesyn,metric=MeanSquares,iter=3,smooth=1,gradStep=0.5,slicewise=0→ To deal with fine cord shape adjustment, regularized SyN deformation
  • Carefully chose type={im, seg} based on the quality of your data, and the similarity with the template. Ideally, you would always choose type=im. However, if you find that there are artifacts of image features (e.g., no CSF/cord contrast) that could compromise the registration, then use type=seg instead. Of course, if you choose type=seg, make sure your segmentation is good (manually adjust it if it is not). By default, the sct_register_to_template relies on the segmentations only because it was found to be more robust to the existing variety of MRIs.
  • Adjust metric based on type:�With type=im, use metric=CC (accurate but long) or MI (fast, but requires enough voxels)�With type=seg, use metric=MeanSquares.

sct_register_to_template

79

80 of 175

Register to template: -ldisc

  • The approach described previously uses two labels at the mid-vertebral level to register the template, which is fine if you are only interested in a relatively small region (e.g. C2 —> C7).
  • However, if your volume spans a large superior-inferior length (e.g., C2 —> L1), the linear scaling between your subject and the template might produce inaccurate vertebral level matching between C2 and L1. In that case, you might prefer to rely on all inter-vertebral discs for a more accurate registration:

sct_register_to_template

80

sct_register_to_template -i t2.nii.gz -s t2_seg.nii.gz -ldisc t2_seg_labeled_discs.nii.gz -c t2

  • Conversely, if you have a very small FOV (e.g., covering only C3/C4), you can create a unique label at disc C3/C4 (value=4) and use -ldisc for registration. In that case, a single translation (no scaling) will be performed between the template and the subject.
  • Note: If more than 2 labels are provided, -ldisc is not compatible with -ref subject. For more information, please see the help: sct_register_to_template -h

81 of 175

Example in compressed cord

# In case of highly compressed cord, the algo columnwise can be used, which allows for more deformation than bsplinesyn.

# NB: In the example below, the registration is done in the subject space (no straightening) using a single label point at disc C3-C4 (<LABEL_DISC>).

sct_register_to_template -i <IMAGE> -s <SEGMENTATION> -ldisc <LABEL_DISC> -ref subject -param step=1,type=seg,algo=centermassrot:step=2,type=seg,algo=columnwise

81

IMAGE

SEGMENTATION(*)

*: manual adjustment likely required

anat2IMAGE

wm/gm atlas

82 of 175

Warp template objects

sct_warp_template

# Warp template objects (T2, cord segmentation, vertebral levels, etc.). Here we use -a 0 because we don’t need the white matter atlas at this point.

sct_warp_template -d t2.nii.gz -w warp_template2anat.nii.gz -a 0 -qc ~/qc_singleSubj

# Note: A folder label/template/ is created, which contains template objects in the space of the subject. The file info_label.txt lists all template files.

# Check results using FSLeyes. Tips: use CMD+f (or CTRL+f on Linux/Windows) to switch overlay on/off.

fsleyes t2.nii.gz -cm greyscale -a 100.0 label/template/PAM50_t2.nii.gz -cm greyscale -dr 0 4000 -a 100.0 label/template/PAM50_gm.nii.gz -cm red-yellow -dr 0.4 1 -a 50.0 label/template/PAM50_wm.nii.gz -cm blue-lightblue -dr 0.4 1 -a 50.0 &

82

t2

warp_template2anat

/label/template

Output

Input

83 of 175

A note about subject-centric analysis

  • The PAM50 template was just warped to the subject’s coordinate space (subject-centric analysis)�
  • However, you can also use the inverse warping field (warp_anat2template.nii.gz) to warp the subject files to the template space�
  • Pros and cons:
    • Subject-centric: Metric files aren’t warped → No re-interpolation to worry about
    • Template-centric: Metric files warped to same space → Allows for group mapping

sct_warp_template, sct_apply_tranfo

83

84 of 175

How to add another contrast (MTR, diffusion, etc.)?

85 of 175

Register additional contrasts

85

86 of 175

Anat (T2w or T1w)

DTI, MTR, ...

Segmentation

Vertebral labeling

Template & forward/backward transform

Concatenate warping fields

Straightening

1. Affine

2. Non-rigid

Concatenate warping fields

Register to template in anat space

.

  • C3

T3

Warp template objects to metric

87 of 175

Segment MT data

sct_register_multimodal, sct_propseg

# Go to mt folder

cd ../mt

# Segment cord

sct_deepseg_sc -i mt1.nii.gz -c t2 -qc ~/qc_singleSubj

87

mt1

mt1_seg

Output

Input

88 of 175

Create mask

sct_create_mask

# Create a close mask around the spinal cord for more accurate registration (i.e. does not account for surrounding tissue which could move independently from the cord)

sct_create_mask -i mt1.nii.gz -p centerline,mt1_seg.nii.gz -size 35mm -f cylinder -o mask_mt1.nii.gz

88

mt1

mask_mt1

mt1_seg

Output

Input

89 of 175

Register template to MT1

sct_register_multimodal

# Register template->mt1. The flag -initwarp ../t2/warp_template2anat.nii.gz initializes the registration using the template->t2 transformation which was previously estimated

# Tips: Here we only use the segmentations (type=seg) to minimize the sensitivity of the registration procedure to image artifacts.

# Tips: First step: algo=centermass to align source and destination segmentations, then algo=bpslinesyn to adapt the shape of the cord to the mt modality (in case there are distortions between the t2 and the mt scan).

sct_register_multimodal -i $SCT_DIR/data/PAM50/template/PAM50_t2.nii.gz -iseg $SCT_DIR/data/PAM50/template/PAM50_cord.nii.gz -d mt1.nii.gz -dseg mt1_seg.nii.gz -m mask_mt1.nii.gz -initwarp ../t2/warp_template2anat.nii.gz -param step=1,type=seg,algo=centermass:step=2,type=seg,algo=bsplinesyn,slicewise=1,iter=3 -owarp warp_template2mt.nii.gz -qc ~/qc_singleSubj

89

90 of 175

Register template without anatomical image

sct_register_to_template

# You can register the template directly to a metric image, without going via an anatomical image. For that, you just need to create one or two labels in the metric space. For example, if you know that your FOV is centered at C3/C4 disc, then you can create a label automatically at the S-I axis midpoint using -create-seg-mid:

sct_label_utils -i mt1_seg.nii.gz -create-seg-mid 4 -o label_c3c4.nii.gz

# Then, you can register to the template.

# Note: In case the metric image has axial resolution with thick slices, we recommend to do the registration in the subject space (instead of the template space), without cord straightening.

sct_register_to_template -i mt1.nii.gz -s mt1_seg.nii.gz -ldisc label_c3c4.nii.gz -ref subject -param step=1,type=seg,algo=centermassrot:step=2,type=seg,algo=bsplinesyn,slicewise=1

90

mt1

mt1_seg

mt1_label

.

Output

Input

91 of 175

Warp template to MT

sct_warp_template

# Warp template

sct_warp_template -d mt1.nii.gz -w warp_template2mt.nii.gz -a 1 -qc ~/qc_singleSubj

# Check results using FSLeyes. Tips: use CMD+f (or CTRL+f on Linux/Windows) to switch overlay on/off.

fsleyes mt1.nii.gz -cm greyscale -a 100.0 label/template/PAM50_t2.nii.gz -cm greyscale -dr 0 4000 -a 100.0 label/template/PAM50_gm.nii.gz -cm red-yellow -dr 0.4 1 -a 50.0 label/template/PAM50_wm.nii.gz -cm blue-lightblue -dr 0.4 1 -a 50.0 &

91

label/template/

label/atlas/

WM atlas

mt1

warp_template2mt

Output

Input

92 of 175

Register mt0 on mt1

sct_register_multimodal

# Register mt0->mt1 using z-regularized slicewise translations (algo=slicereg)

sct_register_multimodal -i mt0.nii.gz -d mt1.nii.gz -dseg mt1_seg.nii.gz -m mask_mt1.nii.gz -param step=1,type=im,algo=slicereg,metric=CC -x spline -qc ~/qc_singleSubj

# Check QC report or FSLeyes. Tips: use CMD+f (or CTRL+f on Linux/Windows) to switch overlay on/off.

fsleyes mt1.nii.gz mt0_reg.nii.gz &

92

93 of 175

Compute MTR

sct_compute_mtr

# Compute magnetization transfer ratio

# Note: MTR is given in percentage.

sct_compute_mtr -mt0 mt0_reg.nii.gz -mt1 mt1.nii.gz

93

mt1

mt0_reg

mtr

0

50

Output

Input

94 of 175

How to register the lumbar region to the PAM50 template?

95 of 175

Segmenting lumbar region

# Change to the folder containing the lumbar scan

cd ../t2_lumbar

# Use lumbar-specific `sct_deepseg` model to segment the spinal cord

sct_deepseg -i t2_lumbar.nii.gz -task seg_lumbar_sc_t2w

# Note: Input image (e.g. t2_lumbar.nii.gz) should primarily display the lumbar region, as the segmentation model may perform worse if the upper regions of the spinal cord are visible.

t2_lumbar

t2_lumbar_seg

Output

Input

96 of 175

Selecting landmarks for registration

  • Using only disc labels will often result in misalignment of the terminal end of the spinal cord
  • So, we introduce a new label “60” (conus medullaris)

One label (17: T9-T10 disc)

✅ aligned top discs

✅ semi-aligned bottom discs

❌ misaligned conus medullaris

One label (60: conus medullaris)

17

60

Two labels (17 and 60)

60

17

misaligned top discs

misaligned bottom discs

aligned conus medullaris

✅ aligned top discs

❌ misaligned bottom discs

aligned conus medullaris

97 of 175

Labeling lumbar landmarks

# Open images in viewer (to identify coords within the seg slices)

fsleyes t2_lumbar.nii.gz -cm greyscale t2_lumbar_seg.nii.gz -cm red

# Use coords to label the T9-T10 disc (17) and conus medullaris (60)

sct_label_utils -i t2_lumbar.nii.gz -create 27,76,187,17:27,79,80,60 -o t2_lumbar_labels.nii.gz

# Create QC report entry for generated labels

sct_qc -i t2_lumbar.nii.gz -s t2_lumbar_labels.nii.gz -p sct_label_utils -qc ~/qc_singleSubj

t2_lumbar

t2_lumbar_labels

17

60

Note: Coordinates must exist within the same

axial slices as the

cord segmentation!

Output

Input

98 of 175

Register lumbar to template

sct_register_to_template

# Register t2->template.

sct_register_to_template -i t2_lumbar.nii.gz -s t2_lumbar_seg.nii.gz -ldisc t2_lumbar_labels.nii.gz -c t2 -qc ~/qc_singleSubj -param step=1,type=seg,algo=centermassrot:step=2,type=seg,algo=bsplinesyn,metric=MeanSquares,iter=3,slicewise=0:step=3,type=im,algo=syn,metric=CC,iter=3,slicewise=0

# Note: By default the PAM50 template is selected. You can also select your own template using flag -t.

98

t2_lumbar

t2_lumbar_seg

t2_lumbar_labels

template2anat

anat2template

warp_anat2template

warp_template2anat

17

60

NEW

in v6.1

Output

Input

99 of 175

Gray matter segmentation

99

100 of 175

Theory

101 of 175

GM segmentation methods

  • SCT features a deep learning method for GM segmentation called: sct_deepseg_gm
    • Algorithm: Deep learning with dilated convolutions [1]
    • Pros: High accuracy, robust to pathologies
    • Cons: Restricted to T2*-like contrasts (GM bright, �WM dark)
  • The older method [3] sct_segment_graymatter �is no longer available.

sct_deepseg_gm

101

Results of the GM challenge [2]

Dice coefficient

sct_deepseg_gm

sct_segment_gm

102 of 175

Hands-on

103 of 175

Segment GM and WM

sct_deepseg_gm

# Go to T2*-weighted data, which has good GM/WM contrast and high in-plane resolution

cd ../t2s

# Segment gray matter (check QC report afterwards)

sct_deepseg_gm -i t2s.nii.gz -qc ~/qc_singleSubj

# Full spinal cord segmentation

sct_deepseg_sc -i t2s.nii.gz -c t2s -qc ~/qc_singleSubj

# Subtract GM segmentation from cord segmentation to obtain WM segmentation

sct_maths -i t2s_seg.nii.gz -sub t2s_gmseg.nii.gz -o t2s_wmseg.nii.gz

103

t2s

t2s_gmseg

t2s_wmseg

Output

Input

104 of 175

CSA of GM and WM

# Compute cross-sectional area (CSA) of the gray and white matter for all slices in the volume.

# Note: Here we use the flag -angle-corr 0, because we do not want to correct the computed CSA by the cosine of the angle between the cord centerline and the S-I axis: we assume that slices were acquired orthogonally to the cord.

sct_process_segmentation -i t2s_gmseg.nii.gz -o csa_gm.csv -perslice 1 -angle-corr 0

sct_process_segmentation -i t2s_wmseg.nii.gz -o csa_wm.csv -perslice 1 -angle-corr 0

104

CSA (mm2)

gray matter

white matter

t2s_gmseg

t2s_wmseg

Output

Input

105 of 175

Extract signal intensity in GM

sct_extract_metric

# You can also use the GM/WM binary masks to extract signal from MRI data using sct_extract_metric. The example below will show how to use the GM and WM segmentations to quantify T2* signal as done in [Martin et al. PLoS One 2018].

# Quantify average WM and GM signal between slices 2 and 12.

sct_extract_metric -i t2s.nii.gz -f t2s_wmseg.nii.gz -method bin -z 2:12 -o t2s_value.csv

sct_extract_metric -i t2s.nii.gz -f t2s_gmseg.nii.gz -method bin -z 2:12 -o t2s_value.csv -append 1

# Note: the flag -append enables to append a new result at the end of an already-existing csv file.

105

Slice (I->S)

Label

Size [vox]

BIN()

STD()

2:12

t2s_wmseg

2788

1313.1486

235.0801

2:12

t2s_gmseg

599

1495.0286

209.3065

106 of 175

How to account for white and gray matter segmentations during template registration?

107 of 175

Anat (T2w or T1w)

DTI, MTR, ...

Segmentation

Warp template objects to metric

Vertebral labeling

Template & forward/backward transform

Concatenate warping fields

Straightening

1. Affine

2. Non-rigid

Concatenate warping fields

Register to template in anat space

Gray matter segmentation

Optional step to improve accuracy of atlas registration

.

  • C3

T3

Warping field with local deformation

108 of 175

GM-informed template registration

# Register template->t2s (using warping field generated from template<->t2 registration)

# Tips: Here we use the WM seg for the iseg/dseg fields in order to account for both the cord and the GM shape.

sct_register_multimodal -i "${SCT_DIR}"/data/PAM50/template/PAM50_t2s.nii.gz -iseg "${SCT_DIR}"/data/PAM50/template/PAM50_wm.nii.gz -d t2s.nii.gz -dseg t2s_wmseg.nii.gz -initwarp ../t2/warp_template2anat.nii.gz -initwarpinv ../t2/warp_anat2template.nii.gz -owarp warp_template2t2s.nii.gz -owarpinv warp_t2s2template.nii.gz -param step=1,type=seg,algo=rigid:step=2,type=seg,metric=CC,algo=bsplinesyn,slicewise=1,iter=3:step=3,type=im,metric=CC,algo=syn,slicewise=1,iter=2 -qc ~/qc_singleSubj

# Warp template

sct_warp_template -d t2s.nii.gz -w warp_template2t2s.nii.gz -qc ~/qc_singleSubj

108

t2s

t2s_wmseg

PAM50_wm (unregistered)

PAM50_wm (registered)

109 of 175

Register another metric

cd ../mt

# Register template->mt via t2s to account for GM segmentation

sct_register_multimodal -i $SCT_DIR/data/PAM50/template/PAM50_t2.nii.gz -iseg $SCT_DIR/data/PAM50/template/PAM50_cord.nii.gz -d mt1.nii.gz -dseg mt1_seg.nii.gz -param step=1,type=seg,algo=centermass:step=2,type=seg,algo=bsplinesyn,slicewise=1,iter=3 -m mask_mt1.nii.gz -initwarp ../t2s/warp_template2t2s.nii.gz -owarp warp_template2mt.nii.gz -qc ~/qc_singleSubj

# Warp template

sct_warp_template -d mt1.nii.gz -w warp_template2mt.nii.gz -qc ~/qc_singleSubj

109

t2s

PAM50_t2 (reg)

PAM50_gm (reg)

PAM50_wm (reg)

110 of 175

Atlas-based analysis

110

111 of 175

Anat (T2w or T1w)

DTI, MTR, ...

Segmentation

Warp template objects to metric

Vertebral labeling

Template & forward/backward transform

Concatenate warping fields

Straightening

1. Affine

2. Non-rigid

Concatenate warping fields

Register to template in anat space

Estimate metric in spinal pathway (accounts for partial volume effect)

spinothalamic

spinocerebellar

corticospinal

cuneatus

gracilis

White matter atlas (30 tracts)

Gray matter segmentation

Optional step to improve accuracy of atlas registration

.

  • C3

T3

Warping field with local deformation

Compute cross-sectional area

CSA (mm2)

MTR (%)

112 of 175

Theory

113 of 175

White matter atlas

Lévy et al., Neuroimage 2015

Based on: Standring, Gray's Anatomy 2008

113

rubrospinal tract

spino-olivary tract

spinal lemniscus (spinothalamic and spinoreticular tracts)

medial longitudinal fasciculus

ventrolateral reticulospinal tract

lateral vestibulospinal tract

ventral reticulospinal tract

tectospinal tract

ventral corticospinal tract

medial reticulospinal tract

gray matter (ventral)

gray matter (medial)

fasciculus gracilis

spinocerebellar tract

lateral reticulospinal tract

fasciculus cuneatus

lateral corticospinal tract

cerebrospinal fluid

gray matter (dorsal)

114 of 175

White matter atlas

114

cerebrospinal fluid

white matter

gray matter

S=0

S=50

apparent value in voxel: S=25

115 of 175

Quantify metrics with atlas

115

    • Weighted average using PV information (wa)Problem: Does not solve PVE (e.g., CSF=0, WM=40 ➔ voxel in rubrospinal tract with 50% CSF & 50% WM value = 20)
    • Maximum Likelihood (ml)�Uses data from all voxels (y) and partial volume value �from each tract (Xi) to estimate the “true” value (β)in each tract.Problem: not robust to noise within small tracts
    • Maximum A Posteriori (map)�Uses prior information (β0) from CSF, �WM and GM for robust estimation of β. Especially relevant for small tracts.

Recommended

    • Current standard method: Average within binary ROI (bin)Problem: does not account for PVE

116 of 175

Validation of atlas-based analysis

116

1

0

Atlas creation

20% noise & randomized values in tracts

Bootstrapping

Less than 2% error in “large” tracts

117 of 175

Hands-on

118 of 175

The file info_label.txt

118

    • The function sct_warp_template generates the local folder label/atlas/, which includes the WM tracts and the file named info_label.txt:

sct_extract_metric

Single labels IDs

e.g.: left fasciculus cuneatus = #02

Do not edit this part!

Combined labels

e.g: dorsal column = #00+#01+#02+#03

= 0:3

= 53

This part you can edit

# View the labels present at ./label/atlas/info_label.txt

sct_extract_metric -list-labels

119 of 175

Adding custom tracts

  • The generated file label/atlas/info_label.txt is copied from SCT’s installation folder: $SCT_DIR/data/PAM50/atlas/info_label.txt
  • If you would like to add custom tracts for your analyses, e.g. left and right WM tracts, you can edit the source file, so that next time you run sct_warp_template, the modified info_label.txt file will be copied into your subject’s folder.
  • In the example below, we have added two ensembles of tracts corresponding to the right and left hemi-cord:

119

120 of 175

Extract MTR in white matter

sct_extract_metric

# Extract MTR for each slice within the white matter (combined label: #51)

# NB: 'label/atlas' is the warped atlas that was created by sct_warp_template

sct_extract_metric -i mtr.nii.gz -f label/atlas -method map -l 51 -o mtr_in_wm.csv

# Tips: To list all available labels, type: "sct_extract_metric -list-labels"

120

Slice (I->S)

Label

Size [vox]

MAP()

STD()

0

white matter

0

None

None

1

white matter

48.1509

57.2138

6.9390

2

white matter

62.7561

41.9577

5.4025

3

white matter

60.1965

55.6021

4.5924

4

white matter

67.7719

52.6508

4.9176

5

white matter

71.3479

53.4372

5.0556

6

white matter

74.2350

52.8688

4.8549

20

white matter

72.5338

62.0072

5.3584

21

white matter

0

None

None

121 of 175

Extract MTR in white matter

sct_extract_metric

# Extract MTR within the right and left corticospinal tract and aggregate across specific slices

sct_extract_metric -i mtr.nii.gz -f label/atlas -method map -l 4,5 -z 5:15 -o mtr_in_cst.csv

121

# You can specify the vertebral levels to extract MTR from. For example, to quantify MTR between C2 and C4 levels in the dorsal column (combined label: #53) using weighted average:

sct_extract_metric -i mtr.nii.gz -f label/atlas -method map -l 53 -vert 2:4 -vertfile label/template/PAM50_levels.nii.gz -o mtr_in_dc.csv

Slice (I->S)

Label

Size [vox]

MAP()

STD()

5:15

WM left lateral corticospinal tract

67.2845

53.7157

2.9213

5:15

WM right lateral corticospinal tract

67.6989

53.0890

3.8742

Slice (I->S)

VertLevel

Label

Size [vox]

MAP()

STD()

7:16

2:4

dorsal columns

248.3735

53.6583

3.9940

122 of 175

Diffusion-weighted MRI

122

123 of 175

Preprocess dMRI data

cd ../dmri

# Compute mean dMRI from dMRI data

sct_dmri_separate_b0_and_dwi -i dmri.nii.gz -bvec bvecs.txt

# Segment SC on mean dMRI data

# Note: This segmentation does not need to be accurate-- it is only used to create a mask around the cord

sct_deepseg_sc -i dmri_dwi_mean.nii.gz -c dwi -qc ~/qc_singleSubj

# Create mask (to be used in the subsequent motion correction step)

sct_create_mask -i dmri_dwi_mean.nii.gz -p centerline,dmri_dwi_mean_seg.nii.gz -size 35mm

123

124 of 175

Motion correction for dMRI

sct_dmri_moco

# Motion correction (moco)

sct_dmri_moco -i dmri.nii.gz -m mask_dmri_dwi_mean.nii.gz -bvec bvecs.txt -qc ~/qc_singleSubj -qc-seg dmri_dwi_mean_seg.nii.gz

# Check results in the QC report

124

mask_dmri_dwi_mean.nii.gz

————————————————————

Gaussian mask

displacement (mm)

volume #

Outlier detection

dmri.nii.gz dmri_dwi_mean.nii.gz

dmri_dwi_mean_seg.nii.gz

dmri_moco

Group-wise

registration

Slicereg

Incrementally update target volume with registered volume

Registration features:

Output

Input

125 of 175

Register template to dMRI

# Segment SC on motion-corrected mean dwi data (check results in the QC report)

sct_deepseg_sc -i dmri_moco_dwi_mean.nii.gz -c dwi -qc ~/qc_singleSubj

# Register template->dwi via t2s to account for GM segmentation

# Tips: In general for DWI we use the PAM50_t1 contrast, which is close to the dwi contrast (although here we are not using type=im in -param, so it will not make a difference).

# Note: the flag "-initwarpinv" provides a transformation dmri->template, in case you would like to bring all your DTI metrics in the PAM50 space (e.g. group averaging of FA maps)

sct_register_multimodal -i "${SCT_DIR}/data/PAM50/template/PAM50_t1.nii.gz" -iseg "${SCT_DIR}/data/PAM50/template/PAM50_cord.nii.gz" -d dmri_moco_dwi_mean.nii.gz -dseg dmri_moco_dwi_mean_seg.nii.gz -initwarp ../t2s/warp_template2t2s.nii.gz -initwarpinv ../t2s/warp_t2s2template.nii.gz -owarp warp_template2dmri.nii.gz -owarpinv warp_dmri2template.nii.gz -param step=1,type=seg,algo=centermass:step=2,type=seg,algo=bsplinesyn,slicewise=1,iter=3 -qc ~/qc_singleSubj

# Warp template

sct_warp_template -d dmri_moco_dwi_mean.nii.gz -w warp_template2dmri.nii.gz -qc ~/qc_singleSubj

# Check results in the QC report

125

126 of 175

Compute DTI

sct_dmri_compute_dti

# Compute DTI metrics using dipy [1]

sct_dmri_compute_dti -i dmri_moco.nii.gz -bval bvals.txt -bvec bvecs.txt

# Tips: the flag "-method restore" estimates tensors with robust fit (RESTORE method [2])

# Compute FA within the white matter from individual level 2 to 5

sct_extract_metric -i dti_FA.nii.gz -f label/atlas -l 51 -method map -vert 2:5 -vertfile label/template/PAM50_levels.nii.gz -perlevel 1 -o fa_in_wm.csv

126

dmri_moco

bvecs.txt

————————————————————

bvals.txt

————————————————————

FA

MD

AD

RD

Output

Input

127 of 175

Functional MRI

127

128 of 175

Spinal labeling for fMRI

cd ../fmri

# Average all fMRI time series to make it a 3D volume (needed by the next command)

sct_maths -i fmri.nii.gz -mean t -o fmri_mean.nii.gz

# Bring t2 segmentation to fmri space (to create a mask)

sct_register_multimodal -i ../t2/t2_seg.nii.gz -d fmri_mean.nii.gz -identity 1

# Create mask at the center of the FOV

sct_create_mask -i fmri.nii.gz -p centerline,t2_seg_reg.nii.gz -size 35mm -f cylinder

# Motion correction (using mask)

sct_fmri_moco -i fmri.nii.gz -m mask_fmri.nii.gz -qc ~/qc_singleSubj -qc-seg t2_seg_reg.nii.gz

# Register the template to the fMRI scan.

sct_register_multimodal -i "${SCT_DIR}/data/PAM50/template/PAM50_t2s.nii.gz" -d fmri_moco_mean.nii.gz -dseg t2_seg_reg.nii.gz -param step=1,type=im,algo=syn,metric=CC,iter=5,slicewise=0 -initwarp ../t2s/warp_template2t2s.nii.gz -initwarpinv ../t2s/warp_t2s2template.nii.gz -owarp warp_template2fmri.nii.gz -owarpinv warp_fmri2template.nii.gz -qc ~/qc_singleSubj

# Check results in the QC report

128

129 of 175

Spinal labeling for fMRI

129

  • Vertebral labeling only gives a “rough” idea of where the spinal nerves project in the spinal cord. Spinal labeling [1] is available in SCT
  • There is a new spinal level map (replacing the one from Cadotte et al.) as of v6.1� ❌ Old location (not used anymore): $SCT_DIR/data/PAM50/spinal_levels/ ✅ New location: $SCT_DIR/data/PAM50/template/

NEW

in v6.1

130 of 175

Spinal labeling for fMRI

sct_warp_template

# Warp template with the spinal levels

sct_warp_template -d fmri_moco_mean.nii.gz -w warp_template2fmri.nii.gz -a 0 -qc ~/qc_singleSubj

130

C3

C3

C4

C5

C6

C7

C4

C5

C2

Vertebral levels

Spinal levels

131 of 175

Other features

131

132 of 175

Quality Control (QC)

  • Coming back to the QC report introduced earlier, we will now explore its features in more detail.
  • The QC module is available for the following commands:�
    • sct_propseg
    • sct_deepseg_sc
    • sct_deepseg_gm
    • sct_deepseg_lesion (*NEW*)
    • sct_detect_pmj
    • sct_dmri_moco
    • sct_fmri_moco
    • sct_get_centerline
    • sct_image -stitch (*NEW*)
    • sct_label_utils
    • sct_label_vertebrae
    • sct_process_segmentation
    • sct_register_multimodal
    • sct_register_to_template
    • sct_straighten_spinalcord
    • sct_warp_template

sct_qc

132

NEW

in v6.1

133 of 175

Quality Control (QC) Reports

  • QC reports allow you to quickly assess large batches of subjects by marking the quality of the processing (Pass/Fail) or data quality (Artifact)
  • You can then export the assessments to a YML file and use it for batch analyses (see section Analysis pipelines with SCT).

133

134 of 175

SCT-FSLeyes integration

134

135 of 175

SCT-FSLeyes integration

  • Thanks to the Python plugin, it is possible to call SCT functions from FSLeyes.
  • Open FSLeyes from the Terminal (in order to load SCT environment variables): fsleyes
  • Click on File > Run script and select �$SCT_DIR/contrib/fsl_integration/sct_fsleyes_script.py
  • Also see our video tutorial: https://youtu.be/XC0vu0brEB0
  • Currently 5 different SCT tools are supported.

135

136 of 175

Smooth along spinal cord

sct_smooth_spinalcord

136

no smoothing

z-smoothing

Isotropic smoothing

smoothing along centerline

follows curvature

137 of 175

Smooth along spinal cord

sct_smooth_spinalcord

cd ../t1

# Segment the spinal cord using the usual sct_deepseg_sc command

sct_deepseg_sc -i t1.nii.gz -c t1 -qc ~/qc_singleSubj

# Smooth spinal cord along centerline (extracted from the segmentation)

# Tips: use flag "-sigma" to specify smoothing kernel size (in mm)

sct_smooth_spinalcord -i t1.nii.gz -s t1_seg.nii.gz

# Second-pass segmentation using the smoothed anatomical image

sct_deepseg_sc -i t1_smooth.nii.gz -c t1 -qc ~/qc_singleSubj

137

t1

t1_seg

t1_smooth

Output

Input

138 of 175

Align the cord in the R-L plane

sct_flatten_sagittal

# Align the spinal cord in the right-left direction using slice-wise translations.

sct_flatten_sagittal -i t1.nii.gz -s t1_seg.nii.gz

# Note: Use for visualization purposes only

138

139 of 175

Operations on images

sct_maths

sct_maths -h

-add <str> Add following input (can be number or image(s))

-sub <str> Subtract following input (can be number of image(s))

-mul <str> Multiply following input (can be number or image(s))

-div <str> Divide following input (can be number or image(s))

-mean {x,y,z,t} Average data across dimension.

-rms {x,y,z,t} Compute root-mean-squared across dimension.

-bin <float> Binarize image using specified threshold. E.g. -bin 0.5

-otsu <int> Threshold image using Otsu algorithm.

-percent <int> Threshold image using percentile of its histogram.

-thr <float> Use following number to threshold image (zero below number).

-dilate <int> Dilate binary image using specified ball radius.

-erode <int> Erode binary image using specified ball radius.

-smooth <list of: float> Gaussian smoothing filter with specified standard deviations in

-laplacian <list of: float> Laplacian filtering with specified standard deviations in mm

-denoise <list of: str> Non-local means adaptive denoising from P. Coupe et al.

-mi <file> Compute the mutual information (MI) between two images

-symmetrize {0,1,2} Symmetrize data along the specified dimension.

And more...!

139

140 of 175

Manipulate images

sct_image

sct_image

IMAGE OPERATIONS:

-pad <str> Pad 3d image. Specify padding as: "x,y,z" (in voxel)

-pad-asym <str> Pad 3d image with asymmetric padding.

-split {x,y,z,t} Split data along the specified dimension

-concat {x,y,z,t} Concatenate data along the specified dimension

-remove-vol <int list> Remove specific volumes from a 4d volume. Separate with ","

-keep-vol <int list> Keep specific volumes from a 4d volume (remove others). Separate with ","

-type {uint8,int16 ...} Change file type

-stitch Stitch multiple images acquired in the same orientation *NEW*

HEADER OPERATIONS:

-header [{sct,fslhd,nibabel}] Print the header of a NIfTI file.

-copy-header <file> Copy the header of the source image (specified in -i)

-set-sform-to-qform Set the input image's sform matrix equal to its qform matrix.

-set-qform-to-sform Set the input image's qform matrix equal to its sform matrix.

ORIENTATION OPERATIONS:

-getorient Get orientation of the input image.

-setorient Set orientation of the input image. (Modifies the data array AND header.)

-flip Flip an axis (x,y,z,t) of the data array. (Does not modify header.)

-transpose Transpose the axes (x,y,z) of the data array. (Does not modify header.)

And more...!

140

141 of 175

Image stitching

sct_image -stitch

  • Most studies focus on the cervical spinal cord only, but detecting lesions in the whole spinal cord is clinically relevant
  • MRI data are acquired as "chunks" that need to be stitched into a single image
  • We added a stitching function (sct_image -stitch)

142 of 175

Other features?

  • To see all available functions, type “sct_” then TAB

142

143 of 175

Activate SCT’s Python

  • If you need to activate SCT’s Python, e.g. for prototyping new features, or debugging some functions, run the following from the terminal:

143

source ${SCT_DIR}/python/etc/profile.d/conda.sh

conda activate venv_sct

144 of 175

Analysis pipelines with SCT

144

145 of 175

Batch your processing!

  • Processing pipeline: Consists of a chain of commands arranged so that the output of each element is the input of the next. Pipelines can be designed to automatically process MRI data over hundreds of subjects.
  • Batch scripts are written in shell language (i.e. same as your Terminal) and contains a sequence of SCT commands to establish pipelines.
  • SCT team regularly creates customized pipelines. See examples:�https://github.com/sct-pipeline

sct_run_batch

145

146 of 175

Data organization

  • All participant data are organized into a directory and follow certain conventions, such as the BIDS (https://bids.neuroimaging.io/) data structure:

sct_run_batch

146

my-bids-dataset/

├── README

├── dataset_description.json

├── participants.tsv

├── participants.json

├── sub-ubc01/

├── sub-ubc02/

├── sub-ubc03/

│   ├── anat/

│   │   ├── sub-ubc03_T1w.json

│   │   ├── sub-ubc03_T1w.nii.gz

│   │   ├── sub-ubc03_T2star.json

│   │   ├── sub-ubc03_T2star.nii.gz

147 of 175

Hands-on

148 of 175

Processing multiple subjects

  • Here we use a wrapper, called sct_run_batch, which loops across subjects and launch a batch script.

Text

sct_run_batch

148

# Go to the multi_subject folder

cd ../../../multi_subject

# set proper permissions

chmod +x process_data.sh

# Explore the dataset using the ‘tree’ command (or ‘find’ if tree is not available)

tree data

# See what's in the processing script (choose one command based on OS)

open process_data.sh # MacOS users

xdg-open process_data.sh # Linux users

notepad process_data.sh # Windows users

# Process data (takes 10-30 min). Here we use -jobs 3 to distribute the 3 different subjects across 3 CPU cores

sct_run_batch -script process_data.sh -config config.yml -jobs 3

149 of 175

multi_subject: CSA

sct_run_batch

149

CSA.csv

Filename

Slice (I->S)

VertLevel

MEAN(area)

STD(area)

sub-01_T2w_seg.nii.gz

161:203

2:3

83.5691

2.8218

sub-03_T2w_seg.nii.gz

159:199

2:3

60.6215

2.8740

sub-05_T2w_seg.nii.gz

159:190

2:3

68.7636

3.1984

Each line represents a subject

CSA results

150 of 175

multi_subject: MTR in WM

sct_run_batch

150

MTR_in_DC.csv

Filename

Slice (I->S)

VertLevel

Label

Size [vox]

MAP()

STD()

sub-01/anat/mtr.nii.gz

3:16

2:5

dorsal columns

370.1520

49.7199

4.9987

sub-03/anat/mtr.nii.gz

3:15

2:5

dorsal columns

282.6870

49.3522

5.1998

sub-05/anat/mtr.nii.gz

4:13

2:5

dorsal columns

229.6201

49.2113

4.7677

MTR in dorsal column

151 of 175

Checking QC report

  • Open the QC report (data_processed/qc/index.html)
  • In the search box enter 'deepseg' to review segmentations.
  • If you spot any issues (e.g., segmentation 'leaking') flag it with ❌ ('f' key twice).
  • When finished, you can click 'Download QC Fails' to generate a qc_fail.yml file.
  • We have provided a sample output for you in the multi_subject folder.

151

152 of 175

Manual corrections

  • The script manual_correction.py will be used to conveniently correct the segmentations for the failed subjects.
  • As a prerequisite, make sure you have an image editor installed (in this case: FSLeyes) before running the steps below.

152

# First, download the manual correction script into a folder called `manual-correction`

sct_download_data -d manual-correction -o manual-correction

# Then you can look at the files in the folder

ls manual-correction

# Next, make sure that your image viewer is callable from the

# Terminal. In the course we use FSLeyes but you can do the same

# with another viewer (eg: ITKsnap).

fsleyes --version

# Now we can check the options of the manual correction script (using the help flag -h)

$SCT_DIR/python/envs/venv_sct/bin/python manual-correction/manual_correction.py -h

# NOTE: By typing “$SCT_DIR/python/envs/venv_sct/bin/python” instead of just “python”, we can directly access the version of Python that lives inside the SCT installation

If you have installed FSLeyes via a conda environment, make sure that the environment is active.

153 of 175

Manual corrections

  • Once your setup is ready, you can run the manual correction script.

  • The output segmentations will be located under the derivatives/labels/ folder, according to BIDS convention.
  • Also, JSON sidecar files will be created with name and date, for traceability.

153

# Run the manual correction script

$SCT_DIR/python/envs/venv_sct/bin/python manual-correction/manual_correction.py -config qc_fail.yml -path-img output/data_processed/ -path-label output/data_processed -path-out data/derivatives/labels

# Check the files output to the ‘derivatives/’ folder

tree data/derivatives

154 of 175

Re-run analysis (with corrections)

  • Re-run the analysis. If a label (segmentation or disc) is present in the derivatives/labels/ folder, the script will use that file instead of computing the segmentation.

154

sct_run_batch -script process_data.sh -path-data data/ -path-output output_correction -jobs 3

155 of 175

Provenance of script/data

155

156 of 175

Log files if error

  • Log files are useful to spot errors in some participant data (e.g., file missing, wrong file name)

156

157 of 175

What’s next?

157

158 of 175

What’s next?

158

  • Contrast-agnostic "soft" (non-binary) segmentation
  • SCI segmentation
  • Nerve rootlets segmentation
  • MS lesion segmentation

Upcoming sct_deepseg models

159 of 175

What’s next?

sct_deepseg

  • Model trained on 6 MRI contrasts (Spine Generic)
  • Use an average segmentation across contrasts as ground truth
  • Gives “soft” (non-binary) prediction
  • No need to specify the input contrast

159

Contrast-agnostic segmentation

160 of 175

What’s next?

Bédard*, Karthik Enamundram* et al. arXiv, 2023

Bédard, Karthik Enamundram et al. ISMRM ‘24 (submitted)

sct_deepseg

  • Reduces cross-sectional area variability across contrasts
  • Generalizes well to unseen contrasts/pathologies

sct_deepseg_sc

contrast-agnostic

160

Cervical

Radiculopathy

Traumatic SCI

Multiple

Sclerosis

GRE-EPI

T2w

MP2RAGE

Contrast-agnostic segmentation

161 of 175

What’s next?

  • New deep learning-based approach with better performance than the current template-based approach
  • Will soon be available in sct_label_vertebrae

161

Deep Learning Identification of Vertebral Discs

162 of 175

What’s next?

Valošek*, Enamundram* et al. ISMRM ‘24 (submitted)

162

  • DL-based segmentation of the spinal cord and hyperintense lesions in spinal cord injury (SCI) from T2w images

Automatic Lesion Segmentation in Spinal Cord Injury

163 of 175

What’s next?

  • Current version of SCT uses the ivadomed framework to package its deep learning models
  • Future versions will gradually switch to the more widely used MONAI framework
  • Will soon be available through the sct_deepseg command

163

Integration of MONAI/nnUNet models

164 of 175

What’s next?

Based on: Lévy et al., Neuroimage 2015 and

Hausman, L. “Atlases of the Spinal Cord and Brainstem

and the Forebrain” (Thomas, 1962).

164

medial ventral horn

central ventral horn

lateral ventral horn

ventral intermediate zone

dorsal intermediate zone

reticular formation

dorsomarginal nucleus

fasciculus dorsolateralis

anterior-fissure

central-canal

septum

gray matter (ventral)

gray matter (medial)

gray matter (dorsal)

New labels

  • qT1 and T2*-weighted templates
  • Aligned with the PAM50 space
  • High-resolution (0.18×0.18×0.5)
  • Refined parcellation (new labels)

T2*-weighted

qT1

AMU7T

Templates

Atlas

165 of 175

What’s next?

165

  • DL-based segmentation of the spinal cord nerve rootlets from T2-w images
  • Nerve rootlets can used to estimate spinal cord levels

Automatic Segmentation of Spinal Nerve Rootlets

Axial T2-w image

Nerve rootlets

Spinal Cord Levels

Valošek*, Mathieu* et al. ISMRM ‘24 (submitted)

166 of 175

What’s next?

Collaboration: Raphaëlle Schlienger (Marseille U.)�Olivia Kowalczyk (King's College)

166

Automatic Segmentation of Spinal Nerve Rootlets

Valošek*, Mathieu* et al. ISMRM ‘24 (submitted)

167 of 175

What’s next?

sct_fmri_moco, sct_qc

167

QC report for temporal SNR (tSNR)

  • Compare the tSNR maps before/after motion correction
  • Ensure that motion correction has improved the tSNR

168 of 175

What’s next?

We would like to hear from YOU!

Polling session…

👉 link to poll

169 of 175

Conclusions

169

170 of 175

Need help?

170

171 of 175

Need help?

171

172 of 175

Training: SCT course

Would you like to be added to the mailing list or sponsor the event?

Subscribe to the mailing list via: https://spinalcordmri.org/

Montreal’16

Geneva’16

Hawaii’17

Paris’18

Singapore’16

London’19

Beijing’19

Harvard’21 (Hybrid)

173 of 175

Zoom pic 📸

174 of 175

Contribute to SCT

174

175 of 175

Acknowledgements

Julien Cohen-Adad (PI)

Joshua Newton (Research Associate)

Mathieu Guay-Paquet (Research Associate)

Jan Valosek (Postdoctoral Researcher)

Naga Karthik (PhD student)

Nilser Laines Medina (PhD student)

Pierre-Louis Benveniste (PhD student)

Nathan Molinier (PhD student)

Sandrine Bédard (MSc student)

Rohan Banerjee (MSc student)��Alumni: Alexandru Foias, Alexandru Jora, Andreanne Lemay, Charley Gros, Paul Bautin, Benjamin De Leener, Christian Perone, Clara Giroux, Ainsleigh Hill, Lucas Rouhier, George Peristerakis, Hee-Min Yang, Jérôme Carretero, Nicolas Pinon, P-O Quirion, Sara Dupont, Simon Lévy, Tanguy Duval, Thiago Rezende

Arnaud Le Troter

Nilser Laines Medina

Manuel Taso

Virginie Callot

Louis Collins

Vladimir Fonov

Allan Martin

David Cadotte

Michael Fehlings

Core SCT developers

… and we thank all SCT users for their precious feedback!!

❤️

Collaborators