From 5ca1c2a46a4e451d9c8056c573a0f7c419b138b2 Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Wed, 5 Nov 2025 14:00:17 -0500 Subject: [PATCH 01/22] Temporarily turn off PR trigger on workflows --- .github/workflows/run_batch_script.yml | 4 ++-- .github/workflows/run_script_and_create_release.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run_batch_script.yml b/.github/workflows/run_batch_script.yml index 5182ac3..dd4d7b0 100644 --- a/.github/workflows/run_batch_script.yml +++ b/.github/workflows/run_batch_script.yml @@ -15,8 +15,8 @@ name: "Run sct_run_batch -s process_data.sh" # - 'sct_course_data.zip': Files required to run the SCT course from start to finish. # - 'registration.zip', 'segmentation.zip', etc.: Files required by individual tutorials. -on: - pull_request: +#on: +# pull_request: jobs: run-course-script: diff --git a/.github/workflows/run_script_and_create_release.yml b/.github/workflows/run_script_and_create_release.yml index 2851ad2..760f21a 100644 --- a/.github/workflows/run_script_and_create_release.yml +++ b/.github/workflows/run_script_and_create_release.yml @@ -19,7 +19,7 @@ on: push: branches: - master - pull_request: +# pull_request: workflow_dispatch: inputs: release_title: From bd483283c0956a1c80d1479049fa3e81fef87b14 Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Wed, 5 Nov 2025 13:04:53 -0500 Subject: [PATCH 02/22] Add GHA workflow to diff slides with batch script --- .../workflows/compare_script_to_course.yml | 60 +++++++++++++++++++ .github/workflows/scripts/extract_sct.py | 40 +++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 .github/workflows/compare_script_to_course.yml create mode 100644 .github/workflows/scripts/extract_sct.py diff --git a/.github/workflows/compare_script_to_course.yml b/.github/workflows/compare_script_to_course.yml new file mode 100644 index 0000000..5d450ef --- /dev/null +++ b/.github/workflows/compare_script_to_course.yml @@ -0,0 +1,60 @@ +name: Compare SCT Commands + +on: + pull_request: + workflow_dispatch: + inputs: + text_url: + description: "URL to text file (e.g. GitHub raw gist link)" + required: true + type: string + +jobs: + compare: + runs-on: macos-latest + env: + YDIFF_OPTIONS: "--unified --pager=cat --color=always --width=120 --nowrap" + + steps: + - name: Check out repo + uses: actions/checkout@v4 + + - name: Install Python (for parsing script) + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install `ydiff` # https://github.com/ymattw/ydiff + run: brew install ydiff + + - name: Download remote text file + run: | + curl -L https://gist.githubusercontent.com/joshuacwnewton/3c554bf27111cf0020e5c124b66448c4/raw/ff08cbcf7738941008eca0fa54e024d98eea24e8/gistfile1.txt -o remote.txt + echo "✅ Downloaded remote file:" + wc -l remote.txt + + - name: Extract commands from remote file + run: | + python3 .github/workflows/scripts/extract_sct.py remote.txt -o remote_cmds.txt + sort -u remote_cmds.txt > remote_cmds_sorted.txt + echo "✅ Extracted $(wc -l < remote_cmds_sorted.txt) commands from remote file" + + - name: Extract commands from local batch script + run: | + python3 .github/workflows/scripts/extract_sct.py single_subject/batch_single_subject.sh -o local_cmds.txt + sort -u local_cmds.txt > local_cmds_sorted.txt + echo "✅ Extracted $(wc -l < local_cmds_sorted.txt) commands from local script" + + - name: Diff commands + run: | + echo "🔍 Diffing remote vs local..." + diff -u local_cmds_sorted.txt remote_cmds_sorted.txt > diff.txt || true + ydiff < diff.txt + + - name: Upload results as artifacts + uses: actions/upload-artifact@v4 + with: + name: command-diff-output + path: | + remote_cmds_sorted.txt + local_cmds_sorted.txt diff --git a/.github/workflows/scripts/extract_sct.py b/.github/workflows/scripts/extract_sct.py new file mode 100644 index 0000000..7cca3c7 --- /dev/null +++ b/.github/workflows/scripts/extract_sct.py @@ -0,0 +1,40 @@ +import argparse +from pathlib import Path + + +def extract_sct_commands(paths, output=None): + results = [] + + for path in paths: + with open(path, "r", encoding="utf-8") as f: + for line in f: + stripped = line.lstrip() + if stripped.startswith("# sct_"): + stripped = stripped[2:] + # Find relavent SCT commands to compare + if (stripped.startswith("sct_") + # sct commands must have command + arg + value (3) + # this excludes slide subtitles like "sct_slide ..." + and len(stripped.split(" ")) >= 3 + # exclude lines with <> which are likely placeholders + and not ("<" in stripped and ">" in stripped) + # exclude sct_download_data (data already present) + and not stripped.startswith("sct_download_data") + # exclude sct_run_batch (handled in .yml workflow) + and not stripped.startswith("sct_run_batch")): + results.append(stripped.rstrip()) + + if output: + Path(output).write_text("\n".join(results), encoding="utf-8") + else: + print("\n".join(results)) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Extract SCT commands " + "from TXT files.") + parser.add_argument("files", nargs="+", help="Input text files") + parser.add_argument("-o", "--output", help="Optional output file") + args = parser.parse_args() + + extract_sct_commands(args.files, args.output) From 33fcc22851212cd280bb29695766d7727c5afd9e Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Wed, 19 Nov 2025 11:23:01 -0500 Subject: [PATCH 03/22] Replace `sct_label_vertebrae` with disc labels from `totalspineseg` --- single_subject/batch_single_subject.sh | 31 +++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/single_subject/batch_single_subject.sh b/single_subject/batch_single_subject.sh index 3dd0ab3..96ab911 100755 --- a/single_subject/batch_single_subject.sh +++ b/single_subject/batch_single_subject.sh @@ -63,8 +63,14 @@ sct_deepseg -h # Vertebral labeling # ====================================================================================================================== -# Vertebral labeling -sct_label_vertebrae -i t2.nii.gz -s t2_seg.nii.gz -c t2 -qc ~/qc_singleSubj +# Vertebral disc labeling +sct_deepseg totalspineseg -step1-only -i t2.nii.gz -qc ~/qc_singleSubj + +# Full spinal segmentation (Vertebrae, Intervertebral discs, Spinal cord and Spinal canal) +# Segment using totalspineseg +sct_deepseg totalspineseg -i t2.nii.gz -qc ~/qc_singleSubj +# Check results using FSLeyes +fsleyes t2.nii.gz -cm greyscale t2_step1_canal.nii.gz -cm YlOrRd -a 70.0 t2_step1_cord.nii.gz -cm YlOrRd -a 70.0 t2_step1_levels.nii.gz -cm subcortical -a 70.0 t2_step1_output.nii.gz -cm subcortical -a 70.0 t2_step2_output.nii.gz -cm subcortical -a 70.0 & # 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 @@ -80,11 +86,11 @@ sct_label_vertebrae -i t2.nii.gz -s t2_seg.nii.gz -c t2 -qc ~/qc_singleSubj # ====================================================================================================================== # 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 +sct_process_segmentation -i t2_seg.nii.gz -vert 3:4 -discfile t2_step1_levels.nii.gz -o csa_c3c4.csv # 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 +sct_process_segmentation -i t2_seg.nii.gz -vert 3:4 -discfile t2_step1_levels.nii.gz -perlevel 1 -o csa_perlevel.csv # 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 +sct_process_segmentation -i t2_seg.nii.gz -z 30:35 -discfile t2_step1_levels.nii.gz -perslice 1 -o csa_perslice.csv # A drawback of vertebral level-based CSA is that it doesn’t consider neck flexion and extension. # To overcome this limitation, the CSA can instead be computed using the distance to a reference point. @@ -96,7 +102,7 @@ sct_process_segmentation -i t2_seg.nii.gz -pmj t2_pmj.nii.gz -pmj-distance 64 -p # The above commands will output the metrics in the subject space (with the original image's slice numbers) # However, you can get the corresponding slice number in the PAM50 space by using the flag `-normalize-PAM50 1` -sct_process_segmentation -i t2_seg.nii.gz -vertfile t2_seg_labeled.nii.gz -perslice 1 -normalize-PAM50 1 -o csa_PAM50.csv +sct_process_segmentation -i t2_seg.nii.gz -discfile t2_step1_levels.nii.gz -perslice 1 -normalize-PAM50 1 -o csa_PAM50.csv @@ -127,7 +133,7 @@ sct_compute_compression -i t2_compressed_seg.nii.gz -vertfile t2_compressed_seg_ cd ../t2 # 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 +sct_label_utils -i t2_step1_levels.nii.gz -keep 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 @@ -137,14 +143,14 @@ sct_qc -i t2.nii.gz -s t2_labels_vert.nii.gz -p sct_label_utils -qc ~/qc_singleS #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 inter-vertebral disc. E.g. Label 3: C2/C3, Label 4: C3/C4, etc." # 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 +sct_register_to_template -i t2.nii.gz -s t2_seg.nii.gz -ldisc 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. # Register t2->template with modified parameters (advanced usage of `-param`) -sct_register_to_template -i t2.nii.gz -s t2_seg.nii.gz -l t2_labels_vert.nii.gz -qc ~/qc_singleSubj -ofolder advanced_param -c t2 -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 +sct_register_to_template -i t2.nii.gz -s t2_seg.nii.gz -ldisc t2_labels_vert.nii.gz -qc ~/qc_singleSubj -ofolder advanced_param -c t2 -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 # Register t2->template with large FOV (e.g. C2-L1) using `-ldisc` option -# sct_register_to_template -i t2.nii.gz -s t2_seg.nii.gz -ldisc t2_seg_labeled_discs.nii.gz -c t2 +# sct_register_to_template -i t2.nii.gz -s t2_seg.nii.gz -ldisc t2_step1_levels.nii.gz -c t2 # Register t2->template in compressed cord (example command) # In case of highly compressed cord, the algo columnwise can be used, which allows for more deformation than bsplinesyn. @@ -426,11 +432,6 @@ sct_deepseg sc_canal_t2 -i t2.nii.gz -qc ~/qc_singleSubj # Check results using FSLeyes fsleyes t2.nii.gz -cm greyscale t2_canal_seg_seg.nii.gz -cm red -a 70.0 & -# Full spinal segmentation (Vertebrae, Intervertebral discs, Spinal cord and Spinal canal) -# Segment using totalspineseg -sct_deepseg totalspineseg -i t2.nii.gz -qc ~/qc_singleSubj -# Check results using FSLeyes -fsleyes t2.nii.gz -cm greyscale t2_step1_canal.nii.gz -cm YlOrRd -a 70.0 t2_step1_cord.nii.gz -cm YlOrRd -a 70.0 t2_step1_levels.nii.gz -cm subcortical -a 70.0 t2_step1_output.nii.gz -cm subcortical -a 70.0 t2_step2_output.nii.gz -cm subcortical -a 70.0 & # Segment the spinal nerve rootlets sct_deepseg rootlets -i t2.nii.gz -qc ~/qc_singleSubj From a6d80ca5febfa94cb8e4605571a03128c00a137d Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Wed, 19 Nov 2025 11:23:40 -0500 Subject: [PATCH 04/22] Replace `sct_deepseg_gm` with `sct_deepseg graymatter` --- single_subject/batch_single_subject.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/single_subject/batch_single_subject.sh b/single_subject/batch_single_subject.sh index 96ab911..b8251f3 100755 --- a/single_subject/batch_single_subject.sh +++ b/single_subject/batch_single_subject.sh @@ -243,7 +243,7 @@ sct_register_to_template -i t2_lumbar.nii.gz -s t2_lumbar_seg.nii.gz -ldisc t2_l # 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 +sct_deepseg graymatter -i t2s.nii.gz -qc ~/qc_singleSubj # Spinal cord segmentation sct_deepseg spinalcord -i t2s.nii.gz -qc ~/qc_singleSubj # Subtract GM segmentation from cord segmentation to obtain WM segmentation From 06c0161bc067d7521edf33cf61915b1eac5a769f Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Wed, 19 Nov 2025 11:24:19 -0500 Subject: [PATCH 05/22] Replace `sct_deepseg_sc` with `sct_deepseg spinalcord` --- single_subject/batch_single_subject.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/single_subject/batch_single_subject.sh b/single_subject/batch_single_subject.sh index b8251f3..63734a8 100755 --- a/single_subject/batch_single_subject.sh +++ b/single_subject/batch_single_subject.sh @@ -393,7 +393,7 @@ sct_smooth_spinalcord -i t1.nii.gz -s t1_seg.nii.gz # Tips: use flag "-sigma" to specify smoothing kernel size (in mm) # Second-pass segmentation using the smoothed anatomical image -sct_deepseg_sc -i t1_smooth.nii.gz -c t1 -qc ~/qc_singleSubj +sct_deepseg spinalcord -i t1_smooth.nii.gz -qc ~/qc_singleSubj # 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 From b31a5bd2ff00789cbe673bd342b35ee18ba6596c Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Wed, 19 Nov 2025 11:24:41 -0500 Subject: [PATCH 06/22] Add missing lumbar `sct_qc` command --- single_subject/batch_single_subject.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/single_subject/batch_single_subject.sh b/single_subject/batch_single_subject.sh index 63734a8..d4c5a50 100755 --- a/single_subject/batch_single_subject.sh +++ b/single_subject/batch_single_subject.sh @@ -232,6 +232,9 @@ sct_deepseg sc_lumbar_t2 -i t2_lumbar.nii.gz -qc ~/qc_singleSubj # sake of reproducing the results in the tutorial. sct_label_utils -i t2_lumbar.nii.gz -create 27,76,187,17:27,79,80,60 -o t2_lumbar_labels.nii.gz -qc ~/qc_singleSubj +# generate a QC report for the lumbar labels +sct_qc -i t2_lumbar.nii.gz -s t2_lumbar_labels.nii.gz -p sct_label_utils -qc ~/qc_singleSubj + # Register the image to the template using segmentation and labels 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 From bd6c4c1b0ddf262e173eceb3fa540dd2a41fba59 Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Wed, 19 Nov 2025 11:25:35 -0500 Subject: [PATCH 07/22] Uncomment `sct_analyze_lesion -f` command --- single_subject/batch_single_subject.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/single_subject/batch_single_subject.sh b/single_subject/batch_single_subject.sh index d4c5a50..d0b62a3 100755 --- a/single_subject/batch_single_subject.sh +++ b/single_subject/batch_single_subject.sh @@ -423,7 +423,8 @@ sct_analyze_lesion -m t2_lesion_seg.nii.gz -s t2_sc_seg.nii.gz -qc ~/qc_singleSu # Lesion analysis using PAM50 (the -f flag is used to specify the folder containing the atlas/template) # Note: You must go through the "Register to Template" steps (labeling, registration) first # This is because `sct_warp_template` is required to generate the `label` folder used for `-f` -# sct_analyze_lesion -m t2_lesion_seg.nii.gz -s t2_sc_seg.nii.gz -f label -qc ~/qc_singleSubj +sct_warp_template -d t2.nii.gz -w ../t2/warp_template2anat.nii.gz +sct_analyze_lesion -m t2_lesion_seg.nii.gz -s t2_sc_seg.nii.gz -f label -qc ~/qc_singleSubj # Segment the spinal cord on gradient echo EPI data cd ../fmri/ From 0eb1aec26ed43ab8812d0b8adcd9bed5d82aa328 Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Wed, 19 Nov 2025 11:26:03 -0500 Subject: [PATCH 08/22] Add space to commented-out `sct_label_utils` command --- single_subject/batch_single_subject.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/single_subject/batch_single_subject.sh b/single_subject/batch_single_subject.sh index d0b62a3..fb3fba1 100755 --- a/single_subject/batch_single_subject.sh +++ b/single_subject/batch_single_subject.sh @@ -140,7 +140,7 @@ sct_qc -i t2.nii.gz -s t2_labels_vert.nii.gz -p sct_label_utils -qc ~/qc_singleS # OPTIONAL: 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 command below, we will create labels at the inter-vertebral # 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 inter-vertebral disc. E.g. Label 3: C2/C3, Label 4: C3/C4, etc." +# 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 inter-vertebral disc. E.g. Label 3: C2/C3, Label 4: C3/C4, etc." # Register t2->template. sct_register_to_template -i t2.nii.gz -s t2_seg.nii.gz -ldisc t2_labels_vert.nii.gz -c t2 -qc ~/qc_singleSubj From 4ab8bbcb1bd2754bcaed62f1fe6080f440324446 Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Wed, 19 Nov 2025 11:31:23 -0500 Subject: [PATCH 09/22] Add new `sct_compute_ascor` command --- single_subject/batch_single_subject.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/single_subject/batch_single_subject.sh b/single_subject/batch_single_subject.sh index fb3fba1..5780d85 100755 --- a/single_subject/batch_single_subject.sh +++ b/single_subject/batch_single_subject.sh @@ -436,6 +436,9 @@ sct_deepseg sc_canal_t2 -i t2.nii.gz -qc ~/qc_singleSubj # Check results using FSLeyes fsleyes t2.nii.gz -cm greyscale t2_canal_seg_seg.nii.gz -cm red -a 70.0 & +# Compute aSCOR (Adapted Spinal Cord Occupation Ratio) +# i.e. Spinal cord to canal ratio using the canal seg +sct_compute_ascor -i-SC t2_seg.nii.gz -i-canal t2_canal_seg.nii.gz -perlevel -1 -o ascor.csv # Segment the spinal nerve rootlets sct_deepseg rootlets -i t2.nii.gz -qc ~/qc_singleSubj From 53665c339b2877be75bbb8c75e27fcd9216f92d8 Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Wed, 5 Nov 2025 13:59:49 -0500 Subject: [PATCH 10/22] Temporarily commit course text to make testing easier --- .../workflows/compare_script_to_course.yml | 2 +- remote.txt | 3145 +++++++++++++++++ 2 files changed, 3146 insertions(+), 1 deletion(-) create mode 100644 remote.txt diff --git a/.github/workflows/compare_script_to_course.yml b/.github/workflows/compare_script_to_course.yml index 5d450ef..2b3fb42 100644 --- a/.github/workflows/compare_script_to_course.yml +++ b/.github/workflows/compare_script_to_course.yml @@ -29,7 +29,7 @@ jobs: - name: Download remote text file run: | - curl -L https://gist.githubusercontent.com/joshuacwnewton/3c554bf27111cf0020e5c124b66448c4/raw/ff08cbcf7738941008eca0fa54e024d98eea24e8/gistfile1.txt -o remote.txt + # curl -L https://gist.githubusercontent.com/joshuacwnewton/3c554bf27111cf0020e5c124b66448c4/raw/ff08cbcf7738941008eca0fa54e024d98eea24e8/gistfile1.txt -o remote.txt echo "✅ Downloaded remote file:" wc -l remote.txt diff --git a/remote.txt b/remote.txt new file mode 100644 index 0000000..8348351 --- /dev/null +++ b/remote.txt @@ -0,0 +1,3145 @@ +SCT Course, December 8-9 2025, (Virtual) + +Updated: 2025-11-17 +Course material for SCT v7.2 +Welcome to the SCT course! + +(Reminder for Presenter: +Open the slide deck link in a new logged-out (incognito/private) window to get the “View mode” for clean presentation with easy triple-click copy-paste.) +Record ZOOM +Present team: +core developers: Joshua Newton, Mathieu Guay-Paquet +presenters: Sandrine Bédard, Jan Valosek, Naga Karthik, Nathan Molinier + + Questions during the course +Zoom ‘general’ chat + + Printing these slides +If you wish to print these slides with presenter notes, do the following: +File -> Print preview +In the newly visible menu bar, click on "1 slide without notes" and change to "1 slide with notes" +Uncheck "Include skipped slides". +Download as PDF + + + Outline +4 +Day One + +Introduction +Installation +Segmentation +Vertebral labeling +Shape-based analysis +Registration to template +Register additional contrasts +Day Two + + Gray matter segmentation +Atlas-based analysis +Diffusion-weighted MRI +Functional MRI +Other features +Analysis pipelines with SCT +New and upcoming features +Conclusion +Here is the outline of the course. Each chapter will start with a brief theory, then will be followed by hands-on exercise that we will do together. + + + + Introduction +5 +Day One + +Introduction +Installation +Segmentation +Vertebral labeling +Shape-based analysis +Registration to template +Register additional contrasts +Day Two + + Gray matter segmentation +Atlas-based analysis +Diffusion-weighted MRI +Functional MRI +Other features +Analysis pipelines with SCT +New and upcoming features +Conclusion +This section introduces SCT software, what it can be used for, and some example applications. + + Quantitative MRI of the spinal cord +6 +Spectroscopy +Metabolism +Functional MRI +Neuronal activity +Functional MRI, DTI, MTR, T1, T2, etc. +Diagnosis/prognosis traumas, neurological diseases, cancers +Objective biomarkers for testing new drugs +Diffusion MRI +Axon integrity +Conventional MRI +Pathology +Magnetization transfer +Myelin integrity +MRI features several techniques that provide sensitive and specific metrics to the function, metabolism or microstructure of the central nervous system. For example, diffusion and magnetization transfer were shown to correlate with myelin content, and are therefore relevant for diagnosis applications in neurodegenerative diseases such as multiple sclerosis. + + Image processing +7 +How to process spinal cord multi-parametric MRI data? +brain data +? +spinal cord data +These techniques require advanced image processing methods. This is why for the past twenty years or so, several software packages have been developed to process brain multi-parametric MRI data. Some of these software, such as FSL, SPM or AFNI, are very popular and provide international researchers with a common analysis framework, enabling them to reproduce and compare research results. Such cross-validations are essential steps for further use in clinical diagnosis or by pharmaceutical companies for drug development. +While the same is true for spinal cord quantitative MRI, there has been no publicly-available and widely-distributed software dedicated to the spinal cord. Moreover, brain software cannot readily be applied to spinal cord data, because atlases and image features are very different. + + 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 +This lack of unified processing tools motivated the development of the Spinal Cord Toolbox, or SCT. + +Registration framework + Overview of SCT +9 +and many more features… +Segmentation +C3 +C5 +T1 +C1 +Template and atlas +2D slice-by-slice +Regularized across slices & time +Robust for DWI (group-wise) +Lesion analysis +Lesion Length +Shape-based analysis +_Orientation___________ +_Solidity ________ +_Eccentricity___________ +__ AP__ diameter +_Area__ _____ +_ _RL__ diameter +SCT +In brief, SCT features specific segmentation tools for the spinal cord, a multi-modal template and atlas, a framework to register multi-parametric MRI data to the template, and various tools for atlas-based analysis, motion correction, etc. + + 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. + +Review article: +Valošek & Cohen-Adad. Reproducible Spinal Cord Quantitative MRI Analysis with the Spinal Cord Toolbox. Magn Reson Med Sci 2024 + Template and Atlas: +Valošek* & Bédard* et al. A database of the healthy human spinal cord morphometry in the PAM50 template space. Imaging Neuroscience 2024 +De Leener et al. PAM50: Unbiased multimodal template of the brainstem and spinal cord aligned with the ICBM152 space. Neuroimage 2018 +Lévy et al. White matter atlas of the human spinal cord with estimation of partial volume effect. Neuroimage 2015 +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 + Segmentation: +Karthik* & Valošek* et al. SCIseg: Automatic Segmentation of Intramedullary Lesions in Spinal Cord Injury on T2-weighted MRI Scans Radiology AI 2024 +Valošek et al. Automatic Segmentation of the Spinal Cord Nerve Rootlets. Imaging Neuroscience 2024 +Bedard et al. Towards contrast-agnostic soft segmentation of the spinal cord. Arxiv Preprint 2023 +Gros et al. Automatic segmentation of the spinal cord and intramedullary multiple sclerosis lesions with convolutional neural networks. Neuroimage 2019 +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 +Dupont et al. Fully-integrated framework for the segmentation and registration of the spinal cord white and gray matter. Neuroimage 2017 +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 + Registration: +Beal E et al. Contrast-agnostic deep learning–based registration pipeline: Validation in spinal cord multimodal MRI data. Aperture Neuro 2023 +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 +https://spinalcordtoolbox.com/user_section/citing_sct.html +If you use SCT, please always cite the main SCT reference: De Leener et al. SCT: Spinal Cord Toolbox, an open-source software for processing spinal cord MRI data. Neuroimage 2017. + +Most of the methods implemented in SCT have been validated and published in peer-reviewed journals. For an exhaustive list of the references pertaining to SCT, see: +https://spinalcordtoolbox.com/user_section/citing_sct.html + + Applications (350+ 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. Neuroscience 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 +https://spinalcordtoolbox.com/overview/studies.html +Since its public release in 2014, SCT has been used in various applications, including structural MRI, fMRI and in various diseases such as MS, ALS and spinal cord injury. For an exhaustive list of the references pertaining to SCT, see: https://spinalcordtoolbox.com/overview/studies.html + + 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.) +12 +Yiannakas et al., Neuroimage Clinical 2015 +Application of SCT +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 +As a concrete example application, SCT was used to measure cord cross-sectional area (CSA) in the cervical cord. The fully automatic method of SCT showed similar results than the semi-automatic method of Horsfield et al. Having a fully-automatic means of measuring CSA removes user bias and makes it possible to analyse large database in a fast and reproducible way. + + Mapping MS lesions in the cord +13 +Eden et al., Brain 2019 +Application of SCT +Lesion Probability Map +N=642 (13 sites) +In this study, 642 patients from 13 clinical centers were recruited. Lesions were segmented by neuroradiologists, then all data were non-linearly registered to the PAM50 template in order to derive probability maps of MS lesion location in the cervical cord. + + Gray matter atrophy in ALS +14 +Paquin et al., AJNR 2017 +Application of SCT +Automatic GM segmentation +GM atrophy is a better discriminator of ALS than cord atrophy +Prediction at 1 year +Perone, Sci. Reports 2018 +In this study, SCT was used to segment the spinal gray matter of patients at an early stage of Amyotrophic Lateral Sclerosis (ALS). It was then demonstrated that spinal gray matter atrophy is a better biomarker than spinal cord atrophy, for distinguishing patients from healthy controls, and for 6-months prognosis of motor scores. + + Tract-based analysis in stroke patients +15 +Karbasforoushan et al. Nat. Commun. 2019 +Application of SCT +In this study involving patients with unilateral stroke, diffusion MRI was used to assess the integrity of the brainstem and the cervical spinal cord. Tract-based analysis performed with SCT helped identify altered sensorimotor pathways post-stroke in those patients. These results have implications for rehabilitation interventions post unilateral stroke. + + Combining PET-MRI to study pain +16 +Albrecht et al. Pain 2018 +Application of SCT +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. +Here, SCT was used for the first time on a combined PET-MR study. PET Standardized Uptake Values (SUVs) were extracted in the spinal cord at specific vertebral levels, based on the anatomical MRI, after registration with the PAM50 template. These results implicate immunoactivation at multiple levels of the nervous system as a potentially important and clinically relevant mechanism in human radicular pain, and suggest that therapies targeting immune cell activation may be beneficial for chronic pain patients. + + fMRI of the spinal cord +17 + + Applications of SCT + + 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 +19 +Cohen-Adad et al., Nature Protocols 2021 +Finally, we would just like to highlight a related project that has powered some of the aforementioned studies alongside with SCT. + +Spine generic is an analysis protocol for quantitative analysis of the spinal cord. Spine generic provides standardized analysis protocols for assessing spinal cord macrostructural and microstructural integrity. + + Spine Generic: Multi-center qMRI study +20 +Cohen-Adad et al., Scientific Data (2021) +Application of SCT +Multi-site (n=43), multi-subject (n=267) +Fractional Anisotropy (FA) averaged in WM between C2-C5 +Another example is a multi-center study, featuring two publicly-available datasets, which were acquired using the spine generic protocol. One acquired on a "traveling" single subject, scanned across 19 centers. The second dataset consists of 43 sites which scanned about 6 subjects, for a total of 267 subjects (260 when published). The dataset is well-curated and uses the latest technologies, such as the BIDS and Datalad for accessing the data. + + + + Distribution +OS supported +macOS (Intel and M1/M2/M3/M4) +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) +21 +Testing +Extensive testing: https://github.com/spinalcordtoolbox/spinalcordtoolbox/actions +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 +Here are some technical features. + + Course convention +22 +Links, references, etc. will go here +sct_function_name +Mandatory for this course +Try this at home +name of SCT function +Tips! +NEW +in v7.2 +For the remaining sections of the course, we will be using some common visual elements. + +In the interest of time, not all hands-on examples will be run today (indicated by the red dot), but they are still included in this document for you to try later. + + Installation +23 +Day One + +Introduction +Installation +Segmentation +Vertebral labeling +Shape-based analysis +Registration to template +Register additional contrasts +Day Two + + Gray matter segmentation +Atlas-based analysis +Diffusion-weighted MRI +Functional MRI +Other features +Analysis pipelines with SCT +New and upcoming features +Conclusion +In this section we will learn how to install SCT. + + Recommended terminal +24 +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.) +Before we install SCT, we will talk a little bit about terminals. You will need to use a terminal program to install SCT and run SCT commands. + + Installation of stable release +25 +Instructions for macOS: https://spinalcordtoolbox.com/user_section/installation/mac.html +Installation for Linux: https://spinalcordtoolbox.com/user_section/installation/linux.html +Instructions for Windows: https://spinalcordtoolbox.com/user_section/installation/windows.html +Installation instructions on Docker & Apptainer (NEW!) +https://spinalcordtoolbox.com/stable/user_section/installation/docker.html +https://spinalcordtoolbox.com/stable/user_section/installation/apptainer.html +Note: After installing, make sure to open a fresh, brand new terminal window, then run the following commands to check if SCT has been installed correctly: +sct_check_dependencies +echo $SCT_DIR +# For the “echo” command, you should see SCT’s installation directory in the output + +NEW +in v7.2 +If you prefer to install the development version from Github, instructions can be found there: https://spinalcordtoolbox.com/user_section/installation/linux.html#option-2-install-from-github-development +The advantage of the “github-master” version is that it is always up-to-date with the latest developments. + +ℹ️ As of v6.3 there is a cuda GPU installation mode for running deep learning models faster. More information at: https://github.com/spinalcordtoolbox/spinalcordtoolbox/wiki/Contributing%3A-Installing-SCT-for-GPU +This is an experimental installation, we would love to hear your feedback. + +https://github.com/spinalcordtoolbox/spinalcordtoolbox/pull/4421 + + Resize your terminal +26 +100 chars +SCT display is optimized for Terminal window with 100 characters wide (mostly to display help). + +So, now that we’ve confirmed SCT has been installed correctly, it is a good time to make your terminal window a bit larger. + + Basic Unix commands +27 +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 parent directory +cd .. +# List contents of ‘dir_name’ +ls dir_name +# Cleanup files/directories +rm dir_name/example.txt +rm -r dir_name + + + +Triple-click with left mouse button to select from this slide, then copy and paste in your Terminal +You don’t need to be an expert of Unix commands to use SCT. However, basic commands are needed to be able to navigate in your directories and files. + + Download course material +28 +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 +Download publicly available example data for the purpose of this course. + +Important: we recommend that you do not process data under the sct installation directory. Go outside of SCT install folder before doing your analyses. E.g.: go to your home folder with: cd ~ + + batch_single_subject.sh +29 +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: +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 + +A little bit of background information before we begin +The setup for the SCT course is now complete. + +However, before we begin running SCT commands on the course data, we have a little more background information to cover. + + 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 +31 +You can also inspect output images using a NIfTI image viewer. + +SCT is particularly adapted to both fsleyes (comes with FSL) and ITKSnap, because each SCT command ends with a link to copy/paste and open in those viewers (N.B: this also works with the older fslview). + + NIfTI file formats (.nii vs .nii.gz) +Stands for “Neuroimaging Informatics Technology Initiative” +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 +32 +Speaking of NIfTI images, here is a quick explainer about NIfTI image formats. + +.nii stands for “NiFTi image”. The extra .gz means that the NiFTi file has been “GZipped” (compressed). + +Save physical storage, use nii.gz! + + 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: +33 +/home/Julien superduper folder/my file name.nii.gz +Use dashes (-) and/or 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 +... +When working with SCT, you will often want to customize the output filename using the -o flag. When choosing filenames, please avoid using spaces. + +Note: underscores are better for double clicking. + +Onto the first section of the SCT Course + + Segmentation +35 +Day One + +Introduction +Installation +Segmentation +Vertebral labeling +Shape-based analysis +Registration to template +Register additional contrasts +Day Two + + Gray matter segmentation +Atlas-based analysis +Diffusion-weighted MRI +Functional MRI +Other features +Analysis pipelines with SCT +New and upcoming features +Conclusion +With that background out of the way, now we can begin the SCT course proper. + +In this first section, we will learn how to segment the spinal cord contour. + +Theory +Here we will quickly review the theory behind spinal cord segmentation in SCT + + Spinal cord segmentation +New segmentation tool: +“contrast-agnostic” (2024) +Command: sct_deepseg +Legacy methods: +DeepSegSC (2019) +Command: sct_deepseg_sc +PropSeg (2014) +Command: sct_propseg +37 +Anat (T2w or T1w) +Our contrast-agnostic model was introduced in 2024, and is our recommended approach for spinal cord segmentation. It is accessed via the sct_deepseg command. + +Earlier methods include DeepSegSC, launched in 2019, which can be accessed with the command sct_deepseg_sc, and PropSeg, developed in 2014, which is run using sct_propseg. These tools represent the evolution of segmentation technologies over the years. + + Limitations of contrast-specific models +Historically, automatic SC seg has been limited to specific contrasts (T1w, T2w, T2*w, DWI) +Each contrast had its own “deep learning model” +New contrasts required new models to be trained +T1 “like” +T2 “like” +T1w +dwi +fmri +T2w +mt +-c t1 +-c t2 +DWI “like” +-c dwi +T2* “like” +-c t2s +T2*w +38 + + Limitations of contrast-specific models +CSA across MRI contrasts +✅ Stable CSA +Cross-sectional area (CSA) +New model! +39 +Contrast-specific models +sct_deepseg spinalcord +39 +⚠️ CSA varies +Bédard, Naga Karthik et al. Medical Image Analysis 2025 +# Presented by Sandrine +Not only having contrasts-specific models is limiting on the user-point, but it also provides different morphometrics measures across MRI contrasts. For example, we can compute the spinal cord cross-sectional area averaged at C2-C3 vertebral levels and we obtain different CSA values across contrasts But with the new model, we obtain stable CSA across 6 differents contrasts. + + Contrast-agnostic segmentation + + + + + + +Train a single model using many contrasts +Use “soft” GT (averaged across contrasts) during training → same GT for all contrasts +sct_deepseg spinalcord +Bédard, Naga Karthik et al. Medical Image Analysis 2025 +40 +# Presented by Sandrine +To do so, we first trained a model using many contrast instead on just one +And, to achieve stable CSA across contrast, we created an average segmentation for each subjects of 6 contrasts to get one unique soft ground truth and to use that for training instead. + +Hands-on +# Presented by Julien + + +Spinal cord segmentation +42 +sct_deepseg spinalcord +# Go to T2 contrast folder +cd data/t2 +# Try cord segmentation using deep learning. Note the flag "-qc" to generate a QC report of the segmentation. +sct_deepseg spinalcord -i t2.nii.gz -qc ~/qc_singleSubj +# You can also choose your own output filename using the “-o” argument +sct_deepseg spinalcord -i t2.nii.gz -o test/t2_seg_2.nii.gz + +t2 +t2_seg +Note that when running a new sct_deepseg model for the first time, if the model is not installed, it will install it automatically. + +You can inspect the quality of the segmentation via the web QC and/or via your favorite image viewer. + +In general, we recommend using sct_deepseg as the default method for all contrasts, but if you find that it underperforms on your data, then try sct_propseg or sct_deepseg_sc and then decide which method you prefer to use for your data. + +Importantly, you should stick to one method when doing a study, because there might be biases in terms of cord contour definitions between the methods. + + 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 +# Presented by Julien + + + Quality Control (QC) Reports +44 +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 +An important aspect of using tools like SCT is inspecting output images. + +SCT provides a browser-based QC report feature to make this process easier. + + Other segmentation tools +Contrast-agnostic segmentation is SCT’s recommended “general purpose” tool for SC seg +However, you may have a more specific use-case +e.g. mouse, lumbar, MS/SCI lesions, compressed cord, etc. where “general-purpose” tool produces poor results +SCT has other tools you can try: +SCT’s past SC models (sct_propseg, sct_deepseg_sc) +One of sct_deepseg‘s 17 different segmentation models +sct_propseg/sct_deepseg_sc/sct_deepseg + + Model gallery +46 +sct_deepseg +Our team regularly releases new models under sct_deepseg +In recent versions, we’ve added new models for segmentation of: +Lumbar (T2) +SCI lesion (T2) +Spinal rootlets (T2) +We provide a Model gallery +You can also check available models by running: +# List of available models +sct_deepseg -h + + Vertebral labeling +47 +Day Two + + Gray matter segmentation +Atlas-based analysis +Diffusion-weighted MRI +Functional MRI +Other features +Analysis pipelines with SCT +New and upcoming features +Conclusion +Day One + +Introduction +Installation +Segmentation +Vertebral labeling +Shape-based analysis +Registration to template +Register additional contrasts +In this section we will learn about vertebral labeling, which is a necessary step for both shape-based analysis and registration to template. + +Theory + + Disc labeling +49 +[1] Warszawer et al. ResearchGate Preprint (2025) +sct_deepseg totalspineseg +Rationale +Labeling intervertebral discs along the spinal cord is commonly performed to: +Align subjects to a reference space (e.g., a template such as PAM50). +Extract metrics at specific levels (e.g., cross-sectional area or lesion location to study correlations with sensorimotor dysfunctions). + +TotalSpineSeg +Deep learning based +Contrast-agnostic +FOV-agnostic +Robustness towards pathology/artifact + + Conventions for point labels +50 +The images in this slide show the convention used in SCT for point labels specifically. We demonstrate both vertebral mid-body labels and disc labels, as both can be generated by SCT. + +Here, you can see that Value 3 —> C2-C3 disc, Value 4 —> C3-C4 disc, etc. + +Note that label 49 corresponds to the ponto-medullary groove, label 50 corresponds to the ponto-medullary junction, and label 60 corresponds to the new conus medullaris label. These labels exist in the PAM50 template, and are used in special applications, such as computing distance from PMJ along the spinal cord (49/50), or registering lumbar data (60). + +Hands-on + + Label vertebrae/discs +52 +sct_deepseg totalspineseg +# Vertebral labeling (can be used with any MRI contrast) +sct_deepseg totalspineseg -step1-only -i t2.nii.gz -qc ~/qc_singleSubj +# Check QC report: Go to your browser and do "refresh". +# Note: Here, four files are generated: +t2_step1_cord.nii.gz —> soft segmentation of the spinal cord +t2_T1w_step1_canal.nii.gz —> soft segmentation of the spinal canal +t2_T1w_step1_output.nii.gz —> segmentation of the vertebrae, discs, canal and cord +t2_step1_levels.nii.gz —> discs labels +t2 +t2_step1_levels.nii.gz +3 +4 +5 +6 +7 +8 +9 +10 +11 +Two files representing either vertebral or disc levels are output from sct_label_vertebrae. Either of them can be subsequently used for the template registration and/or for computing metrics along the cord. + + Manual discs labeling +53 +sct_label_utils -create-viewer +# If TotalSpineSeg did not work, you might want to do it 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 inter-vertebral disc. E.g. Label 3: C2/C3, Label 4: C3/C4, etc." +t2 +t2_discs.nii.gz +3 +4 +5 +6 +7 +8 +9 +10 +11 +“viewer” +Here, the value “3” in -create-viewer 3 corresponds to the C2-C3 disc, which is the label we would like to create manually. + +If labeling is wrong (e.g., each vertebrae is assigned one or two levels superior than what it should be), initializing the C2-C3 disc can help. In that case, a viewer pops-out and you just have to click at the posterior tip of C2-C3 disc. + + Shape-based analysis +54 +Day Two + + Gray matter segmentation +Atlas-based analysis +Diffusion-weighted MRI +Functional MRI +Other features +Analysis pipelines with SCT +New and upcoming features +Conclusion +Day One + +Introduction +Installation +Segmentation +Vertebral labeling +Shape-based analysis +Registration to template +Register additional contrasts +In this section we will learn to compute the cord CSA across the superior-inferior axis, as well as other shape metrics (such as diameter, eccentricity, solidity, and orientation). + + Compute CSA with disc labels +55 +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 -discfile t2_step1_levels.nii.gz -o csa_c3c4.csv + +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-23 +6.5 +/Users/julien +143:186 +3:4 + 74.9532 +2.4125 +1.2151 +0.2260 +9.8769 +1.5364 +.csv files are easily imported in Excel, Numbers, Python, etc. +NEW +in v7.2 +# Presented by Sandrine +Here for example, we compute the cord cross-sectional area (CSA) and average it between C3 and C4 vertebral levels. When using the “-vert” flag, sct_process_segmentation will look for a vertebral labeling file, which enables to specify the levels on which you would like to compute CSA. This default label file is label/template/PAM50_levels.nii.gz + +By default, sct_process_segmentation will output a file called csa.csv, which contains CSA results (mean and STD) as well as the angles between the cord centerline and the normal to the axial plane. Angle_AP corresponds to the angle about the AP axis, while angle_RL corresponds to the angle about the RL axis. These angles are used to correct the CSA, therefore if you obtain inconsistent CSA values, it it a good habit to verify the value of these angles. + +N.B. If a segmentation is not perfect (e.g., over-segmentation caused by surrounding tissue, or under-segmentation caused by a lesion), then the computed CSA will be impacted. So you want to make sure the spinal cord segmentation is correct in the slices of interest before quantifying CSA. + + Compute CSA per level/slice +56 +sct_process_segmentation +# Aggregate CSA value per level +sct_process_segmentation -i t2_seg.nii.gz -vert 3:4 -discfile t2_step1_levels.nii.gz -perlevel 1 -o csa_perlevel.csv +# Aggregate CSA value per slices +sct_process_segmentation -i t2_seg.nii.gz -z 30:35 -discfile t2_step1_levels.nii.gz -perslice 1 -o csa_perslice.csv +Slice (I->S) +VertLevel +MEAN(area) +STD(area) +143:164 +4 +76.5782 +1.5781 +165:186 +3 +73.3282 +1.9668 +Slice (I->S) +VertLevel +MEAN(area) +STD(area) +30 +10 +41.1479 +0.0 +31 +10 +41.7494 +0.0 +32 +10 +39.9284 +0.0 +33 +10 +40.6677 +0.0 +34 +9 +41.9585 +0.0 +35 +9 +41.3494 +0.0 +# Presented by Sandrine +The flag -perlevel is used to enable/disable metric output per individual vertebral level, while the flag -perslice is used to enable/disable metric output per individual slice. + +Notes for -perslice: +We still specify -vertfile in order to fill in the information for the VertLevel column +STD is 0.0 because no averaging is being performed (since these are individual slices) + + Compute CSA using PMJ +57 +Bédard et al. Front. Neuroimaging 2022 +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 +Slice (I->S) +DistancePMJ +MEAN(area) +STD(area) +164:201 +64.0 +72.8608 +1.96212 +# Presented by Sandrine +A drawback of vertebral level-based CSA is that it doesn’t consider neck flexion and extension. + +To overcome this limitation, the CSA can instead be computed using the distance to a reference point. Here, we use the Pontomedullary Junction (PMJ), since the distance from the PMJ along the centerline of the spinal cord will vary depending on the position of the neck. + +First, the PMJ is detected. Then, this PMJ label is passed to sct_process_segmentation using the -pmj flag. + +N.B. This feature is only available on SCT v5.4 and higher. + + Shape analysis: Other metrics +Valošek, Bédard et al. NeuroLibre 2023; Imaging Neuroscience 2024 +Martin et al. BMJ Open 2018 +Horáková M et al. QIMS 2022 +sct_process_segmentation +MEAN(diameter_AP) +MEAN(diameter_RL) +MEAN(eccentricity) +MEAN(orientation) +MEAN(solidity) +5.1653 +9.8062 +0.9270 +8.1536 +0.9221 +58 +# Presented by Jan +The output of sct_process_segmentation also includes metrics to analyse the shape of the spinal cord in the axial plane, such as AP diameter, RL diameter, eccentricity, solidity, and orientation. These are of particular interest for studying spinal cord compression. See [Martin et al. BMJ Open 2018] and [Horáková M et al. QIMS 2022] for example applications in degenerative cervical myelopathy. + +The left panel shows a sagittal T2w image of a subject with spinal cord compression. The compression is highlighted by the red arrow and shown in detail in the axial image below. + +The red dashed lines in the charts illustrate how the shape metrics change at the compression slice. + + Shape analysis: normalization +sct_process_segmentation -normalize-PAM50 +Slice (I->S) +VertLevel +MEAN(area) +MEAN(diameter_AP) +MEAN(diameter_RL) +MEAN(eccentricity) +MEAN(solidity) +923 +2 +70.0814 +7.9577 +11.1847 +0.7027 +0.0200 +59 +# Bring shape metrics to the PAM50 anatomical dimensions +sct_process_segmentation -i t2_seg.nii.gz -discfile t2_step1_levels.nii.gz -perslice 1 -normalize-PAM50 1 -o csa_PAM50.csv +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! +Valošek, Bédard et al. NeuroLibre 2023; Imaging Neuroscience 2024 +# Presented by Jan +The sct_process_segmentation script allows you to bring/normalize the shape metrics to the anatomical dimensions of the PAM50 spinal cord template. + +The PAM50 template will be covered in detail in the next section. But, briefly, the spinal cord template is a standard reference space created by a combination of data from many subjects. + +The normalization is done by adding the -normalize-PAM50 flag to the sct_process_segmentation command. + +Normalizing the shape metrics into the PAM50 template space is relevant, for example, during group-level analysis. + + Shape analysis: normalization +sct_process_segmentation -normalize-PAM50 +60 +Once the metrics are normalized into the PAM50 anatomical dimensions, you can compare them with a database of healthy normative values +single subject +CSA +Valošek, Bédard et al. NeuroLibre 2023; Imaging Neuroscience 2024 +x +Slice (I->S) +VertLevel +MEAN(area) +MEAN(diameter_AP) +MEAN(diameter_RL) +MEAN(eccentricity) +MEAN(solidity) +923 +2 +70.0814 +7.9577 +11.1847 +0.7027 +0.0200 +# Presented by Jan +Another use of normalizing shape metrics to the PAM50 template space is to compare against a database of healthy normative values. + +The blue curves in the figure show the mean and standard deviation of the cross-sectional area across vertebral levels computed from a dataset of 203 healthy controls (spine-generic multi-subject dataset). + +The table at the bottom presents shape metrics computed for our subject and normalized to the PAM50 anatomical dimensions. + +Since all values are now in the same anatomical dimensions, you can compare the subject's CSA (the red cross) with the normative values (the blue cross). + + + Application: detection of cord compression +sct_process_segmentation -normalize-PAM50 +61 +Valošek, Bédard et al. NeuroLibre 2023; Imaging Neuroscience 2024 +Compression C5/C6 +# Presented by Jan + +This slide shows an application for the detection of spinal cord compression. +The blue curves show the mean and standard deviation of the AP diameter across vertebral levels computed from a dataset of 203 healthy controls (spine-generic multi-subject dataset). +The red curve shows the AP diameter for a subject with spinal cord compression. We can see the decrease of the AP diameter at the compression level at the C5/C6 intervertebral disc. + + + Quantify spinal cord compression +Valošek, Bédard et al. Imaging Neuroscience 2024 +Bédard, Valošek et al. Spine J. 2025 +sct_compute_compression +62 +MSCC: Maximum spinal cord compression +# Presented by Jan +The sct_compute_compression script is another tool related to spinal cord shape analysis. It allows you to compute metrics quantifying spinal cord compression. + +The computation is based on the MSCC (maximum spinal cord compression) formula. +The shape metrics (such as AP diameter) at the level of compression (red arrow in the left sagittal T2w image) are normalized using the non-compressed levels above and below the compression site. + +If the -normalize-hc flag is used, the shape metrics are normalized using a database of healthy controls, providing MSCC_norm (accounting for the intra-subject variability). Additionally, you can filter the healthy database to account for the influence of sex and age on the morphometric measures, aiming to reduce inter-subject variability + +MSCC can be computed not only for AP diameter but also for other shape metrics such as CSA, RL diameter, eccentricity, and solidity; see the -metric flag. + + Quantify spinal cord compression +sct_compute_compression +cd ../t2_compression +# Segment the spinal cord of the compressed spine +sct_deepseg spinalcord -i t2_compressed.nii.gz -qc ~/qc_singleSubj +# Label the vertebrae using the compressed spinal cord segmentation +sct_label_vertebrae -i t2_compressed.nii.gz -s t2_compressed_seg.nii.gz -c t2 -qc ~/qc_singleSubj +# Generate labels for each spinal cord compression site. +sct_label_utils -i t2_compressed.nii.gz -create 30,152,99,1.0:30,156,118,1.0:30,157,140,1.0:31,160,159,1.0 -o t2_compressed_labels-compression.nii.gz +# Compute ratio between AP-diameter at level of compression vs. above/below +sct_compute_compression -i t2_compressed_seg.nii.gz -vertfile t2_compressed_seg_labeled.nii.gz -l t2_compressed_labels-compression.nii.gz -metric diameter_AP -normalize-hc 0 -o ap_ratio.csv +# Compute AP diameter ratio, normalized with healthy controls +sct_compute_compression -i t2_compressed_seg.nii.gz -vertfile t2_compressed_seg_labeled.nii.gz -l t2_compressed_labels-compression.nii.gz -metric diameter_AP -normalize-hc 1 -o ap_ratio_norm_PAM50.csv +Note: Normally labeling compression sites would be done manually using fsleyes' "Edit mode -> Create mask" functionality. +👉 See the tutorial for more details. + + Registration to template +64 +Day Two + + Gray matter segmentation +Atlas-based analysis +Diffusion-weighted MRI +Functional MRI +Other features +Analysis pipelines with SCT +New and upcoming features +Conclusion +Day One + +Introduction +Installation +Segmentation +Vertebral labeling +Shape-based analysis +Registration to template +Register additional contrasts +In this section we will learn how to register a new image to a pre-existing template, and how to use this registration for computing cord CSA across the superior-inferior axis. + +Theory + + + PAM50: Template of the spinal cord +Spinal cord and brainstem template +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 +66 +👉 More info available on SCT website +Template-based (or atlas-based) analysis is commonly used for brain studies, and requires a template. In SCT, the latest and recommended template is the PAM50 template. PAM stands for “Polytechnique”, “Aix-Marseille University” and “Montreal Neurological Institute”, the three collaborative institutions. The PAM50 templates consists of a T1w, T2w, T2*w, white and gray matter probabilistic atlas, white matter atlas of tracts (30 tracts) and gray matter parcellation (6 regions). + +Note: since SCT v4.0.0, the PAM50 is in the same coordinate system as the MNI ICBM152 Brain template. + +Anat (T2w or T1w) +Segmentation +Vertebral labeling +Template & forward/backward transform +Straightening +1. Affine +2. Non-rigid +Concatenate warping fields +. +C3 +T3 + PAM50: Registration pipeline +Once the subject is registered to the template (and vice versa), we generate warping fields that can be used to transform the template objects (e.g., white matter atlas) onto the subject. + +Anat (T2w or T1w) +Segmentation +Vertebral labeling +Template & forward/backward transform +Straightening +1. Affine +2. Non-rigid +Concatenate warping fields +. +C3 +T3 +First, we will take the previous vertebral label file and select specific vertebral landmarks in the spinal cord, which will be used for template matching with the landmarks from the PAM50 template. + + +Anat (T2w or T1w) +Segmentation +Vertebral labeling +. +C3 +T3 +Template & forward/backward transform +Straightening +1. Affine +2. Non-rigid +Concatenate warping fields +First, we will take the previous vertebral label file and select specific vertebral landmarks in the spinal cord, which will be used for template matching with the landmarks from the PAM50 template. + +Anat (T2w or T1w) +Segmentation +Vertebral labeling +Straightening +. +C3 +T3 +Template & forward/backward transform +1. Affine +2. Non-rigid +Concatenate warping fields +Straightening +After we select which vertebral landmarks we wish to use, we can begin the registration process by “straightening” the spinal cord in order to align it with the PAM50 template (which exhibits a “straight” spinal cord). + + Spinal cord straightening +Internal distance is preserved (as opposed to slice-by-slice translations) +71 +De Leener et al. JMRI 2017 +sct_straighten_spinalcord +https://drive.google.com/file/d/0Bx3A13n3Q_EAQll6Ykg2aFRZRHM +The straightening works by finding, for each point along the spinal cord, the mathematical transformation to go from a curved centerline to a straight centerline. Two warping fields are output: warp_curve2straight.nii.gz and warp_straight2curve.nii.gz. + +A major advantage of the implemented straightening algorithm, is that instead of doing a slice-wise translation (which does not account for the through-plane deformation), here the inner geometry of the cord is preserved. Another advantage is that it outputs a forward and a backward warping field (ITK-compatible), which could be concatenated with subsequent transformations, as will be seen later. + +To get a better intuition about how this straightening works, see this movie: +https://drive.google.com/file/d/0Bx3A13n3Q_EAQll6Ykg2aFRZRHM + +Anat (T2w or T1w) +Segmentation +Vertebral labeling +Straightening +1. Affine +. +C3 +T3 +Template & forward/backward transform +Concatenate warping fields +2. Non-rigid +After straightening, an affine transformation is applied to match the vertebral levels of the subject to that of the template. Then, a non-rigid transformation is estimated for finely match the subject’s cord shape to the template. + +Anat (T2w or T1w) +Segmentation +Vertebral labeling +Template & forward/backward transform +Straightening +1. Affine +2. Non-rigid +Concatenate warping fields +. +C3 +T3 +Once the subject is registered to the template (and vice versa), we generate warping fields that can be used to transform the template objects (e.g., white matter atlas) onto the subject. + +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 +By transforming the template to the subject space, metrics such as MTR can be extracted at specific levels and in specific tracts. We have already seen full-cord CSA measurements, but later on we will get into metric extraction and atlas-based analysis. + +Hands-on + + + Selecting landmarks for registration +76 +sct_label_utils +# Select the C2-C3 and T1-T2 intervertebral disc labels. These labels are needed for template registration. +sct_label_utils -i t2_step1_levels.nii.gz -keep 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 +t2_labels +t2_seg_labeled +value = 3 +value = 9 +. +. +To make things easy, we can reuse the disc label file that was previously generated to extract two intervertebral disc labels as landmarks for template registration. + + Register to template +77 +sct_register_to_template +# Register t2->template. +sct_register_to_template -i t2.nii.gz -s t2_seg.nii.gz -ldisc 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. +t2 +t2_seg +t2_labels +template2anat +anat2template +warp_anat2template +warp_template2anat +. +. +This is the main command for registering your subject to the template. It outputs the PAM50 template (PAM_T2 if you selected -c t2, PAM_T1 if you selected -c t1) registered to your data, and your data registered to the PAM50 template. It also output the forward and backward warping fields (warp_anat2template.nii.gz and warp_template2anat.nii.gz.), which can be used by other software (e.g., SPM, FSL). + + Registration results +78 +https://drive.google.com/file/d/0Bx3A13n3Q_EATGZrTTFwcThOeEk +https://drive.google.com/file/d/0Bx3A13n3Q_EAWElGQkZIRXVTWjg +PAM50 to t2 +t2 to PAM50 +The links at the bottom of this slide redirect you to a gif animation, which alternates between the subject and the PAM50_t2 registered to the subject. In general, we always recommend doing this visual evaluation to assess the quality of registration. + + 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. +79 +sct_register_to_template + + + 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= +80 +[1] https://stnava.github.io/ANTs/; [2] De Leener et al, Neuroimage 2017; [3] Béal et al. Aperture Neuro 2023 +sct_register_to_template, sct_register_multimodal +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 +This non-rigid transformation can be estimated using a variety of algorithms. The main difference with brain algorithms is that here, the transformation is constrained within the z-plane (axial plane). The default transformation should work for most cases, but you might want to play with parameters to optimize registration with your particular contrast and resolution. + +If you need help with this complex procedure, please do not hesitate to contact SCT team on the help forum: +http://forum.spinalcordmri.org/c/sct + + 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. +81 +sct_register_to_template +Choosing these parameters can be overwhelming. Don’t hesitate to ask for help if you are not sure what to use: https://forum.spinalcordmri.org/c/sct + + Demo: Advanced -param +82 +sct_register_to_template +# Register t2->template with modified parameters +sct_register_to_template -i t2.nii.gz -s t2_seg.nii.gz -ldisc t2_labels_vert.nii.gz -qc ~/qc_singleSubj -ofolder advanced_param -c t2 -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 +t2 +t2_seg +t2_labels +template2anat +anat2template +warp_anat2template +warp_template2anat +. +. +Here, we demo what it looks like to change the advanced parameters using the -param argument. + +You can see that we have specified “step=1”, “step=2”, and “step=3”, with different metrics and algorithms for each step. + +We have chosen the metrics and algorithms so that “step=1” starts out using coarse adjustment (algo=rigid), with each step after that performing fine-tuning (algo=bsplinesyn, algo=syn) with progressively fewer iterations. + + 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: +83 +sct_register_to_template +sct_register_to_template -i t2.nii.gz -s t2_seg.nii.gz -ldisc t2_step1_levels.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 1: 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 +Note 2: -lspinal can be used to rely on spinal levels instead of vertebral levels. + + Example in compressed cord +84 +# 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 (). +sct_register_to_template -i -s -ldisc -ref subject -param step=1,type=seg,algo=centermassrot:step=2,type=seg,algo=columnwise +IMAGE +SEGMENTATION(*) +*: manual adjustment likely required +anat2IMAGE +wm/gm atlas +This page shows that sct_register_to_template can also be used with compressed cords, though you will likely need to use some level of manual segmentation and labeling in order to get the required images. + +What can we do with our registration results? +We have run `sct_register_to_template`. Now what? Well, we will explore the PAM50 template in further detail and show the utility of registration. + + Exploring the PAM50 template +You can go to the SCT installation folder and open up “data/PAM50” to explore the features. +Contains several subfolders with useful files: +We will bring these files to the subject space. +Here we will take a moment to look at the PAM50 template in more detail. + +Speaker: Open the PAM50 on fsleyes, and show the T1w, spine and vert levels + + Warp template objects +87 +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 +# 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 & +t2 +warp_template2anat +/label/template +Now that we have the transformation files, we can apply them to bring the template in the subject’s native space. + +By default, the function sct_warp_template will select the PAM50 template, which is located in your $SCT_DIR/data/PAM50 installation folder. If you wish to use another template, select it with the flag -t. + + 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 +88 +sct_warp_template, sct_apply_tranfo +In this course, we will be showing you how to do a subject-centric analysis, meaning that the template is registered to the subject, and metrics will be extracted in the subject’s space. + +However, note that it is also possible to warp all subjects to the template, and do the analyses there. For example, this could be useful for looking at an average map of FA across subjects. + + More on warping fields +89 +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 -d -w +To concatenate several warping fields: +sct_concat_transfo -d -w +Warping fields +To make warping field FSL/SPM-compatible: +# Convert ITK warping field to FSL warping field +sct_image -i -to-fsl -o +# NB: '' is the source image you will be applying the warping field to, and is used as a reference for the source voxel space +Those warping fields are using ITK convention, which is not compatible with software such as FSL or SPM. If you are using non-ITK third-party software for post-processing (e.g., group analysis in fMRI), you can transform your warping field using sct_image to have them compatible with your software. + +WARNING: The ITK/FSL warping field conversion shown here only works if the source and destination files are in the same voxel space. If they are different, you will need to provide a second image to act as a reference for the destination space. More details can be found on https://spinalcordtoolbox.com/overview/concepts/warping-fields.html#compatibility-with-non-itk-software-fsl-spm. + +How to add another contrast (MTR, diffusion, etc.)? +So far, we have seen how to use the PAM50 to quantify the morphometry of the cord on anatomical images. Now we will see how to use template registration for computing qMRI metrics. + + Register additional contrasts +91 +Day Two + + Gray matter segmentation +Atlas-based analysis +Diffusion-weighted MRI +Functional MRI +Other features +Analysis pipelines with SCT +New and upcoming features +Conclusion +Day One + +Introduction +Installation +Segmentation +Vertebral labeling +Shape-based analysis +Registration to template +Register additional contrasts + + +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 +Let’s say you acquire other scans during the same sessions, such as DTI, MT, etc. The key here is to register the PAM50 template to those additional scans. We will now see how to do it. + + Segment MT data +93 +sct_register_multimodal, sct_propseg +# Go to mt folder +cd ../mt +# Segment cord +sct_deepseg spinalcord -i mt1.nii.gz -qc ~/qc_singleSubj + + +mt1 +mt1_seg +Like for the anatomical T2 image, the first step is to obtain a proper segmentation of the cord, here on an MT-weighted scan. + + Create mask +94 +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 +mt1 +mask_mt1 +mt1_seg +Based on the segmentation, we create a mask, which is subsequently used to obtain better registration results between scans (here, between mt1 and the template, and later between mt0 and mt1). + + Register template to MT1 +95 +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 +https://drive.google.com/file/d/0Bx3A13n3Q_EAYTVVQTFYMjhDU0U +Then, we register the PAM50 to the mt space. Note that we don’t use the function sct_register_to_template, but instead we use sct_register_multimodal. The reason being that we start from the pre-registration (i.e. PAM50—>t2 done previously), which already contains information about vertebral labeling. We assume that the subject did not move “too much” in the superior-inferior direction (usually a fair assumption) and we only refine the PAM50—>mt registration by account for small motion (e.g., head tilting) and potential distortions that are inherent to the contrast. + +Here, the destination image is the mt1 scan, which exhibits good cord/CSF contrast (“t2”-like). + +N.B. There could sometimes be 'edge effects' on the top and/or bottom slice due to the warping field not being properly defined at the edge, so it is possible that the top and/or bottom slice of the registered template looks cropped. + + Register template without anatomical image +96 +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 + +mt1 +mt1_seg +mt1_label +. +Registration with -initwarp requires pre-registration, but in some cases you won't have an anatomical image to do a pre-registration. + +So, as an alternative, you can register the template directly to a metric 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 with: sct_label_utils -i mt1_seg.nii.gz -create-seg -1,4 + +For more information, type sct_label_utils -h + + Warp template to MT +97 +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 & +label/template/ +label/atlas/ +WM atlas +mt1 +warp_template2mt +After the registration transformation is computed, you can run sct_warp_template to bring the template objects to the MT space. Here, in addition to the label/template/ folder, the folder label/atlas/ is created, which contains the white matter atlas. + +Note that the current framework is blind to spinal cord internal structure (because anatomical T1 or T2 don’t show GM). While the gray matter coming from the template shows a plausible location of the gray matter for a specific subject, there might be some inaccuracies. If you have an additional scan with good gray/white matter contrast, it might be beneficial to include it in the framework as will be detailed in the next section. + + 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 & +https://drive.google.com/file/d/0Bx3A13n3Q_EATG96VGhjTWJrYkk +98 +While we are in the mt folder, we will also demonstrate how to compute the magnetization transfer ratio (MTR). This will be useful later in the course, where we will demonstrate how extract MTR for specific white matter tracts. + +First, it is necessary to co-register the mt0 and mt1 images. We use sct_register_multimodal to register the mt0 scan on the mt1 scan. Here, we chose algo=slicereg, which provides a robust slice-wise registration, regularized along z. The output interpolation is spline. + + Compute MTR +99 +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 +mt1 +mt0_reg +mtr +0 +50 +Once mt1 and mt0 are co-registered, we can compute mtr (given in percentage). + +Note: when you open the output MTR in FSLview, you might see a flat grey image. This might be due to extreme outlier values which stretch the display contrast. You can adjust the min/max value on the FSLeyes interface (e.g., set it to min=0, max=60). + +Note that we decided to register mt0 on mt1 and not the other way around. There is a reason behind it: since MTR calculation imposes to have mt0 as denominator, we prefer to reduce the amount of noise on this quantity and therefore apply the registration-related interpolation on the mt0. Although the difference is negligible. + +How to register the lumbar region to the PAM50 template? + + + 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 sc_lumbar_t2 -i t2_lumbar.nii.gz -qc ~/qc_singleSubj + +# 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 +The first step in the registration pipeline is to segment the spinal cord. + +Note that instead of using the usual sct_deepseg_sc, we use the specialized “sct_deepseg” model “seg_lumbar_sc_t2w”, which is specifically designed for the lumbar region. + +Currently this model supports T2w only, but we are planning to introduce a new contrast agnostic segmentation model which will support other contrasts (more info in the “New and upcoming features” section of the course). + + Selecting landmarks for registration +Using only disc labels will often result in misalignment of the terminal end of the spinal cord +So, we introduced 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 +Next, we will select landmarks. However, this time, we will not just run sct_label_vertebrae and select 2 disc labels (as before). + +This is because, even if the discs are aligned between subject + PAM50 template, the cord itself may be misaligned, due to variation in the positioning of the cord relative to the discs. (Leftmost example) + +To address this, we want to use a new landmark to specifically align the terminal end of the spinal cord. This is label “60” (conus medullaris). + +You can either choose to use 1 label (just 60), or 2 labels (60 + some other landmark, e.g. one of the uppermost discs). You have some flexibility here – just make sure to stick with whatever approach you choose across all of your subjects. + + 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 -qc ~/qc_singleSubj +# 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! +⚠️ Warning! It is important that both labels are created within the same axial slices where the cord segmentation exists. If it does not, the registration to template will crash. (See: Issue #3873) +If the cord does not extend to the conus medullaris, you should manually extend the cord segmentation. + +In order to precisely select suitable coordinates, you will want to use a viewer to overlay the segmentation onto the anatomical image. + +For this sample data, we have already predetermined the specific coordinates we want to label: +[27, 76, 187]: Posterior tip of the T9-T10 disc +[27, 79, 70 ]: Lowermost voxel of the spinal cord segmentation (i.e. the terminal end of the spinal cord – the conus medullaris) + + + + + Register lumbar to template +104 +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. +t2_lumbar +t2_lumbar_seg +t2_lumbar_labels +template2anat +anat2template +warp_anat2template +warp_template2anat +17 • +60 • +Here, we specifically choose -param to improve the quality of the registration. + +Step 3 uses `algo=syn`, which greatly helps to fine-tune the registration. + +End of Day 1 Material + + + End of Day 1 Poll +We would like to hear from YOU 😊 +Polling session… +👉 link to poll +Results will be announced at the end of Day 2 + +Start of Day 2 Material + + + Gray matter segmentation +108 +Day Two + + Gray matter segmentation +Atlas-based analysis +Diffusion-weighted MRI +Functional MRI +Other features +Analysis pipelines with SCT +New and upcoming features +Conclusion +Day One + +Introduction +Installation +Segmentation +Vertebral labeling +Shape-based analysis +Registration to template +Register additional contrasts +Gray matter segmentation can be used to compute metrics such as cross-sectional area (CSA) of the gray matter. It can also be used to refine the template registration, by accounting for the spinal cord gray matter shape (which was not considered in the previous section). In this section, we will learn how to segment the GM, and how to use it for refining template registration. + +Theory + + + GM segmentation methods +SCT features a deep learning method for GM segmentation called: sct_deepseg graymatter +Algorithm: Deep learning nnUnet [1] +Pros: High accuracy, robust to pathologies, contrast-agnostic +The alternative method sct_deepseg_gm [2] is less performant overall and only limited to T2*-like contrasts (GM bright, WM dark). +110 +[1] Laines-Medina et al. ESMRMB conference 2025 +[2] Perone et al., Sci Report 2018 +sct_deepseg graymatter +NEW +in v7.0 +For segmenting the gray matter, SCT features the function sct_deepseg_gm, which is based a deep learning architecture trained from 232 subjects (~4000 slices). DeepsegGM obtained the best Dice score amongst all other methods that participated in the GM challenge [Prados et al., Neuroimage 2017]. It performs particularly well in presence of pathologies. + +Note that for the past few years, another method named sct_segment_graymatter was available. It used a multi-atlas based segmentation, originally inspired from [Asman et al. MIA 2014]. This method no longer available in SCT, due to the outperforming results of sct_deepseg_gm. If researchers wish to use this legacy method, they will have to install an older version of SCT (v3.2.7). + +Hands-on + + + Segment GM and WM +112 +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 graymatter -i t2s.nii.gz -qc ~/qc_singleSubj +# Full spinal cord segmentation +sct_deepseg spinalcord -i t2s.nii.gz -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 -thr 0 -o t2s_wmseg.nii.gz +t2s +t2s_gmseg +t2s_wmseg +In this course we will use sct_deepseg_gm. The only required input is an image with a T2*-like contrast (GM brighter than WM) and sufficient resolution to distinguish the GM, as shown in the image. + +By default, sct_deepseg_gm outputs binary segmentation, although it is also possible to obtain the un-thresholded segmentations with the flag -thr with values ranging from 0 to 1. Note that the output values of sct_deepseg_gm correspond to the output of the CNN and are not necessarily usable for any sort of partial volume correction or probabilistic interpretation. + +Since we also want the WM segmentation (see later why), we segment the cord and subtract the GM seg from it. + +Note that we use the flag -thr 0 in case some voxels in the GM segmentation are not included in the cord segmentation. That would results in voxels in the WM segmentation having the value “-1”, which would cause issues with the registration. + + CSA of GM and WM +113 +# 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 +CSA (mm2) +gray matter +white matter +t2s_gmseg +t2s_wmseg +The computed GM and WM segmentations can now be used to compute the cross sectional area of GM and WM. This is achieved using sct_process_segmentation. + +Note that here, we do not use the angle correction because the estimation of the cord centerline derivative might be too sensitive to the shape of the GM and/or WM, and as a result, a wrong angle might introduce spurious CSA estimation. In general, if the angle is small, the over-estimation of the CSA will also be small (cos(angle)~1). With axial slices acquired orthogonal to the cord, this is a fair assumption. + + Extract signal intensity in GM +114 +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. +Slice (I->S) +Label +Size [vox] +BIN() +STD() +2:12 +t2s_wmseg +2352 +1274.8536 +207.1855 +2:12 +t2s_gmseg +599 +1495.0286 +209.3065 +SCT also provides the sct_extract_metric, tool which allows you to use single mask files (binary or probabilistic) to average metrics within an image. + +In this case, we will use the white and gray matter masks to extract the signal intensity from the original T2* images. + +This method was successfully applied to the monitoring of myelopathic progression with multiparametric quantitative MRI in [Martin et al. PLoS One 2018]. + +How to account for white and gray matter segmentations during template registration? +As mentioned previously, we would like to use the GM segmentation to refine the template registration. Let’s see how to do this. + +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 +The procedure is shown in purple. The idea is to start from the pre-registration (e.g., t2w—>PAM50) and refine the registration between the WM shape and the PAM50_wm atlas. + + GM-informed template registration +117 +# 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 +t2s +t2s_wmseg +PAM50_wm (unregistered) +PAM50_wm (registered) +As previously done for registering the template to mt1, we use the intermediate template->t2 transformation, which has the necessary information about vertebral level. The difference however, is that instead of using the cord segmentation for the type=seg parameter, here we use the white matter segmentation, which contains both the cord contour and the GM contour. + +ℹ️ Most of the time, the improvement of using GM registration is small. In some cases it can even make it worse (because the result will largely depend on the quality of the GM segmentation), so in general we don’t recommend going through this 2-step registration. + + Register another metric +118 +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 +t2s +PAM50_t2 (reg) +PAM50_gm (reg) +PAM50_wm (reg) +Now that we have estimated a transformation between the template and the t2s data which account for GM shape, we can now register the template to the mt data using the template->t2s transformation as initialization (warp_template2t2s.nii.gz). + +Again, we rely on the cord segmentation only for registering the template to the mt data in order to be less sensitive to image artifact. The difference here (when compared to p.68) is that the information about the GM shape is enclosed in the transformation, producing registration results that are supposedly more accurate. + +Note that because the superior-inferior coverage of the T2*w scans is smaller than the MT scan, the concatenated warping field will only be defined in the region that overlaps between the T2*w and the MT scans. + + Atlas-based analysis +119 +Day Two + + Gray matter segmentation +Atlas-based analysis +Diffusion-weighted MRI +Functional MRI +Other features +Analysis pipelines with SCT +New and upcoming features +Conclusion +Day One + +Introduction +Installation +Segmentation +Vertebral labeling +Shape-based analysis +Registration to template +Register additional contrasts +In this section, we will learn how to quantify metrics (e.g., DTI, MT) using an atlas-based analysis approach. + +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 (%) +Now that we have registered the template to the subject, we can start quantifying some MRI metrics. + +Theory + + + White matter atlas +122 +Lévy et al., Neuroimage 2015 +Based on: Standring, Gray's Anatomy 2008 +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) +A prerequisite for any atlas-based analysis is to have an atlas. In SCT, a digitalized version of the Gray’s Anatomy spinal cord white matter atlas [Standring, Gray's Anatomy 2008] was merged with the PAM50 template. For more information on the procedure, see [Lévy et al., Neuroimage 2015]. + +The atlas is composed of 30 WM tracts, 6 GM regions and the surrounding CSF. The reason for including the CSF is to be able to account for partial volume effect during metric estimation, as explained in the following slides. + + White matter atlas +123 +cerebrospinal fluid +white matter +gray matter +S=0 +S=50 +apparent value in voxel: S=25 +Let’s imagine that the metric value you would like to quantify is 50 in the WM and 0 in the CSF. Because of the coarse resolution of MRI, the apparent value within the voxel will be a mixture between the WM and CSF compartment, yielding the value 25. This phenomenon is called “partial volume effect”. As we will see, there are ways to minimize it or overcome it. + + Quantify metrics with atlas +124 +Lévy et al., Neuroimage 2015 +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 +Because of its simplicity, the traditional method to quantify metrics is to use a binary mask: voxels labeled as “1” (i.e. in the mask) are selected and values within those voxels are averaged to produce, e.g., the average FA inside the spinal cord. As mentioned in the previous slide, this method suffers from partial volume effect and the resulting metric could be biased by the surrounding tissues. + +Instead of using binary masks, we could use weighted masks, which effectively “weight” the contribution of voxels at the interface (e.g., mask value = 0.1) vs. voxels well within the tissue of interest (e.g., mask value = 0.9). While this method (available as -method wa in SCT) minimizes PVE, it does not solve it. + +Alternatively, methods using Gaussian mixture modeling can be used to estimate the “true” value within the region of interest. Here, we benefit from the fact that the metric is measured within thousands of voxels, where the partial volume for each compartment (e.g., white matter, gray matter, CSF) is known. We then use a maximum likelihood estimation (-method ml) to estimate the metric value within each compartment. This approach assumes that within each compartment, the metric is homogeneous. + +Because Maximum Likelihood estimation is sensitive to noise, especially in small tracts, we recommend using the Maximum a Posteriori (-method map), which uses a prior based on the average metric value within the CSF, WM and GM compartment. + +Note that methods ml and map need prior warping of the WM atlas to your data, whereas you could use bin and wa with any binary mask. + + Validation of atlas-based analysis +125 +Lévy et al., Neuroimage 2015 +De Leener et al., Neuroimage 2017 +1 +0 +Atlas creation +20% noise & randomized values in tracts +Bootstrapping +Less than 2% error in “large” tracts +To demonstrate the sensitivity of each method to the amount of noise, to the size of the tract (framed here as “fractional volume”) and to the spatial resolution, we performed bootstrap simulations based on a synthetic MRI phantom. Here is an example of simulation results in realistic conditions, showing that the map and ml methods provide reliable metrics estimate, even in relatively small tracts (e.g., only 2% error in the rubro-spinal tract). For more details, see [Lévy et al., Neuroimage 2015] (construction of the phantom, effect of noise, contrast) and [De Leener et al., Neuroimage 2017; Appendix] (effect of spatial resolution). + +Hands-on + + + The file info_label.txt +127 +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 +The file info_label.txt lists the existing WM tracts nifti files (ID 0—>36), as well as the “combined labels” which could be used for quantifying metrics within a combination of tracts. + +If you want to add more tract combinations for all your studies, instead of editing the file label_info.txt for each subject, you can also edit this file under your SCT installation folder. Each time you will run sct_warp_template, the modified label_info.txt will be copied to each new subject. + +Note that SCT code uses the label IDs to fetch relevant data for processing, so if you wish to generate your own info_label.txt, make sure to choose the correct label IDs. For more information please contact SCT team. + + 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: +128 +Details of the example for editing the info_label.txt file can be seen on this forum’s post: +http://forum.spinalcordmri.org/t/how-to-create-a-hemicord-mask/33/2 + + Extract MTR in white matter +129 +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" +Slice (I->S) +VertLevel +Label +Size [vox] +MAP() +STD() +0 +None +white matter +0 +None +None +1 +6 +white matter +41.6452 +54.5386 +10.6744 +2 +6 +white matter +61.4869 +40.7888 +5.4038 +3 +6 +white matter +66.9520 +55.3711 +4.6303 +4 +5 +white matter +68.8959 +52.4616 +5.1589 +5 +5 +white matter +73.2353 +52.8584 +5.3990 +6 +5 +white matter +75.8461 +52.6179 +4.7946 +… +… +… +… +… +… +20 +1 +white matter +76.2700 +53.8761 +15.2921 +21 +None +white matter +0 +None +None +In this example, we compute, for each slice, MTR within the spinal cord WM. The label volume fraction is indicated as “Size [vox]”, which gives you a sense of the reliability of the measure. In this example, for each slice, the metric was computed based on ~70 voxels. As demonstrated in [De Leener et al., Neuroimage 2017; Appendix], assuming an SNR of 10, having at least 240 voxels results in an error smaller than 1%, while having 30 voxels results in an error inferior than 2%. + + Extract MTR in white matter +130 +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 +# 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 +62.8214 +52.8518 +2.9936 +5:15 +WM right lateral corticospinal tract +68.8171 +52.6106 +3.6469 +Slice (I->S) +VertLevel +Label +Size [vox] +MAP() +STD() +7:16 +2:4 +dorsal columns +223.9491 +53.5445 +3.2687 +In this example, we compute MTR within the right and left corticospinal tract. The number of voxels in each tract is about 67, therefore, as mentioned in the previous slide, the approximate error is less than 1.5% (assuming an SNR of at least 10, and no registration error). + +You can also restrict the quantification to specific vertebral levels (flag -vert) or slice (flag -z), although be careful to always check the associated volume fraction. If too low, your quantifications will be unreliable. If you publish, we recommend including the volume fraction associated with all estimated metrics. + + Diffusion-weighted MRI +131 +Day Two + + Gray matter segmentation +Atlas-based analysis +Diffusion-weighted MRI +Functional MRI +Other features +Analysis pipelines with SCT +New and upcoming features +Conclusion +Day One + +Introduction +Installation +Segmentation +Vertebral labeling +Shape-based analysis +Registration to template +Register additional contrasts +In this section we will learn how to process diffusion-weighted data, in particular: motion correction and registration to the template. + + What is dMRI? +dMRI is sensitive to random water molecule movement (= diffusion) +dMRI can be used to compute metrics reflecting tissue microstructure (e.g., FA) or for fiber tracking (tractography) +Fig ref: fsl.fmrib.ox.ac.uk – FSL Course +Fig ref: David et al., Nature Rev Neur, 2019 + + Preprocess dMRI data +133 +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 spinalcord -i dmri_dwi_mean.nii.gz -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 +Here, the reason we compute the mean from the dMRI data is simply to obtain a 3D volume (instead of 4D) that can be used to get a first coarse cord segmentation. Once the coarse segmentation is obtained, we use it to create a mask around the cord which we will pass to the moco command: this accelerates the processing and makes it more accurate. + + Motion correction for dMRI +134 +Xu et al., Neuroimage 2013 +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 “moco_params.tsv” (mean-square displacement) and the QC report +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: +SCT features a complex motion correction algorithm, which is inspired by [Xu et al., Neuroimage 2013]. The key aspects of this algorithm are as follows: +SliceReg: Slice-wise registration regularized along the Z direction (based on the function antsSliceRegularizedRegistration from ANTs, and described in [De Leener et al., Neuroimage 2017]). +Grouping: there is the possibility to group successive volumes in order to have sufficient SNR to estimate a reliable transformation. If your data are very low SNR you can increase the number of successive images that are averaged into group with the flag -g. +Iterative average: after registering a new group to the target image (which is usually the first DWI group), the target is averaged with the newly registered group in order to increase the SNR of the target image. +Outlier detection: if a detected transformation is too large, it is ignored and the previous transformation is used instead. +Masking: in order to estimate motion of the cord, ignoring the rest of the tissue, there is the possibility to include a mask with the flag -m +For more information, see: sct_dmri_moco -h + +A QC report for motion correction is also generated with the flag -qc. It shows the motion corrected vs. non-motion corrected scans, slice-by-slice and for each volume, for convenient comparison. + +The output “moco_params.tsv” shows the mean-square displacement (mean(sqrt(X^2 + Y^2))) for each slice. For more details about this metric, see this interesting discussion thread: https://github.com/spinalcordtoolbox/spinalcordtoolbox/issues/4344. + + Register template to dMRI +135 +# Segment SC on motion-corrected mean dwi data (check results in the QC report) +sct_deepseg spinalcord -i dmri_moco_dwi_mean.nii.gz -qc ~/qc_singleSubj +# Register template->dwi via T2 to account for cord shape (which is better defined in T2) +# 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 ../t2/warp_template2anat.nii.gz -initwarpinv ../t2/warp_anat2template.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 +At the end of motion correction, three files are created: the motion-corrected dMRI data (dmri_moco.nii.gz), the mean diffusion-weighted data excluding the b=0 (dwi_moco_mean.nii.gz) and the mean b=0 data (b0_moco_mean.nii.gz). + +Usually we recommend using dwi_moco_mean.nii.gz for cord segmentation because it has an excellent cord/CSF contrast. + +Once the cord is segmented, we register the template to it. Here we choose the PAM50_t1 which has similar contrast than the mean DWI data. We used the flag -initwarp ../t2/warp_template2anat.nii.gz to rely on the previously-registered template to our anatomical T2w data, but we could have also used -initwarp ../t2s/warp_template2t2s.nii.gz to account for the gray matter shape, although this latter approach is more constraining (it requires to have a good quality T2*w image) and in some cases, the registration is not necessarily better. + +You also noticed the flag -initwarpinv ../t2/warp_anat2template.nii.gz, which implies that the reverse transformation (dmri—>template) will also be generated, and could be used if you want to bring all your subjects to the template space, e.g., for obtaining group FA maps. + + Compute DTI +136 +[1] Garyfallidis, Front Neuroinform 2014 [2] Chang, Magn Reson Med 2005 +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: You can alternatively use the flag "-method restore" to estimate 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 +dmri_moco +bvecs.txt +———————————————————— +bvals.txt +———————————————————— +FA +MD +AD +RD +Here, we compute the diffusion tensor. SCT relies on the excellent dipy library for computing dMRI metrics [Garyfallidis et al., Front Neuroinform 2014]. As explained in the comments above, you can use the robust fitting method “RESTORE”, which provides better immunity to pulse-related signal drop-out in DWI data. + +Please note that SCT is mainly used for dMRI “pre-”processing, which is why SCT only includes the simple DTI model. For the "more advanced" models, users can use third-party software (e.g., dipy, MRtrix, etc.). + + Functional MRI +137 +Day Two + + Gray matter segmentation +Atlas-based analysis +Diffusion-weighted MRI +Functional MRI +Other features +Analysis pipelines with SCT +New and upcoming features +Conclusion +Day One + +Introduction +Installation +Segmentation +Vertebral labeling +Shape-based analysis +Registration to template +Register additional contrasts +In this section we will learn how to process functional MRI data. + + What is fMRI? +Chen and Glover, Neuropsychol Rev (2015) +Functional MRI (fMRI) is an imaging technique that measures activity in the central nervous system by detecting changes in blood oxygenation and flow, reflecting neuronal activity. It primarily captures Blood Oxygen Level-Dependent (BOLD) contrast images, which show areas of increased neural activity. Common types of fMRI images include resting-state fMRI, used to study functional connectivity by examining brain activity in the absence of tasks, and task-based fMRI, which identifies regions activated during specific tasks or stimuli. Typically, gradient-echo echo planar images (EPI) are acquired, as they provide good sensitivity to the BOLD signal. + +These images are often complemented by high-resolution anatomical scans, like T1-weighted or T2-weighted images, for accurate localization and structural reference. + +For more details, see: https://mriquestions.com/uploads/3/4/5/7/34572113/chen_glover_fmri_review_2015art3a10.10072fs11065-015-9294-9.pdf + + Analysis of fMRI data +139 +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 +# Cord segmentation on motion-corrected averaged time series +sct_deepseg spinalcord -i fmri_moco_mean.nii.gz -qc ~/qc_singleSubj/ +# TSNR before/after motion correction with QC report +sct_fmri_compute_tsnr -i fmri.nii.gz +sct_fmri_compute_tsnr -i fmri_moco.nii.gz +sct_qc -i fmri_tsnr.nii.gz -d fmri_moco_tsnr.nii.gz -s fmri_moco_mean_seg.nii.gz -p sct_fmri_compute_tsnr -qc ~/qc_singleSubj/ +# Register the template to the fMRI scan. +sct_register_multimodal -i "${SCT_DIR}"/data/PAM50/template/PAM50_t2s.nii.gz -iseg "${SCT_DIR}"/data/PAM50/template/PAM50_cord.nii.gz -d fmri_moco_mean.nii.gz -dseg fmri_moco_mean_seg.nii.gz -param step=1,type=seg,algo=centermass:step=2,type=seg,algo=bsplinesyn,slicewise=1,iter=3:step=3,type=im,algo=syn,metric=CC,iter=3,slicewise=1 -initwarp ../t2/warp_template2anat.nii.gz -initwarpinv ../t2/warp_anat2template.nii.gz -owarp warp_template2fmri.nii.gz -owarpinv warp_fmri2template.nii.gz -qc ~/qc_singleSubj +“-identity 1” skips translation/deformation, and only matches dimension, resolution, and orientation. +Here is an example of pre-processing of an fMRI dataset. The first step is to perform motion correction. For robust motion correction, we like to rely on a mask that tightly surrounds the spinal cord. Because the spinal cord segmentation is unreliable on non-motion corrected GRE EPI scans, we bring the anatomical T2w segmentation (or T1w if you don’t have any T2w) into the space of the fMRI scan. Then, we create the mask, we run the motion correction, and we segment the spinal cord on the motion-corrected averaged time series. We compute TSNR before and after and compute the QC report to compare TSNR before and after motion correction. + +Motion correction: We invite you to play with the motion correction parameters, because they are specific to the data (eg, resolution, noise, artifacts, etc.). + +Registration to the template: because data quality in GRE EPI scans is often “so-so”, it is important to always visually check the quality of the cord segmentation, and if necessary, manually correct it. The quality of the segmentation will have an impact on the quality of the registration. + +⚠️ Comparing TSNR on linearly-interpolated motion-corrected data is wrong. If you do so, re-run moco using nn interpolation. + + Spinal labeling for fMRI +140 +[1] Frostell et al. Front Neurol. 2016 +Vertebral labeling only gives a “rough” idea of where the spinal nerves project in the spinal cord. Probabilistic spinal labeling [1] is available in SCT +⚠️ This is a probabilistic, not individual, mapping of spinal levels +Location of the spinal level: $SCT_DIR/data/PAM50/template/ +So far, we have only used vertebral and/or disc labeling for template-based registration. However, knowing the position of the spinal levels (i.e. where the nerve roots connect to the cord) could be more informative from an anatomo-functional standpoint. For that purpose, we have integrated the work of Frostell et al., which provides a one-to-one mapping between vertebral and spinal levels. This is particularly useful for fMRI studies wherein researchers are interested in the spinal levels of activated neurons. For more details on how the labels are generated, see https://spinalcordtoolbox.com/overview/concepts/pam50.html#spinal-levels. + + Spinal labeling for fMRI +130 +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 +C3 +C3 +C4 +C5 +C6 +C7 +C4 +C5 +C2 +Vertebral levels +Spinal levels +When warping the template to the fMRI data, the spinal levels are automatically warped under ./label/template/PAM50_spinal_levels.nii.gz. + + Other features +142 +Day Two + + Gray matter segmentation +Atlas-based analysis +Diffusion-weighted MRI +Functional MRI +Other features +Analysis pipelines with SCT +New and upcoming features +Conclusion +Day One + +Introduction +Installation +Segmentation +Vertebral labeling +Shape-based analysis +Registration to template +Register additional contrasts +We will now look at a few other features that could be useful for your analyses. + + 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_deepseg (*NEW*) +sct_fmri_compute_tsnr (*NEW*) +sct_detect_pmj +sct_dmri_moco +sct_fmri_moco +sct_get_centerline +sct_image -stitch +sct_label_utils +sct_label_vertebrae +sct_process_segmentation +sct_register_multimodal +sct_register_to_template +sct_straighten_spinalcord +sct_warp_template +143 +sct_qc +An important aspect of MRI processing is quality control. What we have seen so far in SCT, is that after each process, the Terminal window displays a command that could be copy/pasted, for opening fsleyes/fslview and do visual QC. However, this is only done on an individual subject basis, and it is not convenient if you have several processes and hundreds of subjects. + +Since SCT v3.0.3, we have introduced an alternative QC method which is more versatile and intuitive. After running a process, result images are generated and organized into a web page for convenient viewing. The syntax to open the QC report in your default web browser is displayed in green on your Terminal (open “xxx”). Below are some useful shortcuts: +up/down arrow: navigate across processes +right arrow: toggle segmentation overlay + +The benefit of this QC report, is that when hundreds of subjects are run in a pipeline, this single browser window allows you to quickly skim through all processed subjects. Another advantage is that you can easily zip the entire QC folder (only a few MB) and share it with your colleagues/collaborators, or even include a link to the report in publications. + + Quality Control (QC) Reports +144 +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). +See live demo with sct_deepseg_sc failed cases. + +The failed cases listed in the output YAML file can be used by a script called ‘manual-correction.py’ that loops across the failed cases and opens an image viewer for the user to manually correct the segmentations. The corrected segmentations are saved according to the BIDS specifications (under the derivatives/labels/ folder). See for example: https://spine-generic.readthedocs.io/analysis-pipeline.html#segmentation-and-vertebral-labeling + +Later on in the course, we will demonstrate how to use this script, so stay tuned. + + SCT-FSLeyes integration +145 +Another cool feature is the integration of SCT within FSLeyes, powered by the Python scripting plugin capabilities. The next slides explains how to do it. + + 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. There will be more in the future if the feature is popular. +146 +See live demo with t2s.nii.gz file. + + Smooth along spinal cord +147 +sct_smooth_spinalcord +no smoothing +z-smoothing +Isotropic smoothing +smoothing along centerline +follows curvature +This smoothing method is similar to 2d cortical surface smoothing in FreeSurfer, only this one is 1d and follows the cord centerline. + +This function can be used to improve sensitivity of fMRI results while minimizing contamination from CSF + +It can also be used to obtain more reliable cord segmentations, because smoothing will sharpen the edge of the cord and will blur out possible artifacts at the cord/CSF interface. + + Smooth along spinal cord +148 +sct_smooth_spinalcord +cd ../t1 +# Segment the spinal cord using the usual sct_deepseg command +sct_deepseg spinalcord -i t1.nii.gz -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 spinalcord -i t1_smooth.nii.gz -qc ~/qc_singleSubj + + + +t1 +t1_seg +t1_smooth +Let’s try sct_smooth_spinalcord in this T1-weighted scan. Here we notice that after smoothing, the apparent noise is reduced, while the cord edges are preserved, allowing a more reliable segmentation on a second pass. + + + Align the cord in the R-L plane +149 +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 +Because some subjects (esp. those with scoliosis) might not be perfectly aligned in the medial plane, it can sometimes be difficult to view the spinal cord in a single 2D slice. The function sct_flatten_sagittal applies slice-wise deformation to align the cord in the medial plane. + +Important: This deformation does not preserve the internal structure of the cord, and is only advised for visual purpose. If you would like to properly align the cord along the RL and AP direction we recommend you use sct_straighten_spinalcord instead. + + Operations on images +150 +sct_maths +sct_maths + -add Add following input (can be number or image(s)) + -sub Subtract following input (can be number of image(s)) + -mul Multiply following input (can be number or image(s)) + -div 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 Binarize image using specified threshold. E.g. -bin 0.5 + -otsu Threshold image using Otsu algorithm. + -percent Threshold image using percentile of its histogram. + -thr Use following number to threshold image (zero below number). + -dilate Dilate binary image using specified ball radius. + -erode Erode binary image using specified ball radius. + -smooth Gaussian smoothing filter with specified standard deviations in + -laplacian Laplacian filtering with specified standard deviations in mm + -denoise Non-local means adaptive denoising from P. Coupe et al. + -mi Compute the mutual information (MI) between two images + -symmetrize {0,1,2} Symmetrize data along the specified dimension. + And more...! +The sct_maths script (fslmaths’ little sister) contains useful functions to apply operations on the image data, such as basic arithmetic operations, thresholding, mathematical morphology and filtering. For more information, type sct_maths -h + + Manipulate images +151 +sct_image +sct_image +IMAGE OPERATIONS: + -pad Pad 3d image. Specify padding as: "x,y,z" (in voxel) + -pad-asym 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 Remove specific volumes from a 4d volume. Separate with "," + -keep-vol 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 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...! + +The sct_image script contains useful functions to manipulate images, such as padding, splitting, keeping/removing volumes on 4d data, re-orienting, etc. For more information type sct_image -h + + Image stitching +Lavdas, Glocker et al. Clin. Radiol. 2019 +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) +Speaking of sct_image, we would like to highlight one very important new option of sct_image called -stitch. + +This method allows you to stitch multiple images acquired in the same orientation, utilizing the algorithm by Lavdas, Glocker et al. + + Other features? +To see all available functions, type “sct_” then TAB +153 + + + 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: +154 +source ${SCT_DIR}/python/etc/profile.d/conda.sh +conda activate venv_sct + + + Analysis pipelines with SCT +155 +Day Two + + Gray matter segmentation +Atlas-based analysis +Diffusion-weighted MRI +Functional MRI +Other features +Analysis pipelines with SCT +New and upcoming features +Conclusion +Day One + +Introduction +Installation +Segmentation +Vertebral labeling +Shape-based analysis +Registration to template +Register additional contrasts + + + 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 +156 +sct_run_batch +Batch scripts are extremely useful in the long term: they make it possible to re-run entire processing and re-generate results if needed (e.g., if after 6-month of a manuscript submission the reviewer asks you to change one parameter in the processing). + +Batch scripts are also excellent in establishing standardized processing, automatizing over large databases and to promote reproducibility of scientific results (e.g., you can publish your article along with the batch processing scripts). + + + Data organization +All participant data are organized into a directory and follow certain conventions, such as the BIDS (https://bids.neuroimaging.io/) data structure: +157 +sct_run_batch +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 +In order for the script to be applied to the entire dataset, you need to follow some conventions in terms of folder and file names. As some of you might know, there is a convention that was created by the brain imaging community called Brain Imaging Data Structure (BIDS). This convention makes it easier to share data, and also to develop and use Applications that are BIDS-compliant (such as SCT). + +Hands-on + + + Processing multiple subjects +Here we use a wrapper, called sct_run_batch, which loops across subjects and launch a batch script. +159 +sct_run_batch +# 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 +If each subject’s data is organized into individual folder, following the same file structure across subjects, it is convenient to create a “loop across all subjects” inside the batch script. When doing so, it is possible to distribute each subject into a single CPU core, allowing to process subjects in parallel. The gain in time can be 4x, 8x or even more, depending on the number of cores and RAM available. + +In this course, we will run a processing pipeline across 3 subjects. Before running this pipeline, let's look at the data structure with tree, as well as the processing script process_data.sh. + +Now, we are ready to launch the processing with the command sct_run_batch. While the processing runs, let's look at the generated outputs (log files, qc, data_processed) + +CSA.csv +Filename +Slice (I->S) +VertLevel +MEAN(area) +STD(area) +sub-01_T2w_seg.nii.gz +160:200 +2:3 +82.9358 +1.9414 +sub-03_T2w_seg.nii.gz +160:200 +2:3 +61.0923 +2.4872 +sub-05_T2w_seg.nii.gz +158:197 +2:3 +69.5586 +2.4585 + multi_subject: CSA +160 +sct_run_batch +Each line represents a subject +CSA results +After running the entire pipeline, you should have all results under the results/ folder. Here for example, we show the mean CSA averaged between C2-C3 levels computed from the T2 data. Each line represents a subject. + +The variability is mainly due to the inherent variability of CSA across subjects. For more details see: https://www.biorxiv.org/content/10.1101/2021.09.30.462636v1.full + +MTR_in_DC.csv +Filename +Slice (I->S) +VertLevel +Label +Size [vox] +MAP() +STD() +sub-01/anat/mtr.nii.gz +4:16 +2:5 +dorsal columns +325.3513 +49.4858 +4.5253 +sub-03/anat/mtr.nii.gz +4:16 +2:5 +dorsal columns +278.6569 +48.9083 +5.6684 +sub-05/anat/mtr.nii.gz +3:16 +2:5 +dorsal columns +302.1767 +49.1237 +4.6411 + multi_subject: MTR in WM +161 +sct_run_batch +MTR in dorsal column +Here are the results of MTR quantification in the dorsal column of each subject between C2 and C5. Notice the remarkable inter-subject consistency. + + Checking QC report +162 +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 'Save Fails' to generate a qc_fail.yml file. +We have provided a sample output for you in the multi_subject folder. +A QC report is generated under qc/. As shown before, the QC report is useful to quickly assess the quality of the analysis pipeline. + +Once you're done QCing the segmentation results, click on 'Download QC Fails' to download the file qc_fail.yml. This file includes the path to all the segmentations that require manual edition. We will see how we can conveniently use that file for batch manual correction. + + 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. +163 +# 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. +We provide a script called manual_correction.py. This script will read the qc_fail.yml file and will loop across the segmentations that require manual correction. When you have hundreds of subjects to process, this function can be very convenient! + +For convenience, we will use SCT's Python environment to run this script. Before doing so, we need to make sure that an image viewer is installed and callable via the Terminal command line. In this course we use FSLeyes, but you can use another viewer (eg: ITKsnap, 3D Slicer). We also need to make sure it can be opened from within another virtual environment. + + Manual corrections +Once your setup is ready, you can run the manual correction script. + +164 +# 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 + +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. +After you run the script, it will check that all dependent software are installed, and then ask you for your name (for the output JSON files). + +Then, the first segmentation to correct will open in FSLeyes. In FSLeyes, click on 'Edit mode' (Alt + E), correct the segmentation, then save it with the same name (overwrite). Then, the next segmentation to correct will pop up, and so on and so forth. + +After the script ends, you will be able to re-run the analysis. + + 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. +165 +sct_run_batch -script process_data.sh -path-data data/ -path-output output_correction -jobs 3 +Re-run the analysis. This time, if the manual correction file exists, it will be used in lieu of doing the automatic segmentation. + +While the script is running, look for the log file of the subjects where manual correction was done, to verify that the manual correction is used. + + Provenance of script/data +166 +Looking at the main sct_run_batch_log.txt log file, you notice '?!?' next to git commit and git origin for the 'SCRIPT' and 'DATA' sections. If you were using a script or data from a git repository, the provenance information would be added here. This is an excellent way to ensure reproducibility of the analysis. + +See for example the log file for the spine-generic project. + +This is also useful when checking how SCT results evolve across versions, and how it is checked for. Go to GitHub release page, and see the results across versions, on each platform. + + Log files if error +167 +Log files are useful to spot errors in some participant data (e.g., file missing, wrong file name) +Log files are generated under the log/ folder. These contain the output of the entire processing for each subject. + +Moreover, at the bottom of the file process_data.sh, the script checks if certain files have been generated— usually this concerns important output files used for quantitative results (e.g., T2 segmentation). If for some reasons (e.g., bug, crash, input file missing) an output file is missing, the prefix 'err.' will be added to the log file. + + New and upcoming features +168 +Day Two + + Gray matter segmentation +Atlas-based analysis +Diffusion-weighted MRI +Functional MRI +Other features +Analysis pipelines with SCT +New and upcoming features +Conclusion +Day One + +Introduction +Installation +Segmentation +Vertebral labeling +Shape-based analysis +Registration to template +Register additional contrasts + +New features + +List of models: https://spinalcordtoolbox.com/stable/user_section/command-line/sct_deepseg.html +# Presented by PL + +sct_deepseg lesion_ms +Benveniste et al. ESMRMB 2025 https://github.com/ivadomed/ms-lesion-agnostic + Lesion Segmentation in Multiple Sclerosis +Deep Learning model trained on ~4,000 manually segmented scans +Robust to multiple contrasts, image orientation, resolution, MRI vendor and field strength +NEW +in v7.2 +171 +# Presented by PL +Recently, a new model was added to SCT. It allows to segment Multiple Sclerosis lesions on multiple contrasts. It was trained on around 4000 images accounting for a broad range of acquisition parameters such as contrasts, orientation, resolution, vendor … +The below GIF displays the segmentation predicted by the model (in red) overlapping the original MRI image. +This method is available as a task in sct_deepseg. + +sct_deepseg lesion_ms +Benveniste et al. ESMRMB 2025 https://github.com/ivadomed/ms-lesion-agnostic + Lesion Segmentation in Multiple Sclerosis +NEW +in v7.2 +172 +cd ../single_subject/data/t2_ms +# Segment the spinal cord which will be used for generating the QC +sct_deepseg spinalcord -i t2.nii.gz -qc ~/qc_singleSubj +# Segment MS lesions with one fold (faster inference) +sct_deepseg lesion_ms -i t2.nii.gz -qc ~/qc_singleSubj -qc-seg t2_seg.nii.gz -single-fold +# The output is `t2_lesion_seg.nii.gz` (the MS lesion segmentation) +fsleyes t2.nii.gz -cm greyscale t2_lesion_seg.nii.gz -cm red -a 70.0 & +# For a more robust (but longer) inference: remove -single-fold +# For a soft segmentation: add -soft-ms-lesion +lesions +Input +Binary segmentation +Soft segmentation +1 +0 +# Presented by PL +Here, we will apply the MS lesion segmentation model on a T2 axial scan of a person with MS. +The model is called using the sct_deepseg function. +The model outputs two nifti files: spinal cord segmentation and lesion segmentation + +List of models: https://spinalcordtoolbox.com/stable/user_section/command-line/sct_deepseg.html +New lesion segmentation tools + +174 +SCIseg: Deep learning-based segmentation of the spinal cord and intramedullary lesions in spinal cord injury (SCI) on T2w images +Works on different FOV, resolution (isotropic, axial, sagittal) +Works across different SCI etiologies (traumatic SCI, ischemic SCI, and degenerative cervical myelopathy) and phases (acute, sub-acute, and chronic) +Naga Karthik, Valošek et al. MICCAI AMAI 2024 +Naga Karthik, Valošek et al. Radiology: AI 2025 + Lesion Segmentation in Spinal Cord Injury +T2w Image +Lesion and Spinal Cord +Segmentation +Lesion +Spinal Cord +174 +# Presented by Jan/Julien +SCIseg is a deep learning model for segmentation of spinal cord injury (SCI) T2w images. +It initially segments the spinal cord followed by a intramedullary lesion segmentation in the subsequent step (nnUNet region-based approach). +The model was developed on multiple SCI datasets with heterogeneous image orientations, resolutions, and FOVs. +It generalizes to different phases of traumatic SCI and also to lesions in degenerative cervical myelopathy, which is a type of non-traumatic SCI characterized by chronic degenerative spinal cord compression + + Lesion Segmentation in Spinal Cord Injury +175 +sct_deepseg lesion_sci_t2 +t2 +t2_sc_seg.nii.gz and t2_lesion_seg.nii.gz +cd ../single_subject/data/t2_lesion +# Segment the spinal cord and intramedullary lesion using the SCIsegV2 model +# Note: t2.nii.gz contains a fake lesion for the purpose of this tutorial +sct_deepseg lesion_sci_t2 -i t2.nii.gz -qc ~/qc_singleSubj +# Two files are output: +# 1) t2_sc_seg.nii.gz: the spinal cord segmentation +# 2) t2_lesion_seg.nii.gz: the lesion segmentation +fsleyes t2.nii.gz -cm greyscale t2_sc_seg.nii.gz -cm red -a 70.0 t2_lesion_seg.nii.gz -cm blue-lightblue -a 70.0 & + +lesion +Lesion +Spinal Cord +Naga Karthik, Valošek et al. MICCAI AMAI 2024 +Naga Karthik, Valošek et al. Radiology: AI 2025 +# Presented by Jan/Julien +Here, we will apply the SCIseg model to a subject with fake lesion (because of the difficulty to share patient data). +The model is called using the sct_deepseg function. +The model outputs two nifti files: spinal cord segmentation and lesion segmentation + +Improved lesion volumetric analysis + + Lesion analysis +sct_analyze_lesion +Lesion and spinal cord segmentation can be used to compute various morphometric measures, such as number of lesions, lesion length, lesion volume, tissue bridges etc. +T2w image +Lesion +Spinal Cord +Segmentation +Lesion Analysis +177 +Naga Karthik, Valošek et al. MICCAI AMAI 2024 +Naga Karthik, Valošek et al. Radiology: AI 2025 Valošek J,, Pfyffer D et al. ISMRM 2025 Pfyffer D et al. Lancet Neurol 2024 +# Presented by Jan/Julien +Lesion and spinal cord segmentation masks can be used to calculate various morphometric measures such as number of lesions, lesion length, lesion volume, tissue bridges, etc. +The figure below shows examples of two such morphometric measures: lesion length and ventral and dorsal tissue bridges. + +# Compute various morphometric measures (number of lesions, volume, length, etc.) +sct_analyze_lesion -m t2_lesion_seg.nii.gz -s t2_sc_seg.nii.gz -qc ~/qc_singleSubj + +sct_analyze_lesion + Lesion analysis +t2_sc_seg.nii.gz +t2_lesion_seg.nii.gz +XLSX file: +QC report showing tissue bridges: +NEW +in v6.4 +178 +# Presented by Jan/Julien +Morphometric measures can be computed using the sct_analyze_lesion function. +This function requires two inputs: lesion segmentation and spinal cord segmentation +The function automatically computes several morphometric measures and saves them into an XLSX file. Moreover, the function generates an HTML QC report for tissue bridges. + + Atlas-based lesion analysis +sct_analyze_lesion -f +The sct_analyze_lesion -f flag allows you to provide a folder containing an template/atlas registered to an anatomical image. If specified, the function computes: +The proportion of lesion within each vertebral level and each region of the template/atlas (e.g. GM, WM, WM tracts) + + +# Warp the white matter atlas (if not warped before) +sct_warp_template -d t2.nii.gz -w ../t2/warp_template2anat.nii.gz +# The -f flag is used to specify the folder containing the atlas/template +sct_analyze_lesion -m t2_lesion_seg.nii.gz -s t2_sc_seg.nii.gz -f label -qc ~/qc_singleSubj + +179 +# Presented by Jan/Julien +Additionally, the sct_analyze_lesion function allows you to provide a folder containing an atlas/template registered to an anatomical image. +If specified, sct_analyze_lesion computes the proportion of lesion within each vertebral level and each region of the template/atlas (e.g. GM, WM, WM tracts). + +Gradient echo EPI cord segmentation + +sct_deepseg sc_epi +cd ../fmri/ +# Segment the spinal cord on gradient echo EPI data +sct_deepseg sc_epi -i fmri_moco_mean.nii.gz -qc ~/qc_singleSubj + EPISeg: GRE-EPI cord segmentation +181 +Banerjee et al. Imaging Neurosci 2025 +NEW +in v6.5 +Data training/testing: + +Gray matter segmentation + +183 +Deep learning based contrast and region agnostic segmentation model + Gray matter segmentation +NEW +in v7.1 +sct_deepseg graymatter +Laines-Medina et al. ESMRMB (2025) +https://github.com/ivadomed/model-gm-contrast-region-agnostic +Training Data: 1367 participants from 16 sites +3 field strengths +12 contrasts +9 pathologies/categories +Regions: +Cervical +Thoraco-lumbar +Acquisition types: +2D: Multi-angle +3D: Slabs / runs +# Presented by Nilser + + +Spinal canal segmentation + +sct_deepseg sc_canal_t2 + Spinal canal segmentation +Deep learning based segmentation of the spinal canal on T2w images +Robust to various FOVs, orientations, resolutions and pathologies +Robust to various orientations +Axial planes on healthy, SCI and DCM subjects +Robust to various regions of the spine +NEW +in v6.5 +185 +Salmona et al. In preparation +https://github.com/ivadomed/model-canal-seg + + Spinal canal segmentation +NEW +in v6.5 +cd ../t2 +# Segment the spinal canal +sct_deepseg sc_canal_t2 -i t2.nii.gz -qc ~/qc_singleSubj +# Check results using FSLeyes +fsleyes t2.nii.gz -cm greyscale t2_canal_seg.nii.gz -cm red -a 70.0 & +sct_deepseg sc_canal_t2 + +186 + + + + +Spinal cord to canal ratio +sct_compute_ascor +sct_compute_ascor -i-SC t2_seg.nii.gz -i-canal t2_canal_seg.nii.gz -perlevel -1 -o ascor.csv +NEW +in v7.2 +Adapted Spinal Cord Occupation Ratio +aSCOR(%) +Healthy controls +Patient +187 +# Presented by Sandrine +"Spinal cord parenchymal fraction (SCPF)", spinal cord reserve + +Full spine segmentation + +https://zenodo.org/records/13894354 + Spine segmentation +Deep learning based segmentation and identification of multiple spinal structures using TotalSpineSeg: Vertebrae, Intervertebral discs, Spinal cord and Spinal canal +NEW +in v6.5 +189 +# Presented by Nathan + + Spine segmentation +# Segment using totalspineseg +sct_deepseg totalspineseg -i t2.nii.gz -qc ~/qc_singleSubj +# Check results using FSLeyes +fsleyes t2.nii.gz -cm greyscale t2_step1_canal.nii.gz -cm YlOrRd -a 70.0 t2_step1_cord.nii.gz -cm YlOrRd -a 70.0 t2_step1_levels.nii.gz -cm subcortical -a 70.0 t2_step1_output.nii.gz -cm subcortical -a 70.0 t2_step2_output.nii.gz -cm subcortical -a 70.0 & +sct_deepseg +NEW +in v6.5 +190 +https://zenodo.org/records/13894354 +# Presented by Nathan + +https://github.com/ivadomed/SpineReports + Generating reports +Extracting spine morphometrics to generate personalized reports of the different structure segmented by totalspineseg is now possible using SpineReports +191 +# Presented by Nathan + +Spinal nerve rootlets segmentation + +193 +RootletSeg: Deep learning-based segmentation of nerve rootlets +Nerve rootlets can be used to estimate spinal levels +T2-w image +Nerve rootlets +Valošek et al. Imaging Neuroscience 2024 +Krejci et al. arXiv 2025 + Spinal nerve rootlets segmentation +NEW +in v7.0 +Fig ref: Cadotte et al., AJNR, 2015 +sct_deepseg rootlets +# Presented by Jan/Julien +Recently, the rootlets segmentation model (RootletSeg) was updated to segment both dorsal and ventral spinal nerve rootlets from T2-weighted and MP2RAGE images (including T1w). +The model provides level-specific (so-called multi-class) segmentation of the C2-Th1 dorsal and ventral spinal nerve rootlets. +Nerve rootlets can be used to obtain different spinal levels (e.g., C2, C3, C4, etc.). +These spinal levels can be used as an alternative to vertebral levels for the registration to the template to perform group-level analysis. + + + Spinal nerve rootlets segmentation +NEW +in v7.0 +# Segment the spinal nerve rootlets +sct_deepseg rootlets -i t2.nii.gz -qc ~/qc_singleSubj +# Check results using FSLeyes +fsleyes t2.nii.gz -cm greyscale t2_rootlets.nii.gz -cm subcortical -a 70.0 & +sct_deepseg rootlets +194 +Valošek et al. Imaging Neuroscience 2024 +Krejci et al. arXiv 2025 +# Presented by Jan/Julien +The rootlets segmentation model is available via the sct_deepseg function. +The model requires a single input: T2w or MP2RAGE image +It outputs level-specific segmentation of the dorsal spinal nerve rootlets + +Bédard et al. Imaging Neuroscience 2025 +sct_register_to_template -lrootlet + Rootlets-based Registration +Use automatic rootlets segmentation for registration to PAM50 template +Available in sct_register_to_template -lrootlet +195 +NEW +in v7.0 +# Presented by Sandrine +Typically, for template registration, we use the vertebrae to align the subjects. However, the vertebral levels do not correspond exactly to the spinal levels, which is limiting for fMRI group analysis that require a good alignment across subject + +The aim here is to use the automatic rootlets segmentation that Jan presented to improve the template registration. +Briefly, we first align the center of the rootlets segmentation with the PAM50 rootelts instead of the interverterbral discs. Then we continue with the same XY alignment of the spinal cord. + +sct_register_to_template -lrootlet + Rootlets-based Registration +Improves alignment across subjects +Potential to improve fMRI group maps +196 +Collaboration: Ken Weber (Stanford) +Bédard et al. Imaging Neuroscience 2025 +Activation maps (N=40) +# Presented by Sandrine +Some preliminary results. we show the an average of the ventral rootlets of the PAM50, of 233 subjects registered using the rootlets and of 233 subjects registered using the discs. + +We see that the shape of the rootlets is much better defined when using rootlets-based registration. +This has the potential to improve spatial normalization for fMRI analysis + +Upcoming features + + Spinal cord morphometry +Context: Analysis of SC morphometry based on segmentation +Using scikit-image ellipse fitting to compute AP and RL diameter is (sometimes) wrong +Problem: Over-estimated AP diameter in U-Shape cords +AP diameter (mm) +Upcoming features +198 +overestimation +# Presented by Sandrine + + + Spinal cord morphometry +New algorithm to compute AP diameter & asymmetry of the cord +Ongoing study (🇨🇭Zurich, 🇨🇦 Calgary, 🇨🇦 Toronto, 🇨🇦 Vancouver, 🇨🇿 Brno, 🇨🇿 Olomouc) +Would you like to participate? Email Julien! +Upcoming features +# Presented by Sandrine + + + Spinal cord asymmetry +sct_process_segmentation -symmetry +Healthy controls +Patient +Upcoming features +Legend red: original segmentation +blue: flipped hemi-cord yellow line: Hausdorff distance +# Presented by Sandrine + + + Update on PAM50 template +Fix mis-registration of WM/GM atlas in lumbar levels +Extend T2*w template towards lumbar cord +Add label for lumbo-sacral enlargement +WIP: Re-generate AMU & Zurich T2*w template and WM/GM atlas +Collaboration: Jan Valosek (Montreal/Zurich), Virginie Callot (AMU), Christian Kündig, Silvan Büeler, Gergely David (Zurich), Raphaelle Schlienger (AMU) +Upcoming features +AMU15 +Zurich42 +# Presented by Julien + + + Lumbar pathology diagnosis +Kaggle/RSNA challenge +Automatic diagnosis of neural foraminal narrowing (NFN), spinal canal stenosis (SCS), and subarticular stenosis (SAS +MRI +Segmentation +Attention map +TotalSpineSeg(*) +SpineDiagnosis(**) +Clinical report +Diagnosis: Foraminal stenosis at L4/L5 +Justification: compression of foramen at levels L4/L5 +# Presented by Thomas + + + Deep learning motion correction +Upcoming features +raw +moco(*) +mocoDL +dMRI +fMRI +(*)sct_dmri_moco -g 1 -param poly=0 -x nn +(*)sct_fmri_moco -g 1 -param poly=0 -x nn +P +A +S +I +R +L +S +I +R +L +A +P +# Presented by Julien + + +Poll Results + + Poll Results + + Conclusion +206 +Day Two + + Gray matter segmentation +Atlas-based analysis +Diffusion-weighted MRI +Functional MRI +Other features +Analysis pipelines with SCT +New and upcoming features +Conclusion +Day One + +Introduction +Installation +Segmentation +Vertebral labeling +Shape-based analysis +Registration to template +Register additional contrasts +We have reached the end of the course. We just have a few closing suggestions for you. + + Need help? +207 +Type command without argument, or with flag “-h”. + + Need help? +208 +http://forum.spinalcordmri.org/c/sct +Post any issue you are having on the sourceforge website. + +In order to help you efficiently, please be specific in the title (e.g., indicate output error) and also indicate the version you are running (e.g., v3.2.1). + +We welcome any suggestion for improvement / new feature requests! + + 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) +Online’23 +Online’24 + + Zoom pic 📸 + + Contribute to SCT +SCT is an open-source project +Contributions are welcome! 🎉 +Please see our contribution guidelines: https://github.com/spinalcordtoolbox/spinalcordtoolbox/wiki/Contributing +211 +Contributions can take the form of opening an issue, suggesting a feature, fixing a bug, implementing a feature, or even becoming a sponsor! + + Acknowledgements +Current: Julien Cohen-Adad, Joshua Newton, Mathieu Guay-Paquet, Jan Valosek, Naga Karthik, Nilser Laines Medina, Pierre-Louis Benveniste, Nathan Molinier, Sandrine Bédard, Rohan Banerjee, Maxime Bouthillier, Samuelle St-Onge, Thomas Dagonneau, Kalum Ost, Paul Hoareau. +Alumni: Abel Salmona, Ainsleigh Hill, Alexandru Foias, Alexandru Jora, Andreanne Lemay, Benjamin De Leener, Charley Gros, Christian Perone, Clara Giroux, George Peristerakis, Hee-Min Yang, Jérôme Carretero, Kateřina Krejci, Lucas Rouhier, Nicolas Pinon, Paul Bautin, P-O Quirion, Sara Dupont, Simon Lévy, Tanguy Duval, Thiago Rezende, Yehuda Warszawer +Core SCT developers +… and we thank all the collaborators and SCT users for their precious feedback!! ❤️ +Sponsors +Grants: \ No newline at end of file From 3c42572fda536e783fee7191d6a74853df59dc43 Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Wed, 19 Nov 2025 11:38:36 -0500 Subject: [PATCH 11/22] Revert "Temporarily commit course text to make testing easier" This reverts commit 53665c339b2877be75bbb8c75e27fcd9216f92d8. --- .../workflows/compare_script_to_course.yml | 3 +- remote.txt | 3145 ----------------- 2 files changed, 1 insertion(+), 3147 deletions(-) delete mode 100644 remote.txt diff --git a/.github/workflows/compare_script_to_course.yml b/.github/workflows/compare_script_to_course.yml index 2b3fb42..7493697 100644 --- a/.github/workflows/compare_script_to_course.yml +++ b/.github/workflows/compare_script_to_course.yml @@ -1,7 +1,6 @@ name: Compare SCT Commands on: - pull_request: workflow_dispatch: inputs: text_url: @@ -29,7 +28,7 @@ jobs: - name: Download remote text file run: | - # curl -L https://gist.githubusercontent.com/joshuacwnewton/3c554bf27111cf0020e5c124b66448c4/raw/ff08cbcf7738941008eca0fa54e024d98eea24e8/gistfile1.txt -o remote.txt + curl -L ${{ inputs.text_url }} -o remote.txt echo "✅ Downloaded remote file:" wc -l remote.txt diff --git a/remote.txt b/remote.txt deleted file mode 100644 index 8348351..0000000 --- a/remote.txt +++ /dev/null @@ -1,3145 +0,0 @@ -SCT Course, December 8-9 2025, (Virtual) - -Updated: 2025-11-17 -Course material for SCT v7.2 -Welcome to the SCT course! - -(Reminder for Presenter: -Open the slide deck link in a new logged-out (incognito/private) window to get the “View mode” for clean presentation with easy triple-click copy-paste.) -Record ZOOM -Present team: -core developers: Joshua Newton, Mathieu Guay-Paquet -presenters: Sandrine Bédard, Jan Valosek, Naga Karthik, Nathan Molinier - - Questions during the course -Zoom ‘general’ chat - - Printing these slides -If you wish to print these slides with presenter notes, do the following: -File -> Print preview -In the newly visible menu bar, click on "1 slide without notes" and change to "1 slide with notes" -Uncheck "Include skipped slides". -Download as PDF - - - Outline -4 -Day One - -Introduction -Installation -Segmentation -Vertebral labeling -Shape-based analysis -Registration to template -Register additional contrasts -Day Two - - Gray matter segmentation -Atlas-based analysis -Diffusion-weighted MRI -Functional MRI -Other features -Analysis pipelines with SCT -New and upcoming features -Conclusion -Here is the outline of the course. Each chapter will start with a brief theory, then will be followed by hands-on exercise that we will do together. - - - - Introduction -5 -Day One - -Introduction -Installation -Segmentation -Vertebral labeling -Shape-based analysis -Registration to template -Register additional contrasts -Day Two - - Gray matter segmentation -Atlas-based analysis -Diffusion-weighted MRI -Functional MRI -Other features -Analysis pipelines with SCT -New and upcoming features -Conclusion -This section introduces SCT software, what it can be used for, and some example applications. - - Quantitative MRI of the spinal cord -6 -Spectroscopy -Metabolism -Functional MRI -Neuronal activity -Functional MRI, DTI, MTR, T1, T2, etc. -Diagnosis/prognosis traumas, neurological diseases, cancers -Objective biomarkers for testing new drugs -Diffusion MRI -Axon integrity -Conventional MRI -Pathology -Magnetization transfer -Myelin integrity -MRI features several techniques that provide sensitive and specific metrics to the function, metabolism or microstructure of the central nervous system. For example, diffusion and magnetization transfer were shown to correlate with myelin content, and are therefore relevant for diagnosis applications in neurodegenerative diseases such as multiple sclerosis. - - Image processing -7 -How to process spinal cord multi-parametric MRI data? -brain data -? -spinal cord data -These techniques require advanced image processing methods. This is why for the past twenty years or so, several software packages have been developed to process brain multi-parametric MRI data. Some of these software, such as FSL, SPM or AFNI, are very popular and provide international researchers with a common analysis framework, enabling them to reproduce and compare research results. Such cross-validations are essential steps for further use in clinical diagnosis or by pharmaceutical companies for drug development. -While the same is true for spinal cord quantitative MRI, there has been no publicly-available and widely-distributed software dedicated to the spinal cord. Moreover, brain software cannot readily be applied to spinal cord data, because atlases and image features are very different. - - 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 -This lack of unified processing tools motivated the development of the Spinal Cord Toolbox, or SCT. - -Registration framework - Overview of SCT -9 -and many more features… -Segmentation -C3 -C5 -T1 -C1 -Template and atlas -2D slice-by-slice -Regularized across slices & time -Robust for DWI (group-wise) -Lesion analysis -Lesion Length -Shape-based analysis -_Orientation___________ -_Solidity ________ -_Eccentricity___________ -__ AP__ diameter -_Area__ _____ -_ _RL__ diameter -SCT -In brief, SCT features specific segmentation tools for the spinal cord, a multi-modal template and atlas, a framework to register multi-parametric MRI data to the template, and various tools for atlas-based analysis, motion correction, etc. - - 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. - -Review article: -Valošek & Cohen-Adad. Reproducible Spinal Cord Quantitative MRI Analysis with the Spinal Cord Toolbox. Magn Reson Med Sci 2024 - Template and Atlas: -Valošek* & Bédard* et al. A database of the healthy human spinal cord morphometry in the PAM50 template space. Imaging Neuroscience 2024 -De Leener et al. PAM50: Unbiased multimodal template of the brainstem and spinal cord aligned with the ICBM152 space. Neuroimage 2018 -Lévy et al. White matter atlas of the human spinal cord with estimation of partial volume effect. Neuroimage 2015 -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 - Segmentation: -Karthik* & Valošek* et al. SCIseg: Automatic Segmentation of Intramedullary Lesions in Spinal Cord Injury on T2-weighted MRI Scans Radiology AI 2024 -Valošek et al. Automatic Segmentation of the Spinal Cord Nerve Rootlets. Imaging Neuroscience 2024 -Bedard et al. Towards contrast-agnostic soft segmentation of the spinal cord. Arxiv Preprint 2023 -Gros et al. Automatic segmentation of the spinal cord and intramedullary multiple sclerosis lesions with convolutional neural networks. Neuroimage 2019 -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 -Dupont et al. Fully-integrated framework for the segmentation and registration of the spinal cord white and gray matter. Neuroimage 2017 -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 - Registration: -Beal E et al. Contrast-agnostic deep learning–based registration pipeline: Validation in spinal cord multimodal MRI data. Aperture Neuro 2023 -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 -https://spinalcordtoolbox.com/user_section/citing_sct.html -If you use SCT, please always cite the main SCT reference: De Leener et al. SCT: Spinal Cord Toolbox, an open-source software for processing spinal cord MRI data. Neuroimage 2017. - -Most of the methods implemented in SCT have been validated and published in peer-reviewed journals. For an exhaustive list of the references pertaining to SCT, see: -https://spinalcordtoolbox.com/user_section/citing_sct.html - - Applications (350+ 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. Neuroscience 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 -https://spinalcordtoolbox.com/overview/studies.html -Since its public release in 2014, SCT has been used in various applications, including structural MRI, fMRI and in various diseases such as MS, ALS and spinal cord injury. For an exhaustive list of the references pertaining to SCT, see: https://spinalcordtoolbox.com/overview/studies.html - - 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.) -12 -Yiannakas et al., Neuroimage Clinical 2015 -Application of SCT -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 -As a concrete example application, SCT was used to measure cord cross-sectional area (CSA) in the cervical cord. The fully automatic method of SCT showed similar results than the semi-automatic method of Horsfield et al. Having a fully-automatic means of measuring CSA removes user bias and makes it possible to analyse large database in a fast and reproducible way. - - Mapping MS lesions in the cord -13 -Eden et al., Brain 2019 -Application of SCT -Lesion Probability Map -N=642 (13 sites) -In this study, 642 patients from 13 clinical centers were recruited. Lesions were segmented by neuroradiologists, then all data were non-linearly registered to the PAM50 template in order to derive probability maps of MS lesion location in the cervical cord. - - Gray matter atrophy in ALS -14 -Paquin et al., AJNR 2017 -Application of SCT -Automatic GM segmentation -GM atrophy is a better discriminator of ALS than cord atrophy -Prediction at 1 year -Perone, Sci. Reports 2018 -In this study, SCT was used to segment the spinal gray matter of patients at an early stage of Amyotrophic Lateral Sclerosis (ALS). It was then demonstrated that spinal gray matter atrophy is a better biomarker than spinal cord atrophy, for distinguishing patients from healthy controls, and for 6-months prognosis of motor scores. - - Tract-based analysis in stroke patients -15 -Karbasforoushan et al. Nat. Commun. 2019 -Application of SCT -In this study involving patients with unilateral stroke, diffusion MRI was used to assess the integrity of the brainstem and the cervical spinal cord. Tract-based analysis performed with SCT helped identify altered sensorimotor pathways post-stroke in those patients. These results have implications for rehabilitation interventions post unilateral stroke. - - Combining PET-MRI to study pain -16 -Albrecht et al. Pain 2018 -Application of SCT -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. -Here, SCT was used for the first time on a combined PET-MR study. PET Standardized Uptake Values (SUVs) were extracted in the spinal cord at specific vertebral levels, based on the anatomical MRI, after registration with the PAM50 template. These results implicate immunoactivation at multiple levels of the nervous system as a potentially important and clinically relevant mechanism in human radicular pain, and suggest that therapies targeting immune cell activation may be beneficial for chronic pain patients. - - fMRI of the spinal cord -17 - - Applications of SCT - - 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 -19 -Cohen-Adad et al., Nature Protocols 2021 -Finally, we would just like to highlight a related project that has powered some of the aforementioned studies alongside with SCT. - -Spine generic is an analysis protocol for quantitative analysis of the spinal cord. Spine generic provides standardized analysis protocols for assessing spinal cord macrostructural and microstructural integrity. - - Spine Generic: Multi-center qMRI study -20 -Cohen-Adad et al., Scientific Data (2021) -Application of SCT -Multi-site (n=43), multi-subject (n=267) -Fractional Anisotropy (FA) averaged in WM between C2-C5 -Another example is a multi-center study, featuring two publicly-available datasets, which were acquired using the spine generic protocol. One acquired on a "traveling" single subject, scanned across 19 centers. The second dataset consists of 43 sites which scanned about 6 subjects, for a total of 267 subjects (260 when published). The dataset is well-curated and uses the latest technologies, such as the BIDS and Datalad for accessing the data. - - - - Distribution -OS supported -macOS (Intel and M1/M2/M3/M4) -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) -21 -Testing -Extensive testing: https://github.com/spinalcordtoolbox/spinalcordtoolbox/actions -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 -Here are some technical features. - - Course convention -22 -Links, references, etc. will go here -sct_function_name -Mandatory for this course -Try this at home -name of SCT function -Tips! -NEW -in v7.2 -For the remaining sections of the course, we will be using some common visual elements. - -In the interest of time, not all hands-on examples will be run today (indicated by the red dot), but they are still included in this document for you to try later. - - Installation -23 -Day One - -Introduction -Installation -Segmentation -Vertebral labeling -Shape-based analysis -Registration to template -Register additional contrasts -Day Two - - Gray matter segmentation -Atlas-based analysis -Diffusion-weighted MRI -Functional MRI -Other features -Analysis pipelines with SCT -New and upcoming features -Conclusion -In this section we will learn how to install SCT. - - Recommended terminal -24 -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.) -Before we install SCT, we will talk a little bit about terminals. You will need to use a terminal program to install SCT and run SCT commands. - - Installation of stable release -25 -Instructions for macOS: https://spinalcordtoolbox.com/user_section/installation/mac.html -Installation for Linux: https://spinalcordtoolbox.com/user_section/installation/linux.html -Instructions for Windows: https://spinalcordtoolbox.com/user_section/installation/windows.html -Installation instructions on Docker & Apptainer (NEW!) -https://spinalcordtoolbox.com/stable/user_section/installation/docker.html -https://spinalcordtoolbox.com/stable/user_section/installation/apptainer.html -Note: After installing, make sure to open a fresh, brand new terminal window, then run the following commands to check if SCT has been installed correctly: -sct_check_dependencies -echo $SCT_DIR -# For the “echo” command, you should see SCT’s installation directory in the output - -NEW -in v7.2 -If you prefer to install the development version from Github, instructions can be found there: https://spinalcordtoolbox.com/user_section/installation/linux.html#option-2-install-from-github-development -The advantage of the “github-master” version is that it is always up-to-date with the latest developments. - -ℹ️ As of v6.3 there is a cuda GPU installation mode for running deep learning models faster. More information at: https://github.com/spinalcordtoolbox/spinalcordtoolbox/wiki/Contributing%3A-Installing-SCT-for-GPU -This is an experimental installation, we would love to hear your feedback. - -https://github.com/spinalcordtoolbox/spinalcordtoolbox/pull/4421 - - Resize your terminal -26 -100 chars -SCT display is optimized for Terminal window with 100 characters wide (mostly to display help). - -So, now that we’ve confirmed SCT has been installed correctly, it is a good time to make your terminal window a bit larger. - - Basic Unix commands -27 -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 parent directory -cd .. -# List contents of ‘dir_name’ -ls dir_name -# Cleanup files/directories -rm dir_name/example.txt -rm -r dir_name - - - -Triple-click with left mouse button to select from this slide, then copy and paste in your Terminal -You don’t need to be an expert of Unix commands to use SCT. However, basic commands are needed to be able to navigate in your directories and files. - - Download course material -28 -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 -Download publicly available example data for the purpose of this course. - -Important: we recommend that you do not process data under the sct installation directory. Go outside of SCT install folder before doing your analyses. E.g.: go to your home folder with: cd ~ - - batch_single_subject.sh -29 -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: -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 - -A little bit of background information before we begin -The setup for the SCT course is now complete. - -However, before we begin running SCT commands on the course data, we have a little more background information to cover. - - 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 -31 -You can also inspect output images using a NIfTI image viewer. - -SCT is particularly adapted to both fsleyes (comes with FSL) and ITKSnap, because each SCT command ends with a link to copy/paste and open in those viewers (N.B: this also works with the older fslview). - - NIfTI file formats (.nii vs .nii.gz) -Stands for “Neuroimaging Informatics Technology Initiative” -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 -32 -Speaking of NIfTI images, here is a quick explainer about NIfTI image formats. - -.nii stands for “NiFTi image”. The extra .gz means that the NiFTi file has been “GZipped” (compressed). - -Save physical storage, use nii.gz! - - 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: -33 -/home/Julien superduper folder/my file name.nii.gz -Use dashes (-) and/or 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 -... -When working with SCT, you will often want to customize the output filename using the -o flag. When choosing filenames, please avoid using spaces. - -Note: underscores are better for double clicking. - -Onto the first section of the SCT Course - - Segmentation -35 -Day One - -Introduction -Installation -Segmentation -Vertebral labeling -Shape-based analysis -Registration to template -Register additional contrasts -Day Two - - Gray matter segmentation -Atlas-based analysis -Diffusion-weighted MRI -Functional MRI -Other features -Analysis pipelines with SCT -New and upcoming features -Conclusion -With that background out of the way, now we can begin the SCT course proper. - -In this first section, we will learn how to segment the spinal cord contour. - -Theory -Here we will quickly review the theory behind spinal cord segmentation in SCT - - Spinal cord segmentation -New segmentation tool: -“contrast-agnostic” (2024) -Command: sct_deepseg -Legacy methods: -DeepSegSC (2019) -Command: sct_deepseg_sc -PropSeg (2014) -Command: sct_propseg -37 -Anat (T2w or T1w) -Our contrast-agnostic model was introduced in 2024, and is our recommended approach for spinal cord segmentation. It is accessed via the sct_deepseg command. - -Earlier methods include DeepSegSC, launched in 2019, which can be accessed with the command sct_deepseg_sc, and PropSeg, developed in 2014, which is run using sct_propseg. These tools represent the evolution of segmentation technologies over the years. - - Limitations of contrast-specific models -Historically, automatic SC seg has been limited to specific contrasts (T1w, T2w, T2*w, DWI) -Each contrast had its own “deep learning model” -New contrasts required new models to be trained -T1 “like” -T2 “like” -T1w -dwi -fmri -T2w -mt --c t1 --c t2 -DWI “like” --c dwi -T2* “like” --c t2s -T2*w -38 - - Limitations of contrast-specific models -CSA across MRI contrasts -✅ Stable CSA -Cross-sectional area (CSA) -New model! -39 -Contrast-specific models -sct_deepseg spinalcord -39 -⚠️ CSA varies -Bédard, Naga Karthik et al. Medical Image Analysis 2025 -# Presented by Sandrine -Not only having contrasts-specific models is limiting on the user-point, but it also provides different morphometrics measures across MRI contrasts. For example, we can compute the spinal cord cross-sectional area averaged at C2-C3 vertebral levels and we obtain different CSA values across contrasts But with the new model, we obtain stable CSA across 6 differents contrasts. - - Contrast-agnostic segmentation - - - - - - -Train a single model using many contrasts -Use “soft” GT (averaged across contrasts) during training → same GT for all contrasts -sct_deepseg spinalcord -Bédard, Naga Karthik et al. Medical Image Analysis 2025 -40 -# Presented by Sandrine -To do so, we first trained a model using many contrast instead on just one -And, to achieve stable CSA across contrast, we created an average segmentation for each subjects of 6 contrasts to get one unique soft ground truth and to use that for training instead. - -Hands-on -# Presented by Julien - - -Spinal cord segmentation -42 -sct_deepseg spinalcord -# Go to T2 contrast folder -cd data/t2 -# Try cord segmentation using deep learning. Note the flag "-qc" to generate a QC report of the segmentation. -sct_deepseg spinalcord -i t2.nii.gz -qc ~/qc_singleSubj -# You can also choose your own output filename using the “-o” argument -sct_deepseg spinalcord -i t2.nii.gz -o test/t2_seg_2.nii.gz - -t2 -t2_seg -Note that when running a new sct_deepseg model for the first time, if the model is not installed, it will install it automatically. - -You can inspect the quality of the segmentation via the web QC and/or via your favorite image viewer. - -In general, we recommend using sct_deepseg as the default method for all contrasts, but if you find that it underperforms on your data, then try sct_propseg or sct_deepseg_sc and then decide which method you prefer to use for your data. - -Importantly, you should stick to one method when doing a study, because there might be biases in terms of cord contour definitions between the methods. - - 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 -# Presented by Julien - - - Quality Control (QC) Reports -44 -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 -An important aspect of using tools like SCT is inspecting output images. - -SCT provides a browser-based QC report feature to make this process easier. - - Other segmentation tools -Contrast-agnostic segmentation is SCT’s recommended “general purpose” tool for SC seg -However, you may have a more specific use-case -e.g. mouse, lumbar, MS/SCI lesions, compressed cord, etc. where “general-purpose” tool produces poor results -SCT has other tools you can try: -SCT’s past SC models (sct_propseg, sct_deepseg_sc) -One of sct_deepseg‘s 17 different segmentation models -sct_propseg/sct_deepseg_sc/sct_deepseg - - Model gallery -46 -sct_deepseg -Our team regularly releases new models under sct_deepseg -In recent versions, we’ve added new models for segmentation of: -Lumbar (T2) -SCI lesion (T2) -Spinal rootlets (T2) -We provide a Model gallery -You can also check available models by running: -# List of available models -sct_deepseg -h - - Vertebral labeling -47 -Day Two - - Gray matter segmentation -Atlas-based analysis -Diffusion-weighted MRI -Functional MRI -Other features -Analysis pipelines with SCT -New and upcoming features -Conclusion -Day One - -Introduction -Installation -Segmentation -Vertebral labeling -Shape-based analysis -Registration to template -Register additional contrasts -In this section we will learn about vertebral labeling, which is a necessary step for both shape-based analysis and registration to template. - -Theory - - Disc labeling -49 -[1] Warszawer et al. ResearchGate Preprint (2025) -sct_deepseg totalspineseg -Rationale -Labeling intervertebral discs along the spinal cord is commonly performed to: -Align subjects to a reference space (e.g., a template such as PAM50). -Extract metrics at specific levels (e.g., cross-sectional area or lesion location to study correlations with sensorimotor dysfunctions). - -TotalSpineSeg -Deep learning based -Contrast-agnostic -FOV-agnostic -Robustness towards pathology/artifact - - Conventions for point labels -50 -The images in this slide show the convention used in SCT for point labels specifically. We demonstrate both vertebral mid-body labels and disc labels, as both can be generated by SCT. - -Here, you can see that Value 3 —> C2-C3 disc, Value 4 —> C3-C4 disc, etc. - -Note that label 49 corresponds to the ponto-medullary groove, label 50 corresponds to the ponto-medullary junction, and label 60 corresponds to the new conus medullaris label. These labels exist in the PAM50 template, and are used in special applications, such as computing distance from PMJ along the spinal cord (49/50), or registering lumbar data (60). - -Hands-on - - Label vertebrae/discs -52 -sct_deepseg totalspineseg -# Vertebral labeling (can be used with any MRI contrast) -sct_deepseg totalspineseg -step1-only -i t2.nii.gz -qc ~/qc_singleSubj -# Check QC report: Go to your browser and do "refresh". -# Note: Here, four files are generated: -t2_step1_cord.nii.gz —> soft segmentation of the spinal cord -t2_T1w_step1_canal.nii.gz —> soft segmentation of the spinal canal -t2_T1w_step1_output.nii.gz —> segmentation of the vertebrae, discs, canal and cord -t2_step1_levels.nii.gz —> discs labels -t2 -t2_step1_levels.nii.gz -3 -4 -5 -6 -7 -8 -9 -10 -11 -Two files representing either vertebral or disc levels are output from sct_label_vertebrae. Either of them can be subsequently used for the template registration and/or for computing metrics along the cord. - - Manual discs labeling -53 -sct_label_utils -create-viewer -# If TotalSpineSeg did not work, you might want to do it 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 inter-vertebral disc. E.g. Label 3: C2/C3, Label 4: C3/C4, etc." -t2 -t2_discs.nii.gz -3 -4 -5 -6 -7 -8 -9 -10 -11 -“viewer” -Here, the value “3” in -create-viewer 3 corresponds to the C2-C3 disc, which is the label we would like to create manually. - -If labeling is wrong (e.g., each vertebrae is assigned one or two levels superior than what it should be), initializing the C2-C3 disc can help. In that case, a viewer pops-out and you just have to click at the posterior tip of C2-C3 disc. - - Shape-based analysis -54 -Day Two - - Gray matter segmentation -Atlas-based analysis -Diffusion-weighted MRI -Functional MRI -Other features -Analysis pipelines with SCT -New and upcoming features -Conclusion -Day One - -Introduction -Installation -Segmentation -Vertebral labeling -Shape-based analysis -Registration to template -Register additional contrasts -In this section we will learn to compute the cord CSA across the superior-inferior axis, as well as other shape metrics (such as diameter, eccentricity, solidity, and orientation). - - Compute CSA with disc labels -55 -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 -discfile t2_step1_levels.nii.gz -o csa_c3c4.csv - -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-23 -6.5 -/Users/julien -143:186 -3:4 - 74.9532 -2.4125 -1.2151 -0.2260 -9.8769 -1.5364 -.csv files are easily imported in Excel, Numbers, Python, etc. -NEW -in v7.2 -# Presented by Sandrine -Here for example, we compute the cord cross-sectional area (CSA) and average it between C3 and C4 vertebral levels. When using the “-vert” flag, sct_process_segmentation will look for a vertebral labeling file, which enables to specify the levels on which you would like to compute CSA. This default label file is label/template/PAM50_levels.nii.gz - -By default, sct_process_segmentation will output a file called csa.csv, which contains CSA results (mean and STD) as well as the angles between the cord centerline and the normal to the axial plane. Angle_AP corresponds to the angle about the AP axis, while angle_RL corresponds to the angle about the RL axis. These angles are used to correct the CSA, therefore if you obtain inconsistent CSA values, it it a good habit to verify the value of these angles. - -N.B. If a segmentation is not perfect (e.g., over-segmentation caused by surrounding tissue, or under-segmentation caused by a lesion), then the computed CSA will be impacted. So you want to make sure the spinal cord segmentation is correct in the slices of interest before quantifying CSA. - - Compute CSA per level/slice -56 -sct_process_segmentation -# Aggregate CSA value per level -sct_process_segmentation -i t2_seg.nii.gz -vert 3:4 -discfile t2_step1_levels.nii.gz -perlevel 1 -o csa_perlevel.csv -# Aggregate CSA value per slices -sct_process_segmentation -i t2_seg.nii.gz -z 30:35 -discfile t2_step1_levels.nii.gz -perslice 1 -o csa_perslice.csv -Slice (I->S) -VertLevel -MEAN(area) -STD(area) -143:164 -4 -76.5782 -1.5781 -165:186 -3 -73.3282 -1.9668 -Slice (I->S) -VertLevel -MEAN(area) -STD(area) -30 -10 -41.1479 -0.0 -31 -10 -41.7494 -0.0 -32 -10 -39.9284 -0.0 -33 -10 -40.6677 -0.0 -34 -9 -41.9585 -0.0 -35 -9 -41.3494 -0.0 -# Presented by Sandrine -The flag -perlevel is used to enable/disable metric output per individual vertebral level, while the flag -perslice is used to enable/disable metric output per individual slice. - -Notes for -perslice: -We still specify -vertfile in order to fill in the information for the VertLevel column -STD is 0.0 because no averaging is being performed (since these are individual slices) - - Compute CSA using PMJ -57 -Bédard et al. Front. Neuroimaging 2022 -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 -Slice (I->S) -DistancePMJ -MEAN(area) -STD(area) -164:201 -64.0 -72.8608 -1.96212 -# Presented by Sandrine -A drawback of vertebral level-based CSA is that it doesn’t consider neck flexion and extension. - -To overcome this limitation, the CSA can instead be computed using the distance to a reference point. Here, we use the Pontomedullary Junction (PMJ), since the distance from the PMJ along the centerline of the spinal cord will vary depending on the position of the neck. - -First, the PMJ is detected. Then, this PMJ label is passed to sct_process_segmentation using the -pmj flag. - -N.B. This feature is only available on SCT v5.4 and higher. - - Shape analysis: Other metrics -Valošek, Bédard et al. NeuroLibre 2023; Imaging Neuroscience 2024 -Martin et al. BMJ Open 2018 -Horáková M et al. QIMS 2022 -sct_process_segmentation -MEAN(diameter_AP) -MEAN(diameter_RL) -MEAN(eccentricity) -MEAN(orientation) -MEAN(solidity) -5.1653 -9.8062 -0.9270 -8.1536 -0.9221 -58 -# Presented by Jan -The output of sct_process_segmentation also includes metrics to analyse the shape of the spinal cord in the axial plane, such as AP diameter, RL diameter, eccentricity, solidity, and orientation. These are of particular interest for studying spinal cord compression. See [Martin et al. BMJ Open 2018] and [Horáková M et al. QIMS 2022] for example applications in degenerative cervical myelopathy. - -The left panel shows a sagittal T2w image of a subject with spinal cord compression. The compression is highlighted by the red arrow and shown in detail in the axial image below. - -The red dashed lines in the charts illustrate how the shape metrics change at the compression slice. - - Shape analysis: normalization -sct_process_segmentation -normalize-PAM50 -Slice (I->S) -VertLevel -MEAN(area) -MEAN(diameter_AP) -MEAN(diameter_RL) -MEAN(eccentricity) -MEAN(solidity) -923 -2 -70.0814 -7.9577 -11.1847 -0.7027 -0.0200 -59 -# Bring shape metrics to the PAM50 anatomical dimensions -sct_process_segmentation -i t2_seg.nii.gz -discfile t2_step1_levels.nii.gz -perslice 1 -normalize-PAM50 1 -o csa_PAM50.csv -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! -Valošek, Bédard et al. NeuroLibre 2023; Imaging Neuroscience 2024 -# Presented by Jan -The sct_process_segmentation script allows you to bring/normalize the shape metrics to the anatomical dimensions of the PAM50 spinal cord template. - -The PAM50 template will be covered in detail in the next section. But, briefly, the spinal cord template is a standard reference space created by a combination of data from many subjects. - -The normalization is done by adding the -normalize-PAM50 flag to the sct_process_segmentation command. - -Normalizing the shape metrics into the PAM50 template space is relevant, for example, during group-level analysis. - - Shape analysis: normalization -sct_process_segmentation -normalize-PAM50 -60 -Once the metrics are normalized into the PAM50 anatomical dimensions, you can compare them with a database of healthy normative values -single subject -CSA -Valošek, Bédard et al. NeuroLibre 2023; Imaging Neuroscience 2024 -x -Slice (I->S) -VertLevel -MEAN(area) -MEAN(diameter_AP) -MEAN(diameter_RL) -MEAN(eccentricity) -MEAN(solidity) -923 -2 -70.0814 -7.9577 -11.1847 -0.7027 -0.0200 -# Presented by Jan -Another use of normalizing shape metrics to the PAM50 template space is to compare against a database of healthy normative values. - -The blue curves in the figure show the mean and standard deviation of the cross-sectional area across vertebral levels computed from a dataset of 203 healthy controls (spine-generic multi-subject dataset). - -The table at the bottom presents shape metrics computed for our subject and normalized to the PAM50 anatomical dimensions. - -Since all values are now in the same anatomical dimensions, you can compare the subject's CSA (the red cross) with the normative values (the blue cross). - - - Application: detection of cord compression -sct_process_segmentation -normalize-PAM50 -61 -Valošek, Bédard et al. NeuroLibre 2023; Imaging Neuroscience 2024 -Compression C5/C6 -# Presented by Jan - -This slide shows an application for the detection of spinal cord compression. -The blue curves show the mean and standard deviation of the AP diameter across vertebral levels computed from a dataset of 203 healthy controls (spine-generic multi-subject dataset). -The red curve shows the AP diameter for a subject with spinal cord compression. We can see the decrease of the AP diameter at the compression level at the C5/C6 intervertebral disc. - - - Quantify spinal cord compression -Valošek, Bédard et al. Imaging Neuroscience 2024 -Bédard, Valošek et al. Spine J. 2025 -sct_compute_compression -62 -MSCC: Maximum spinal cord compression -# Presented by Jan -The sct_compute_compression script is another tool related to spinal cord shape analysis. It allows you to compute metrics quantifying spinal cord compression. - -The computation is based on the MSCC (maximum spinal cord compression) formula. -The shape metrics (such as AP diameter) at the level of compression (red arrow in the left sagittal T2w image) are normalized using the non-compressed levels above and below the compression site. - -If the -normalize-hc flag is used, the shape metrics are normalized using a database of healthy controls, providing MSCC_norm (accounting for the intra-subject variability). Additionally, you can filter the healthy database to account for the influence of sex and age on the morphometric measures, aiming to reduce inter-subject variability - -MSCC can be computed not only for AP diameter but also for other shape metrics such as CSA, RL diameter, eccentricity, and solidity; see the -metric flag. - - Quantify spinal cord compression -sct_compute_compression -cd ../t2_compression -# Segment the spinal cord of the compressed spine -sct_deepseg spinalcord -i t2_compressed.nii.gz -qc ~/qc_singleSubj -# Label the vertebrae using the compressed spinal cord segmentation -sct_label_vertebrae -i t2_compressed.nii.gz -s t2_compressed_seg.nii.gz -c t2 -qc ~/qc_singleSubj -# Generate labels for each spinal cord compression site. -sct_label_utils -i t2_compressed.nii.gz -create 30,152,99,1.0:30,156,118,1.0:30,157,140,1.0:31,160,159,1.0 -o t2_compressed_labels-compression.nii.gz -# Compute ratio between AP-diameter at level of compression vs. above/below -sct_compute_compression -i t2_compressed_seg.nii.gz -vertfile t2_compressed_seg_labeled.nii.gz -l t2_compressed_labels-compression.nii.gz -metric diameter_AP -normalize-hc 0 -o ap_ratio.csv -# Compute AP diameter ratio, normalized with healthy controls -sct_compute_compression -i t2_compressed_seg.nii.gz -vertfile t2_compressed_seg_labeled.nii.gz -l t2_compressed_labels-compression.nii.gz -metric diameter_AP -normalize-hc 1 -o ap_ratio_norm_PAM50.csv -Note: Normally labeling compression sites would be done manually using fsleyes' "Edit mode -> Create mask" functionality. -👉 See the tutorial for more details. - - Registration to template -64 -Day Two - - Gray matter segmentation -Atlas-based analysis -Diffusion-weighted MRI -Functional MRI -Other features -Analysis pipelines with SCT -New and upcoming features -Conclusion -Day One - -Introduction -Installation -Segmentation -Vertebral labeling -Shape-based analysis -Registration to template -Register additional contrasts -In this section we will learn how to register a new image to a pre-existing template, and how to use this registration for computing cord CSA across the superior-inferior axis. - -Theory - - - PAM50: Template of the spinal cord -Spinal cord and brainstem template -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 -66 -👉 More info available on SCT website -Template-based (or atlas-based) analysis is commonly used for brain studies, and requires a template. In SCT, the latest and recommended template is the PAM50 template. PAM stands for “Polytechnique”, “Aix-Marseille University” and “Montreal Neurological Institute”, the three collaborative institutions. The PAM50 templates consists of a T1w, T2w, T2*w, white and gray matter probabilistic atlas, white matter atlas of tracts (30 tracts) and gray matter parcellation (6 regions). - -Note: since SCT v4.0.0, the PAM50 is in the same coordinate system as the MNI ICBM152 Brain template. - -Anat (T2w or T1w) -Segmentation -Vertebral labeling -Template & forward/backward transform -Straightening -1. Affine -2. Non-rigid -Concatenate warping fields -. -C3 -T3 - PAM50: Registration pipeline -Once the subject is registered to the template (and vice versa), we generate warping fields that can be used to transform the template objects (e.g., white matter atlas) onto the subject. - -Anat (T2w or T1w) -Segmentation -Vertebral labeling -Template & forward/backward transform -Straightening -1. Affine -2. Non-rigid -Concatenate warping fields -. -C3 -T3 -First, we will take the previous vertebral label file and select specific vertebral landmarks in the spinal cord, which will be used for template matching with the landmarks from the PAM50 template. - - -Anat (T2w or T1w) -Segmentation -Vertebral labeling -. -C3 -T3 -Template & forward/backward transform -Straightening -1. Affine -2. Non-rigid -Concatenate warping fields -First, we will take the previous vertebral label file and select specific vertebral landmarks in the spinal cord, which will be used for template matching with the landmarks from the PAM50 template. - -Anat (T2w or T1w) -Segmentation -Vertebral labeling -Straightening -. -C3 -T3 -Template & forward/backward transform -1. Affine -2. Non-rigid -Concatenate warping fields -Straightening -After we select which vertebral landmarks we wish to use, we can begin the registration process by “straightening” the spinal cord in order to align it with the PAM50 template (which exhibits a “straight” spinal cord). - - Spinal cord straightening -Internal distance is preserved (as opposed to slice-by-slice translations) -71 -De Leener et al. JMRI 2017 -sct_straighten_spinalcord -https://drive.google.com/file/d/0Bx3A13n3Q_EAQll6Ykg2aFRZRHM -The straightening works by finding, for each point along the spinal cord, the mathematical transformation to go from a curved centerline to a straight centerline. Two warping fields are output: warp_curve2straight.nii.gz and warp_straight2curve.nii.gz. - -A major advantage of the implemented straightening algorithm, is that instead of doing a slice-wise translation (which does not account for the through-plane deformation), here the inner geometry of the cord is preserved. Another advantage is that it outputs a forward and a backward warping field (ITK-compatible), which could be concatenated with subsequent transformations, as will be seen later. - -To get a better intuition about how this straightening works, see this movie: -https://drive.google.com/file/d/0Bx3A13n3Q_EAQll6Ykg2aFRZRHM - -Anat (T2w or T1w) -Segmentation -Vertebral labeling -Straightening -1. Affine -. -C3 -T3 -Template & forward/backward transform -Concatenate warping fields -2. Non-rigid -After straightening, an affine transformation is applied to match the vertebral levels of the subject to that of the template. Then, a non-rigid transformation is estimated for finely match the subject’s cord shape to the template. - -Anat (T2w or T1w) -Segmentation -Vertebral labeling -Template & forward/backward transform -Straightening -1. Affine -2. Non-rigid -Concatenate warping fields -. -C3 -T3 -Once the subject is registered to the template (and vice versa), we generate warping fields that can be used to transform the template objects (e.g., white matter atlas) onto the subject. - -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 -By transforming the template to the subject space, metrics such as MTR can be extracted at specific levels and in specific tracts. We have already seen full-cord CSA measurements, but later on we will get into metric extraction and atlas-based analysis. - -Hands-on - - - Selecting landmarks for registration -76 -sct_label_utils -# Select the C2-C3 and T1-T2 intervertebral disc labels. These labels are needed for template registration. -sct_label_utils -i t2_step1_levels.nii.gz -keep 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 -t2_labels -t2_seg_labeled -value = 3 -value = 9 -. -. -To make things easy, we can reuse the disc label file that was previously generated to extract two intervertebral disc labels as landmarks for template registration. - - Register to template -77 -sct_register_to_template -# Register t2->template. -sct_register_to_template -i t2.nii.gz -s t2_seg.nii.gz -ldisc 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. -t2 -t2_seg -t2_labels -template2anat -anat2template -warp_anat2template -warp_template2anat -. -. -This is the main command for registering your subject to the template. It outputs the PAM50 template (PAM_T2 if you selected -c t2, PAM_T1 if you selected -c t1) registered to your data, and your data registered to the PAM50 template. It also output the forward and backward warping fields (warp_anat2template.nii.gz and warp_template2anat.nii.gz.), which can be used by other software (e.g., SPM, FSL). - - Registration results -78 -https://drive.google.com/file/d/0Bx3A13n3Q_EATGZrTTFwcThOeEk -https://drive.google.com/file/d/0Bx3A13n3Q_EAWElGQkZIRXVTWjg -PAM50 to t2 -t2 to PAM50 -The links at the bottom of this slide redirect you to a gif animation, which alternates between the subject and the PAM50_t2 registered to the subject. In general, we always recommend doing this visual evaluation to assess the quality of registration. - - 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. -79 -sct_register_to_template - - - 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= -80 -[1] https://stnava.github.io/ANTs/; [2] De Leener et al, Neuroimage 2017; [3] Béal et al. Aperture Neuro 2023 -sct_register_to_template, sct_register_multimodal -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 -This non-rigid transformation can be estimated using a variety of algorithms. The main difference with brain algorithms is that here, the transformation is constrained within the z-plane (axial plane). The default transformation should work for most cases, but you might want to play with parameters to optimize registration with your particular contrast and resolution. - -If you need help with this complex procedure, please do not hesitate to contact SCT team on the help forum: -http://forum.spinalcordmri.org/c/sct - - 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. -81 -sct_register_to_template -Choosing these parameters can be overwhelming. Don’t hesitate to ask for help if you are not sure what to use: https://forum.spinalcordmri.org/c/sct - - Demo: Advanced -param -82 -sct_register_to_template -# Register t2->template with modified parameters -sct_register_to_template -i t2.nii.gz -s t2_seg.nii.gz -ldisc t2_labels_vert.nii.gz -qc ~/qc_singleSubj -ofolder advanced_param -c t2 -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 -t2 -t2_seg -t2_labels -template2anat -anat2template -warp_anat2template -warp_template2anat -. -. -Here, we demo what it looks like to change the advanced parameters using the -param argument. - -You can see that we have specified “step=1”, “step=2”, and “step=3”, with different metrics and algorithms for each step. - -We have chosen the metrics and algorithms so that “step=1” starts out using coarse adjustment (algo=rigid), with each step after that performing fine-tuning (algo=bsplinesyn, algo=syn) with progressively fewer iterations. - - 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: -83 -sct_register_to_template -sct_register_to_template -i t2.nii.gz -s t2_seg.nii.gz -ldisc t2_step1_levels.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 1: 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 -Note 2: -lspinal can be used to rely on spinal levels instead of vertebral levels. - - Example in compressed cord -84 -# 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 (). -sct_register_to_template -i -s -ldisc -ref subject -param step=1,type=seg,algo=centermassrot:step=2,type=seg,algo=columnwise -IMAGE -SEGMENTATION(*) -*: manual adjustment likely required -anat2IMAGE -wm/gm atlas -This page shows that sct_register_to_template can also be used with compressed cords, though you will likely need to use some level of manual segmentation and labeling in order to get the required images. - -What can we do with our registration results? -We have run `sct_register_to_template`. Now what? Well, we will explore the PAM50 template in further detail and show the utility of registration. - - Exploring the PAM50 template -You can go to the SCT installation folder and open up “data/PAM50” to explore the features. -Contains several subfolders with useful files: -We will bring these files to the subject space. -Here we will take a moment to look at the PAM50 template in more detail. - -Speaker: Open the PAM50 on fsleyes, and show the T1w, spine and vert levels - - Warp template objects -87 -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 -# 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 & -t2 -warp_template2anat -/label/template -Now that we have the transformation files, we can apply them to bring the template in the subject’s native space. - -By default, the function sct_warp_template will select the PAM50 template, which is located in your $SCT_DIR/data/PAM50 installation folder. If you wish to use another template, select it with the flag -t. - - 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 -88 -sct_warp_template, sct_apply_tranfo -In this course, we will be showing you how to do a subject-centric analysis, meaning that the template is registered to the subject, and metrics will be extracted in the subject’s space. - -However, note that it is also possible to warp all subjects to the template, and do the analyses there. For example, this could be useful for looking at an average map of FA across subjects. - - More on warping fields -89 -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 -d -w -To concatenate several warping fields: -sct_concat_transfo -d -w -Warping fields -To make warping field FSL/SPM-compatible: -# Convert ITK warping field to FSL warping field -sct_image -i -to-fsl -o -# NB: '' is the source image you will be applying the warping field to, and is used as a reference for the source voxel space -Those warping fields are using ITK convention, which is not compatible with software such as FSL or SPM. If you are using non-ITK third-party software for post-processing (e.g., group analysis in fMRI), you can transform your warping field using sct_image to have them compatible with your software. - -WARNING: The ITK/FSL warping field conversion shown here only works if the source and destination files are in the same voxel space. If they are different, you will need to provide a second image to act as a reference for the destination space. More details can be found on https://spinalcordtoolbox.com/overview/concepts/warping-fields.html#compatibility-with-non-itk-software-fsl-spm. - -How to add another contrast (MTR, diffusion, etc.)? -So far, we have seen how to use the PAM50 to quantify the morphometry of the cord on anatomical images. Now we will see how to use template registration for computing qMRI metrics. - - Register additional contrasts -91 -Day Two - - Gray matter segmentation -Atlas-based analysis -Diffusion-weighted MRI -Functional MRI -Other features -Analysis pipelines with SCT -New and upcoming features -Conclusion -Day One - -Introduction -Installation -Segmentation -Vertebral labeling -Shape-based analysis -Registration to template -Register additional contrasts - - -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 -Let’s say you acquire other scans during the same sessions, such as DTI, MT, etc. The key here is to register the PAM50 template to those additional scans. We will now see how to do it. - - Segment MT data -93 -sct_register_multimodal, sct_propseg -# Go to mt folder -cd ../mt -# Segment cord -sct_deepseg spinalcord -i mt1.nii.gz -qc ~/qc_singleSubj - - -mt1 -mt1_seg -Like for the anatomical T2 image, the first step is to obtain a proper segmentation of the cord, here on an MT-weighted scan. - - Create mask -94 -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 -mt1 -mask_mt1 -mt1_seg -Based on the segmentation, we create a mask, which is subsequently used to obtain better registration results between scans (here, between mt1 and the template, and later between mt0 and mt1). - - Register template to MT1 -95 -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 -https://drive.google.com/file/d/0Bx3A13n3Q_EAYTVVQTFYMjhDU0U -Then, we register the PAM50 to the mt space. Note that we don’t use the function sct_register_to_template, but instead we use sct_register_multimodal. The reason being that we start from the pre-registration (i.e. PAM50—>t2 done previously), which already contains information about vertebral labeling. We assume that the subject did not move “too much” in the superior-inferior direction (usually a fair assumption) and we only refine the PAM50—>mt registration by account for small motion (e.g., head tilting) and potential distortions that are inherent to the contrast. - -Here, the destination image is the mt1 scan, which exhibits good cord/CSF contrast (“t2”-like). - -N.B. There could sometimes be 'edge effects' on the top and/or bottom slice due to the warping field not being properly defined at the edge, so it is possible that the top and/or bottom slice of the registered template looks cropped. - - Register template without anatomical image -96 -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 - -mt1 -mt1_seg -mt1_label -. -Registration with -initwarp requires pre-registration, but in some cases you won't have an anatomical image to do a pre-registration. - -So, as an alternative, you can register the template directly to a metric 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 with: sct_label_utils -i mt1_seg.nii.gz -create-seg -1,4 - -For more information, type sct_label_utils -h - - Warp template to MT -97 -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 & -label/template/ -label/atlas/ -WM atlas -mt1 -warp_template2mt -After the registration transformation is computed, you can run sct_warp_template to bring the template objects to the MT space. Here, in addition to the label/template/ folder, the folder label/atlas/ is created, which contains the white matter atlas. - -Note that the current framework is blind to spinal cord internal structure (because anatomical T1 or T2 don’t show GM). While the gray matter coming from the template shows a plausible location of the gray matter for a specific subject, there might be some inaccuracies. If you have an additional scan with good gray/white matter contrast, it might be beneficial to include it in the framework as will be detailed in the next section. - - 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 & -https://drive.google.com/file/d/0Bx3A13n3Q_EATG96VGhjTWJrYkk -98 -While we are in the mt folder, we will also demonstrate how to compute the magnetization transfer ratio (MTR). This will be useful later in the course, where we will demonstrate how extract MTR for specific white matter tracts. - -First, it is necessary to co-register the mt0 and mt1 images. We use sct_register_multimodal to register the mt0 scan on the mt1 scan. Here, we chose algo=slicereg, which provides a robust slice-wise registration, regularized along z. The output interpolation is spline. - - Compute MTR -99 -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 -mt1 -mt0_reg -mtr -0 -50 -Once mt1 and mt0 are co-registered, we can compute mtr (given in percentage). - -Note: when you open the output MTR in FSLview, you might see a flat grey image. This might be due to extreme outlier values which stretch the display contrast. You can adjust the min/max value on the FSLeyes interface (e.g., set it to min=0, max=60). - -Note that we decided to register mt0 on mt1 and not the other way around. There is a reason behind it: since MTR calculation imposes to have mt0 as denominator, we prefer to reduce the amount of noise on this quantity and therefore apply the registration-related interpolation on the mt0. Although the difference is negligible. - -How to register the lumbar region to the PAM50 template? - - - 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 sc_lumbar_t2 -i t2_lumbar.nii.gz -qc ~/qc_singleSubj - -# 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 -The first step in the registration pipeline is to segment the spinal cord. - -Note that instead of using the usual sct_deepseg_sc, we use the specialized “sct_deepseg” model “seg_lumbar_sc_t2w”, which is specifically designed for the lumbar region. - -Currently this model supports T2w only, but we are planning to introduce a new contrast agnostic segmentation model which will support other contrasts (more info in the “New and upcoming features” section of the course). - - Selecting landmarks for registration -Using only disc labels will often result in misalignment of the terminal end of the spinal cord -So, we introduced 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 -Next, we will select landmarks. However, this time, we will not just run sct_label_vertebrae and select 2 disc labels (as before). - -This is because, even if the discs are aligned between subject + PAM50 template, the cord itself may be misaligned, due to variation in the positioning of the cord relative to the discs. (Leftmost example) - -To address this, we want to use a new landmark to specifically align the terminal end of the spinal cord. This is label “60” (conus medullaris). - -You can either choose to use 1 label (just 60), or 2 labels (60 + some other landmark, e.g. one of the uppermost discs). You have some flexibility here – just make sure to stick with whatever approach you choose across all of your subjects. - - 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 -qc ~/qc_singleSubj -# 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! -⚠️ Warning! It is important that both labels are created within the same axial slices where the cord segmentation exists. If it does not, the registration to template will crash. (See: Issue #3873) -If the cord does not extend to the conus medullaris, you should manually extend the cord segmentation. - -In order to precisely select suitable coordinates, you will want to use a viewer to overlay the segmentation onto the anatomical image. - -For this sample data, we have already predetermined the specific coordinates we want to label: -[27, 76, 187]: Posterior tip of the T9-T10 disc -[27, 79, 70 ]: Lowermost voxel of the spinal cord segmentation (i.e. the terminal end of the spinal cord – the conus medullaris) - - - - - Register lumbar to template -104 -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. -t2_lumbar -t2_lumbar_seg -t2_lumbar_labels -template2anat -anat2template -warp_anat2template -warp_template2anat -17 • -60 • -Here, we specifically choose -param to improve the quality of the registration. - -Step 3 uses `algo=syn`, which greatly helps to fine-tune the registration. - -End of Day 1 Material - - - End of Day 1 Poll -We would like to hear from YOU 😊 -Polling session… -👉 link to poll -Results will be announced at the end of Day 2 - -Start of Day 2 Material - - - Gray matter segmentation -108 -Day Two - - Gray matter segmentation -Atlas-based analysis -Diffusion-weighted MRI -Functional MRI -Other features -Analysis pipelines with SCT -New and upcoming features -Conclusion -Day One - -Introduction -Installation -Segmentation -Vertebral labeling -Shape-based analysis -Registration to template -Register additional contrasts -Gray matter segmentation can be used to compute metrics such as cross-sectional area (CSA) of the gray matter. It can also be used to refine the template registration, by accounting for the spinal cord gray matter shape (which was not considered in the previous section). In this section, we will learn how to segment the GM, and how to use it for refining template registration. - -Theory - - - GM segmentation methods -SCT features a deep learning method for GM segmentation called: sct_deepseg graymatter -Algorithm: Deep learning nnUnet [1] -Pros: High accuracy, robust to pathologies, contrast-agnostic -The alternative method sct_deepseg_gm [2] is less performant overall and only limited to T2*-like contrasts (GM bright, WM dark). -110 -[1] Laines-Medina et al. ESMRMB conference 2025 -[2] Perone et al., Sci Report 2018 -sct_deepseg graymatter -NEW -in v7.0 -For segmenting the gray matter, SCT features the function sct_deepseg_gm, which is based a deep learning architecture trained from 232 subjects (~4000 slices). DeepsegGM obtained the best Dice score amongst all other methods that participated in the GM challenge [Prados et al., Neuroimage 2017]. It performs particularly well in presence of pathologies. - -Note that for the past few years, another method named sct_segment_graymatter was available. It used a multi-atlas based segmentation, originally inspired from [Asman et al. MIA 2014]. This method no longer available in SCT, due to the outperforming results of sct_deepseg_gm. If researchers wish to use this legacy method, they will have to install an older version of SCT (v3.2.7). - -Hands-on - - - Segment GM and WM -112 -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 graymatter -i t2s.nii.gz -qc ~/qc_singleSubj -# Full spinal cord segmentation -sct_deepseg spinalcord -i t2s.nii.gz -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 -thr 0 -o t2s_wmseg.nii.gz -t2s -t2s_gmseg -t2s_wmseg -In this course we will use sct_deepseg_gm. The only required input is an image with a T2*-like contrast (GM brighter than WM) and sufficient resolution to distinguish the GM, as shown in the image. - -By default, sct_deepseg_gm outputs binary segmentation, although it is also possible to obtain the un-thresholded segmentations with the flag -thr with values ranging from 0 to 1. Note that the output values of sct_deepseg_gm correspond to the output of the CNN and are not necessarily usable for any sort of partial volume correction or probabilistic interpretation. - -Since we also want the WM segmentation (see later why), we segment the cord and subtract the GM seg from it. - -Note that we use the flag -thr 0 in case some voxels in the GM segmentation are not included in the cord segmentation. That would results in voxels in the WM segmentation having the value “-1”, which would cause issues with the registration. - - CSA of GM and WM -113 -# 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 -CSA (mm2) -gray matter -white matter -t2s_gmseg -t2s_wmseg -The computed GM and WM segmentations can now be used to compute the cross sectional area of GM and WM. This is achieved using sct_process_segmentation. - -Note that here, we do not use the angle correction because the estimation of the cord centerline derivative might be too sensitive to the shape of the GM and/or WM, and as a result, a wrong angle might introduce spurious CSA estimation. In general, if the angle is small, the over-estimation of the CSA will also be small (cos(angle)~1). With axial slices acquired orthogonal to the cord, this is a fair assumption. - - Extract signal intensity in GM -114 -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. -Slice (I->S) -Label -Size [vox] -BIN() -STD() -2:12 -t2s_wmseg -2352 -1274.8536 -207.1855 -2:12 -t2s_gmseg -599 -1495.0286 -209.3065 -SCT also provides the sct_extract_metric, tool which allows you to use single mask files (binary or probabilistic) to average metrics within an image. - -In this case, we will use the white and gray matter masks to extract the signal intensity from the original T2* images. - -This method was successfully applied to the monitoring of myelopathic progression with multiparametric quantitative MRI in [Martin et al. PLoS One 2018]. - -How to account for white and gray matter segmentations during template registration? -As mentioned previously, we would like to use the GM segmentation to refine the template registration. Let’s see how to do this. - -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 -The procedure is shown in purple. The idea is to start from the pre-registration (e.g., t2w—>PAM50) and refine the registration between the WM shape and the PAM50_wm atlas. - - GM-informed template registration -117 -# 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 -t2s -t2s_wmseg -PAM50_wm (unregistered) -PAM50_wm (registered) -As previously done for registering the template to mt1, we use the intermediate template->t2 transformation, which has the necessary information about vertebral level. The difference however, is that instead of using the cord segmentation for the type=seg parameter, here we use the white matter segmentation, which contains both the cord contour and the GM contour. - -ℹ️ Most of the time, the improvement of using GM registration is small. In some cases it can even make it worse (because the result will largely depend on the quality of the GM segmentation), so in general we don’t recommend going through this 2-step registration. - - Register another metric -118 -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 -t2s -PAM50_t2 (reg) -PAM50_gm (reg) -PAM50_wm (reg) -Now that we have estimated a transformation between the template and the t2s data which account for GM shape, we can now register the template to the mt data using the template->t2s transformation as initialization (warp_template2t2s.nii.gz). - -Again, we rely on the cord segmentation only for registering the template to the mt data in order to be less sensitive to image artifact. The difference here (when compared to p.68) is that the information about the GM shape is enclosed in the transformation, producing registration results that are supposedly more accurate. - -Note that because the superior-inferior coverage of the T2*w scans is smaller than the MT scan, the concatenated warping field will only be defined in the region that overlaps between the T2*w and the MT scans. - - Atlas-based analysis -119 -Day Two - - Gray matter segmentation -Atlas-based analysis -Diffusion-weighted MRI -Functional MRI -Other features -Analysis pipelines with SCT -New and upcoming features -Conclusion -Day One - -Introduction -Installation -Segmentation -Vertebral labeling -Shape-based analysis -Registration to template -Register additional contrasts -In this section, we will learn how to quantify metrics (e.g., DTI, MT) using an atlas-based analysis approach. - -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 (%) -Now that we have registered the template to the subject, we can start quantifying some MRI metrics. - -Theory - - - White matter atlas -122 -Lévy et al., Neuroimage 2015 -Based on: Standring, Gray's Anatomy 2008 -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) -A prerequisite for any atlas-based analysis is to have an atlas. In SCT, a digitalized version of the Gray’s Anatomy spinal cord white matter atlas [Standring, Gray's Anatomy 2008] was merged with the PAM50 template. For more information on the procedure, see [Lévy et al., Neuroimage 2015]. - -The atlas is composed of 30 WM tracts, 6 GM regions and the surrounding CSF. The reason for including the CSF is to be able to account for partial volume effect during metric estimation, as explained in the following slides. - - White matter atlas -123 -cerebrospinal fluid -white matter -gray matter -S=0 -S=50 -apparent value in voxel: S=25 -Let’s imagine that the metric value you would like to quantify is 50 in the WM and 0 in the CSF. Because of the coarse resolution of MRI, the apparent value within the voxel will be a mixture between the WM and CSF compartment, yielding the value 25. This phenomenon is called “partial volume effect”. As we will see, there are ways to minimize it or overcome it. - - Quantify metrics with atlas -124 -Lévy et al., Neuroimage 2015 -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 -Because of its simplicity, the traditional method to quantify metrics is to use a binary mask: voxels labeled as “1” (i.e. in the mask) are selected and values within those voxels are averaged to produce, e.g., the average FA inside the spinal cord. As mentioned in the previous slide, this method suffers from partial volume effect and the resulting metric could be biased by the surrounding tissues. - -Instead of using binary masks, we could use weighted masks, which effectively “weight” the contribution of voxels at the interface (e.g., mask value = 0.1) vs. voxels well within the tissue of interest (e.g., mask value = 0.9). While this method (available as -method wa in SCT) minimizes PVE, it does not solve it. - -Alternatively, methods using Gaussian mixture modeling can be used to estimate the “true” value within the region of interest. Here, we benefit from the fact that the metric is measured within thousands of voxels, where the partial volume for each compartment (e.g., white matter, gray matter, CSF) is known. We then use a maximum likelihood estimation (-method ml) to estimate the metric value within each compartment. This approach assumes that within each compartment, the metric is homogeneous. - -Because Maximum Likelihood estimation is sensitive to noise, especially in small tracts, we recommend using the Maximum a Posteriori (-method map), which uses a prior based on the average metric value within the CSF, WM and GM compartment. - -Note that methods ml and map need prior warping of the WM atlas to your data, whereas you could use bin and wa with any binary mask. - - Validation of atlas-based analysis -125 -Lévy et al., Neuroimage 2015 -De Leener et al., Neuroimage 2017 -1 -0 -Atlas creation -20% noise & randomized values in tracts -Bootstrapping -Less than 2% error in “large” tracts -To demonstrate the sensitivity of each method to the amount of noise, to the size of the tract (framed here as “fractional volume”) and to the spatial resolution, we performed bootstrap simulations based on a synthetic MRI phantom. Here is an example of simulation results in realistic conditions, showing that the map and ml methods provide reliable metrics estimate, even in relatively small tracts (e.g., only 2% error in the rubro-spinal tract). For more details, see [Lévy et al., Neuroimage 2015] (construction of the phantom, effect of noise, contrast) and [De Leener et al., Neuroimage 2017; Appendix] (effect of spatial resolution). - -Hands-on - - - The file info_label.txt -127 -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 -The file info_label.txt lists the existing WM tracts nifti files (ID 0—>36), as well as the “combined labels” which could be used for quantifying metrics within a combination of tracts. - -If you want to add more tract combinations for all your studies, instead of editing the file label_info.txt for each subject, you can also edit this file under your SCT installation folder. Each time you will run sct_warp_template, the modified label_info.txt will be copied to each new subject. - -Note that SCT code uses the label IDs to fetch relevant data for processing, so if you wish to generate your own info_label.txt, make sure to choose the correct label IDs. For more information please contact SCT team. - - 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: -128 -Details of the example for editing the info_label.txt file can be seen on this forum’s post: -http://forum.spinalcordmri.org/t/how-to-create-a-hemicord-mask/33/2 - - Extract MTR in white matter -129 -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" -Slice (I->S) -VertLevel -Label -Size [vox] -MAP() -STD() -0 -None -white matter -0 -None -None -1 -6 -white matter -41.6452 -54.5386 -10.6744 -2 -6 -white matter -61.4869 -40.7888 -5.4038 -3 -6 -white matter -66.9520 -55.3711 -4.6303 -4 -5 -white matter -68.8959 -52.4616 -5.1589 -5 -5 -white matter -73.2353 -52.8584 -5.3990 -6 -5 -white matter -75.8461 -52.6179 -4.7946 -… -… -… -… -… -… -20 -1 -white matter -76.2700 -53.8761 -15.2921 -21 -None -white matter -0 -None -None -In this example, we compute, for each slice, MTR within the spinal cord WM. The label volume fraction is indicated as “Size [vox]”, which gives you a sense of the reliability of the measure. In this example, for each slice, the metric was computed based on ~70 voxels. As demonstrated in [De Leener et al., Neuroimage 2017; Appendix], assuming an SNR of 10, having at least 240 voxels results in an error smaller than 1%, while having 30 voxels results in an error inferior than 2%. - - Extract MTR in white matter -130 -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 -# 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 -62.8214 -52.8518 -2.9936 -5:15 -WM right lateral corticospinal tract -68.8171 -52.6106 -3.6469 -Slice (I->S) -VertLevel -Label -Size [vox] -MAP() -STD() -7:16 -2:4 -dorsal columns -223.9491 -53.5445 -3.2687 -In this example, we compute MTR within the right and left corticospinal tract. The number of voxels in each tract is about 67, therefore, as mentioned in the previous slide, the approximate error is less than 1.5% (assuming an SNR of at least 10, and no registration error). - -You can also restrict the quantification to specific vertebral levels (flag -vert) or slice (flag -z), although be careful to always check the associated volume fraction. If too low, your quantifications will be unreliable. If you publish, we recommend including the volume fraction associated with all estimated metrics. - - Diffusion-weighted MRI -131 -Day Two - - Gray matter segmentation -Atlas-based analysis -Diffusion-weighted MRI -Functional MRI -Other features -Analysis pipelines with SCT -New and upcoming features -Conclusion -Day One - -Introduction -Installation -Segmentation -Vertebral labeling -Shape-based analysis -Registration to template -Register additional contrasts -In this section we will learn how to process diffusion-weighted data, in particular: motion correction and registration to the template. - - What is dMRI? -dMRI is sensitive to random water molecule movement (= diffusion) -dMRI can be used to compute metrics reflecting tissue microstructure (e.g., FA) or for fiber tracking (tractography) -Fig ref: fsl.fmrib.ox.ac.uk – FSL Course -Fig ref: David et al., Nature Rev Neur, 2019 - - Preprocess dMRI data -133 -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 spinalcord -i dmri_dwi_mean.nii.gz -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 -Here, the reason we compute the mean from the dMRI data is simply to obtain a 3D volume (instead of 4D) that can be used to get a first coarse cord segmentation. Once the coarse segmentation is obtained, we use it to create a mask around the cord which we will pass to the moco command: this accelerates the processing and makes it more accurate. - - Motion correction for dMRI -134 -Xu et al., Neuroimage 2013 -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 “moco_params.tsv” (mean-square displacement) and the QC report -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: -SCT features a complex motion correction algorithm, which is inspired by [Xu et al., Neuroimage 2013]. The key aspects of this algorithm are as follows: -SliceReg: Slice-wise registration regularized along the Z direction (based on the function antsSliceRegularizedRegistration from ANTs, and described in [De Leener et al., Neuroimage 2017]). -Grouping: there is the possibility to group successive volumes in order to have sufficient SNR to estimate a reliable transformation. If your data are very low SNR you can increase the number of successive images that are averaged into group with the flag -g. -Iterative average: after registering a new group to the target image (which is usually the first DWI group), the target is averaged with the newly registered group in order to increase the SNR of the target image. -Outlier detection: if a detected transformation is too large, it is ignored and the previous transformation is used instead. -Masking: in order to estimate motion of the cord, ignoring the rest of the tissue, there is the possibility to include a mask with the flag -m -For more information, see: sct_dmri_moco -h - -A QC report for motion correction is also generated with the flag -qc. It shows the motion corrected vs. non-motion corrected scans, slice-by-slice and for each volume, for convenient comparison. - -The output “moco_params.tsv” shows the mean-square displacement (mean(sqrt(X^2 + Y^2))) for each slice. For more details about this metric, see this interesting discussion thread: https://github.com/spinalcordtoolbox/spinalcordtoolbox/issues/4344. - - Register template to dMRI -135 -# Segment SC on motion-corrected mean dwi data (check results in the QC report) -sct_deepseg spinalcord -i dmri_moco_dwi_mean.nii.gz -qc ~/qc_singleSubj -# Register template->dwi via T2 to account for cord shape (which is better defined in T2) -# 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 ../t2/warp_template2anat.nii.gz -initwarpinv ../t2/warp_anat2template.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 -At the end of motion correction, three files are created: the motion-corrected dMRI data (dmri_moco.nii.gz), the mean diffusion-weighted data excluding the b=0 (dwi_moco_mean.nii.gz) and the mean b=0 data (b0_moco_mean.nii.gz). - -Usually we recommend using dwi_moco_mean.nii.gz for cord segmentation because it has an excellent cord/CSF contrast. - -Once the cord is segmented, we register the template to it. Here we choose the PAM50_t1 which has similar contrast than the mean DWI data. We used the flag -initwarp ../t2/warp_template2anat.nii.gz to rely on the previously-registered template to our anatomical T2w data, but we could have also used -initwarp ../t2s/warp_template2t2s.nii.gz to account for the gray matter shape, although this latter approach is more constraining (it requires to have a good quality T2*w image) and in some cases, the registration is not necessarily better. - -You also noticed the flag -initwarpinv ../t2/warp_anat2template.nii.gz, which implies that the reverse transformation (dmri—>template) will also be generated, and could be used if you want to bring all your subjects to the template space, e.g., for obtaining group FA maps. - - Compute DTI -136 -[1] Garyfallidis, Front Neuroinform 2014 [2] Chang, Magn Reson Med 2005 -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: You can alternatively use the flag "-method restore" to estimate 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 -dmri_moco -bvecs.txt -———————————————————— -bvals.txt -———————————————————— -FA -MD -AD -RD -Here, we compute the diffusion tensor. SCT relies on the excellent dipy library for computing dMRI metrics [Garyfallidis et al., Front Neuroinform 2014]. As explained in the comments above, you can use the robust fitting method “RESTORE”, which provides better immunity to pulse-related signal drop-out in DWI data. - -Please note that SCT is mainly used for dMRI “pre-”processing, which is why SCT only includes the simple DTI model. For the "more advanced" models, users can use third-party software (e.g., dipy, MRtrix, etc.). - - Functional MRI -137 -Day Two - - Gray matter segmentation -Atlas-based analysis -Diffusion-weighted MRI -Functional MRI -Other features -Analysis pipelines with SCT -New and upcoming features -Conclusion -Day One - -Introduction -Installation -Segmentation -Vertebral labeling -Shape-based analysis -Registration to template -Register additional contrasts -In this section we will learn how to process functional MRI data. - - What is fMRI? -Chen and Glover, Neuropsychol Rev (2015) -Functional MRI (fMRI) is an imaging technique that measures activity in the central nervous system by detecting changes in blood oxygenation and flow, reflecting neuronal activity. It primarily captures Blood Oxygen Level-Dependent (BOLD) contrast images, which show areas of increased neural activity. Common types of fMRI images include resting-state fMRI, used to study functional connectivity by examining brain activity in the absence of tasks, and task-based fMRI, which identifies regions activated during specific tasks or stimuli. Typically, gradient-echo echo planar images (EPI) are acquired, as they provide good sensitivity to the BOLD signal. - -These images are often complemented by high-resolution anatomical scans, like T1-weighted or T2-weighted images, for accurate localization and structural reference. - -For more details, see: https://mriquestions.com/uploads/3/4/5/7/34572113/chen_glover_fmri_review_2015art3a10.10072fs11065-015-9294-9.pdf - - Analysis of fMRI data -139 -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 -# Cord segmentation on motion-corrected averaged time series -sct_deepseg spinalcord -i fmri_moco_mean.nii.gz -qc ~/qc_singleSubj/ -# TSNR before/after motion correction with QC report -sct_fmri_compute_tsnr -i fmri.nii.gz -sct_fmri_compute_tsnr -i fmri_moco.nii.gz -sct_qc -i fmri_tsnr.nii.gz -d fmri_moco_tsnr.nii.gz -s fmri_moco_mean_seg.nii.gz -p sct_fmri_compute_tsnr -qc ~/qc_singleSubj/ -# Register the template to the fMRI scan. -sct_register_multimodal -i "${SCT_DIR}"/data/PAM50/template/PAM50_t2s.nii.gz -iseg "${SCT_DIR}"/data/PAM50/template/PAM50_cord.nii.gz -d fmri_moco_mean.nii.gz -dseg fmri_moco_mean_seg.nii.gz -param step=1,type=seg,algo=centermass:step=2,type=seg,algo=bsplinesyn,slicewise=1,iter=3:step=3,type=im,algo=syn,metric=CC,iter=3,slicewise=1 -initwarp ../t2/warp_template2anat.nii.gz -initwarpinv ../t2/warp_anat2template.nii.gz -owarp warp_template2fmri.nii.gz -owarpinv warp_fmri2template.nii.gz -qc ~/qc_singleSubj -“-identity 1” skips translation/deformation, and only matches dimension, resolution, and orientation. -Here is an example of pre-processing of an fMRI dataset. The first step is to perform motion correction. For robust motion correction, we like to rely on a mask that tightly surrounds the spinal cord. Because the spinal cord segmentation is unreliable on non-motion corrected GRE EPI scans, we bring the anatomical T2w segmentation (or T1w if you don’t have any T2w) into the space of the fMRI scan. Then, we create the mask, we run the motion correction, and we segment the spinal cord on the motion-corrected averaged time series. We compute TSNR before and after and compute the QC report to compare TSNR before and after motion correction. - -Motion correction: We invite you to play with the motion correction parameters, because they are specific to the data (eg, resolution, noise, artifacts, etc.). - -Registration to the template: because data quality in GRE EPI scans is often “so-so”, it is important to always visually check the quality of the cord segmentation, and if necessary, manually correct it. The quality of the segmentation will have an impact on the quality of the registration. - -⚠️ Comparing TSNR on linearly-interpolated motion-corrected data is wrong. If you do so, re-run moco using nn interpolation. - - Spinal labeling for fMRI -140 -[1] Frostell et al. Front Neurol. 2016 -Vertebral labeling only gives a “rough” idea of where the spinal nerves project in the spinal cord. Probabilistic spinal labeling [1] is available in SCT -⚠️ This is a probabilistic, not individual, mapping of spinal levels -Location of the spinal level: $SCT_DIR/data/PAM50/template/ -So far, we have only used vertebral and/or disc labeling for template-based registration. However, knowing the position of the spinal levels (i.e. where the nerve roots connect to the cord) could be more informative from an anatomo-functional standpoint. For that purpose, we have integrated the work of Frostell et al., which provides a one-to-one mapping between vertebral and spinal levels. This is particularly useful for fMRI studies wherein researchers are interested in the spinal levels of activated neurons. For more details on how the labels are generated, see https://spinalcordtoolbox.com/overview/concepts/pam50.html#spinal-levels. - - Spinal labeling for fMRI -130 -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 -C3 -C3 -C4 -C5 -C6 -C7 -C4 -C5 -C2 -Vertebral levels -Spinal levels -When warping the template to the fMRI data, the spinal levels are automatically warped under ./label/template/PAM50_spinal_levels.nii.gz. - - Other features -142 -Day Two - - Gray matter segmentation -Atlas-based analysis -Diffusion-weighted MRI -Functional MRI -Other features -Analysis pipelines with SCT -New and upcoming features -Conclusion -Day One - -Introduction -Installation -Segmentation -Vertebral labeling -Shape-based analysis -Registration to template -Register additional contrasts -We will now look at a few other features that could be useful for your analyses. - - 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_deepseg (*NEW*) -sct_fmri_compute_tsnr (*NEW*) -sct_detect_pmj -sct_dmri_moco -sct_fmri_moco -sct_get_centerline -sct_image -stitch -sct_label_utils -sct_label_vertebrae -sct_process_segmentation -sct_register_multimodal -sct_register_to_template -sct_straighten_spinalcord -sct_warp_template -143 -sct_qc -An important aspect of MRI processing is quality control. What we have seen so far in SCT, is that after each process, the Terminal window displays a command that could be copy/pasted, for opening fsleyes/fslview and do visual QC. However, this is only done on an individual subject basis, and it is not convenient if you have several processes and hundreds of subjects. - -Since SCT v3.0.3, we have introduced an alternative QC method which is more versatile and intuitive. After running a process, result images are generated and organized into a web page for convenient viewing. The syntax to open the QC report in your default web browser is displayed in green on your Terminal (open “xxx”). Below are some useful shortcuts: -up/down arrow: navigate across processes -right arrow: toggle segmentation overlay - -The benefit of this QC report, is that when hundreds of subjects are run in a pipeline, this single browser window allows you to quickly skim through all processed subjects. Another advantage is that you can easily zip the entire QC folder (only a few MB) and share it with your colleagues/collaborators, or even include a link to the report in publications. - - Quality Control (QC) Reports -144 -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). -See live demo with sct_deepseg_sc failed cases. - -The failed cases listed in the output YAML file can be used by a script called ‘manual-correction.py’ that loops across the failed cases and opens an image viewer for the user to manually correct the segmentations. The corrected segmentations are saved according to the BIDS specifications (under the derivatives/labels/ folder). See for example: https://spine-generic.readthedocs.io/analysis-pipeline.html#segmentation-and-vertebral-labeling - -Later on in the course, we will demonstrate how to use this script, so stay tuned. - - SCT-FSLeyes integration -145 -Another cool feature is the integration of SCT within FSLeyes, powered by the Python scripting plugin capabilities. The next slides explains how to do it. - - 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. There will be more in the future if the feature is popular. -146 -See live demo with t2s.nii.gz file. - - Smooth along spinal cord -147 -sct_smooth_spinalcord -no smoothing -z-smoothing -Isotropic smoothing -smoothing along centerline -follows curvature -This smoothing method is similar to 2d cortical surface smoothing in FreeSurfer, only this one is 1d and follows the cord centerline. - -This function can be used to improve sensitivity of fMRI results while minimizing contamination from CSF - -It can also be used to obtain more reliable cord segmentations, because smoothing will sharpen the edge of the cord and will blur out possible artifacts at the cord/CSF interface. - - Smooth along spinal cord -148 -sct_smooth_spinalcord -cd ../t1 -# Segment the spinal cord using the usual sct_deepseg command -sct_deepseg spinalcord -i t1.nii.gz -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 spinalcord -i t1_smooth.nii.gz -qc ~/qc_singleSubj - - - -t1 -t1_seg -t1_smooth -Let’s try sct_smooth_spinalcord in this T1-weighted scan. Here we notice that after smoothing, the apparent noise is reduced, while the cord edges are preserved, allowing a more reliable segmentation on a second pass. - - - Align the cord in the R-L plane -149 -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 -Because some subjects (esp. those with scoliosis) might not be perfectly aligned in the medial plane, it can sometimes be difficult to view the spinal cord in a single 2D slice. The function sct_flatten_sagittal applies slice-wise deformation to align the cord in the medial plane. - -Important: This deformation does not preserve the internal structure of the cord, and is only advised for visual purpose. If you would like to properly align the cord along the RL and AP direction we recommend you use sct_straighten_spinalcord instead. - - Operations on images -150 -sct_maths -sct_maths - -add Add following input (can be number or image(s)) - -sub Subtract following input (can be number of image(s)) - -mul Multiply following input (can be number or image(s)) - -div 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 Binarize image using specified threshold. E.g. -bin 0.5 - -otsu Threshold image using Otsu algorithm. - -percent Threshold image using percentile of its histogram. - -thr Use following number to threshold image (zero below number). - -dilate Dilate binary image using specified ball radius. - -erode Erode binary image using specified ball radius. - -smooth Gaussian smoothing filter with specified standard deviations in - -laplacian Laplacian filtering with specified standard deviations in mm - -denoise Non-local means adaptive denoising from P. Coupe et al. - -mi Compute the mutual information (MI) between two images - -symmetrize {0,1,2} Symmetrize data along the specified dimension. - And more...! -The sct_maths script (fslmaths’ little sister) contains useful functions to apply operations on the image data, such as basic arithmetic operations, thresholding, mathematical morphology and filtering. For more information, type sct_maths -h - - Manipulate images -151 -sct_image -sct_image -IMAGE OPERATIONS: - -pad Pad 3d image. Specify padding as: "x,y,z" (in voxel) - -pad-asym 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 Remove specific volumes from a 4d volume. Separate with "," - -keep-vol 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 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...! - -The sct_image script contains useful functions to manipulate images, such as padding, splitting, keeping/removing volumes on 4d data, re-orienting, etc. For more information type sct_image -h - - Image stitching -Lavdas, Glocker et al. Clin. Radiol. 2019 -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) -Speaking of sct_image, we would like to highlight one very important new option of sct_image called -stitch. - -This method allows you to stitch multiple images acquired in the same orientation, utilizing the algorithm by Lavdas, Glocker et al. - - Other features? -To see all available functions, type “sct_” then TAB -153 - - - 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: -154 -source ${SCT_DIR}/python/etc/profile.d/conda.sh -conda activate venv_sct - - - Analysis pipelines with SCT -155 -Day Two - - Gray matter segmentation -Atlas-based analysis -Diffusion-weighted MRI -Functional MRI -Other features -Analysis pipelines with SCT -New and upcoming features -Conclusion -Day One - -Introduction -Installation -Segmentation -Vertebral labeling -Shape-based analysis -Registration to template -Register additional contrasts - - - 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 -156 -sct_run_batch -Batch scripts are extremely useful in the long term: they make it possible to re-run entire processing and re-generate results if needed (e.g., if after 6-month of a manuscript submission the reviewer asks you to change one parameter in the processing). - -Batch scripts are also excellent in establishing standardized processing, automatizing over large databases and to promote reproducibility of scientific results (e.g., you can publish your article along with the batch processing scripts). - - - Data organization -All participant data are organized into a directory and follow certain conventions, such as the BIDS (https://bids.neuroimaging.io/) data structure: -157 -sct_run_batch -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 -In order for the script to be applied to the entire dataset, you need to follow some conventions in terms of folder and file names. As some of you might know, there is a convention that was created by the brain imaging community called Brain Imaging Data Structure (BIDS). This convention makes it easier to share data, and also to develop and use Applications that are BIDS-compliant (such as SCT). - -Hands-on - - - Processing multiple subjects -Here we use a wrapper, called sct_run_batch, which loops across subjects and launch a batch script. -159 -sct_run_batch -# 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 -If each subject’s data is organized into individual folder, following the same file structure across subjects, it is convenient to create a “loop across all subjects” inside the batch script. When doing so, it is possible to distribute each subject into a single CPU core, allowing to process subjects in parallel. The gain in time can be 4x, 8x or even more, depending on the number of cores and RAM available. - -In this course, we will run a processing pipeline across 3 subjects. Before running this pipeline, let's look at the data structure with tree, as well as the processing script process_data.sh. - -Now, we are ready to launch the processing with the command sct_run_batch. While the processing runs, let's look at the generated outputs (log files, qc, data_processed) - -CSA.csv -Filename -Slice (I->S) -VertLevel -MEAN(area) -STD(area) -sub-01_T2w_seg.nii.gz -160:200 -2:3 -82.9358 -1.9414 -sub-03_T2w_seg.nii.gz -160:200 -2:3 -61.0923 -2.4872 -sub-05_T2w_seg.nii.gz -158:197 -2:3 -69.5586 -2.4585 - multi_subject: CSA -160 -sct_run_batch -Each line represents a subject -CSA results -After running the entire pipeline, you should have all results under the results/ folder. Here for example, we show the mean CSA averaged between C2-C3 levels computed from the T2 data. Each line represents a subject. - -The variability is mainly due to the inherent variability of CSA across subjects. For more details see: https://www.biorxiv.org/content/10.1101/2021.09.30.462636v1.full - -MTR_in_DC.csv -Filename -Slice (I->S) -VertLevel -Label -Size [vox] -MAP() -STD() -sub-01/anat/mtr.nii.gz -4:16 -2:5 -dorsal columns -325.3513 -49.4858 -4.5253 -sub-03/anat/mtr.nii.gz -4:16 -2:5 -dorsal columns -278.6569 -48.9083 -5.6684 -sub-05/anat/mtr.nii.gz -3:16 -2:5 -dorsal columns -302.1767 -49.1237 -4.6411 - multi_subject: MTR in WM -161 -sct_run_batch -MTR in dorsal column -Here are the results of MTR quantification in the dorsal column of each subject between C2 and C5. Notice the remarkable inter-subject consistency. - - Checking QC report -162 -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 'Save Fails' to generate a qc_fail.yml file. -We have provided a sample output for you in the multi_subject folder. -A QC report is generated under qc/. As shown before, the QC report is useful to quickly assess the quality of the analysis pipeline. - -Once you're done QCing the segmentation results, click on 'Download QC Fails' to download the file qc_fail.yml. This file includes the path to all the segmentations that require manual edition. We will see how we can conveniently use that file for batch manual correction. - - 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. -163 -# 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. -We provide a script called manual_correction.py. This script will read the qc_fail.yml file and will loop across the segmentations that require manual correction. When you have hundreds of subjects to process, this function can be very convenient! - -For convenience, we will use SCT's Python environment to run this script. Before doing so, we need to make sure that an image viewer is installed and callable via the Terminal command line. In this course we use FSLeyes, but you can use another viewer (eg: ITKsnap, 3D Slicer). We also need to make sure it can be opened from within another virtual environment. - - Manual corrections -Once your setup is ready, you can run the manual correction script. - -164 -# 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 - -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. -After you run the script, it will check that all dependent software are installed, and then ask you for your name (for the output JSON files). - -Then, the first segmentation to correct will open in FSLeyes. In FSLeyes, click on 'Edit mode' (Alt + E), correct the segmentation, then save it with the same name (overwrite). Then, the next segmentation to correct will pop up, and so on and so forth. - -After the script ends, you will be able to re-run the analysis. - - 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. -165 -sct_run_batch -script process_data.sh -path-data data/ -path-output output_correction -jobs 3 -Re-run the analysis. This time, if the manual correction file exists, it will be used in lieu of doing the automatic segmentation. - -While the script is running, look for the log file of the subjects where manual correction was done, to verify that the manual correction is used. - - Provenance of script/data -166 -Looking at the main sct_run_batch_log.txt log file, you notice '?!?' next to git commit and git origin for the 'SCRIPT' and 'DATA' sections. If you were using a script or data from a git repository, the provenance information would be added here. This is an excellent way to ensure reproducibility of the analysis. - -See for example the log file for the spine-generic project. - -This is also useful when checking how SCT results evolve across versions, and how it is checked for. Go to GitHub release page, and see the results across versions, on each platform. - - Log files if error -167 -Log files are useful to spot errors in some participant data (e.g., file missing, wrong file name) -Log files are generated under the log/ folder. These contain the output of the entire processing for each subject. - -Moreover, at the bottom of the file process_data.sh, the script checks if certain files have been generated— usually this concerns important output files used for quantitative results (e.g., T2 segmentation). If for some reasons (e.g., bug, crash, input file missing) an output file is missing, the prefix 'err.' will be added to the log file. - - New and upcoming features -168 -Day Two - - Gray matter segmentation -Atlas-based analysis -Diffusion-weighted MRI -Functional MRI -Other features -Analysis pipelines with SCT -New and upcoming features -Conclusion -Day One - -Introduction -Installation -Segmentation -Vertebral labeling -Shape-based analysis -Registration to template -Register additional contrasts - -New features - -List of models: https://spinalcordtoolbox.com/stable/user_section/command-line/sct_deepseg.html -# Presented by PL - -sct_deepseg lesion_ms -Benveniste et al. ESMRMB 2025 https://github.com/ivadomed/ms-lesion-agnostic - Lesion Segmentation in Multiple Sclerosis -Deep Learning model trained on ~4,000 manually segmented scans -Robust to multiple contrasts, image orientation, resolution, MRI vendor and field strength -NEW -in v7.2 -171 -# Presented by PL -Recently, a new model was added to SCT. It allows to segment Multiple Sclerosis lesions on multiple contrasts. It was trained on around 4000 images accounting for a broad range of acquisition parameters such as contrasts, orientation, resolution, vendor … -The below GIF displays the segmentation predicted by the model (in red) overlapping the original MRI image. -This method is available as a task in sct_deepseg. - -sct_deepseg lesion_ms -Benveniste et al. ESMRMB 2025 https://github.com/ivadomed/ms-lesion-agnostic - Lesion Segmentation in Multiple Sclerosis -NEW -in v7.2 -172 -cd ../single_subject/data/t2_ms -# Segment the spinal cord which will be used for generating the QC -sct_deepseg spinalcord -i t2.nii.gz -qc ~/qc_singleSubj -# Segment MS lesions with one fold (faster inference) -sct_deepseg lesion_ms -i t2.nii.gz -qc ~/qc_singleSubj -qc-seg t2_seg.nii.gz -single-fold -# The output is `t2_lesion_seg.nii.gz` (the MS lesion segmentation) -fsleyes t2.nii.gz -cm greyscale t2_lesion_seg.nii.gz -cm red -a 70.0 & -# For a more robust (but longer) inference: remove -single-fold -# For a soft segmentation: add -soft-ms-lesion -lesions -Input -Binary segmentation -Soft segmentation -1 -0 -# Presented by PL -Here, we will apply the MS lesion segmentation model on a T2 axial scan of a person with MS. -The model is called using the sct_deepseg function. -The model outputs two nifti files: spinal cord segmentation and lesion segmentation - -List of models: https://spinalcordtoolbox.com/stable/user_section/command-line/sct_deepseg.html -New lesion segmentation tools - -174 -SCIseg: Deep learning-based segmentation of the spinal cord and intramedullary lesions in spinal cord injury (SCI) on T2w images -Works on different FOV, resolution (isotropic, axial, sagittal) -Works across different SCI etiologies (traumatic SCI, ischemic SCI, and degenerative cervical myelopathy) and phases (acute, sub-acute, and chronic) -Naga Karthik, Valošek et al. MICCAI AMAI 2024 -Naga Karthik, Valošek et al. Radiology: AI 2025 - Lesion Segmentation in Spinal Cord Injury -T2w Image -Lesion and Spinal Cord -Segmentation -Lesion -Spinal Cord -174 -# Presented by Jan/Julien -SCIseg is a deep learning model for segmentation of spinal cord injury (SCI) T2w images. -It initially segments the spinal cord followed by a intramedullary lesion segmentation in the subsequent step (nnUNet region-based approach). -The model was developed on multiple SCI datasets with heterogeneous image orientations, resolutions, and FOVs. -It generalizes to different phases of traumatic SCI and also to lesions in degenerative cervical myelopathy, which is a type of non-traumatic SCI characterized by chronic degenerative spinal cord compression - - Lesion Segmentation in Spinal Cord Injury -175 -sct_deepseg lesion_sci_t2 -t2 -t2_sc_seg.nii.gz and t2_lesion_seg.nii.gz -cd ../single_subject/data/t2_lesion -# Segment the spinal cord and intramedullary lesion using the SCIsegV2 model -# Note: t2.nii.gz contains a fake lesion for the purpose of this tutorial -sct_deepseg lesion_sci_t2 -i t2.nii.gz -qc ~/qc_singleSubj -# Two files are output: -# 1) t2_sc_seg.nii.gz: the spinal cord segmentation -# 2) t2_lesion_seg.nii.gz: the lesion segmentation -fsleyes t2.nii.gz -cm greyscale t2_sc_seg.nii.gz -cm red -a 70.0 t2_lesion_seg.nii.gz -cm blue-lightblue -a 70.0 & - -lesion -Lesion -Spinal Cord -Naga Karthik, Valošek et al. MICCAI AMAI 2024 -Naga Karthik, Valošek et al. Radiology: AI 2025 -# Presented by Jan/Julien -Here, we will apply the SCIseg model to a subject with fake lesion (because of the difficulty to share patient data). -The model is called using the sct_deepseg function. -The model outputs two nifti files: spinal cord segmentation and lesion segmentation - -Improved lesion volumetric analysis - - Lesion analysis -sct_analyze_lesion -Lesion and spinal cord segmentation can be used to compute various morphometric measures, such as number of lesions, lesion length, lesion volume, tissue bridges etc. -T2w image -Lesion -Spinal Cord -Segmentation -Lesion Analysis -177 -Naga Karthik, Valošek et al. MICCAI AMAI 2024 -Naga Karthik, Valošek et al. Radiology: AI 2025 Valošek J,, Pfyffer D et al. ISMRM 2025 Pfyffer D et al. Lancet Neurol 2024 -# Presented by Jan/Julien -Lesion and spinal cord segmentation masks can be used to calculate various morphometric measures such as number of lesions, lesion length, lesion volume, tissue bridges, etc. -The figure below shows examples of two such morphometric measures: lesion length and ventral and dorsal tissue bridges. - -# Compute various morphometric measures (number of lesions, volume, length, etc.) -sct_analyze_lesion -m t2_lesion_seg.nii.gz -s t2_sc_seg.nii.gz -qc ~/qc_singleSubj - -sct_analyze_lesion - Lesion analysis -t2_sc_seg.nii.gz -t2_lesion_seg.nii.gz -XLSX file: -QC report showing tissue bridges: -NEW -in v6.4 -178 -# Presented by Jan/Julien -Morphometric measures can be computed using the sct_analyze_lesion function. -This function requires two inputs: lesion segmentation and spinal cord segmentation -The function automatically computes several morphometric measures and saves them into an XLSX file. Moreover, the function generates an HTML QC report for tissue bridges. - - Atlas-based lesion analysis -sct_analyze_lesion -f -The sct_analyze_lesion -f flag allows you to provide a folder containing an template/atlas registered to an anatomical image. If specified, the function computes: -The proportion of lesion within each vertebral level and each region of the template/atlas (e.g. GM, WM, WM tracts) - - -# Warp the white matter atlas (if not warped before) -sct_warp_template -d t2.nii.gz -w ../t2/warp_template2anat.nii.gz -# The -f flag is used to specify the folder containing the atlas/template -sct_analyze_lesion -m t2_lesion_seg.nii.gz -s t2_sc_seg.nii.gz -f label -qc ~/qc_singleSubj - -179 -# Presented by Jan/Julien -Additionally, the sct_analyze_lesion function allows you to provide a folder containing an atlas/template registered to an anatomical image. -If specified, sct_analyze_lesion computes the proportion of lesion within each vertebral level and each region of the template/atlas (e.g. GM, WM, WM tracts). - -Gradient echo EPI cord segmentation - -sct_deepseg sc_epi -cd ../fmri/ -# Segment the spinal cord on gradient echo EPI data -sct_deepseg sc_epi -i fmri_moco_mean.nii.gz -qc ~/qc_singleSubj - EPISeg: GRE-EPI cord segmentation -181 -Banerjee et al. Imaging Neurosci 2025 -NEW -in v6.5 -Data training/testing: - -Gray matter segmentation - -183 -Deep learning based contrast and region agnostic segmentation model - Gray matter segmentation -NEW -in v7.1 -sct_deepseg graymatter -Laines-Medina et al. ESMRMB (2025) -https://github.com/ivadomed/model-gm-contrast-region-agnostic -Training Data: 1367 participants from 16 sites -3 field strengths -12 contrasts -9 pathologies/categories -Regions: -Cervical -Thoraco-lumbar -Acquisition types: -2D: Multi-angle -3D: Slabs / runs -# Presented by Nilser - - -Spinal canal segmentation - -sct_deepseg sc_canal_t2 - Spinal canal segmentation -Deep learning based segmentation of the spinal canal on T2w images -Robust to various FOVs, orientations, resolutions and pathologies -Robust to various orientations -Axial planes on healthy, SCI and DCM subjects -Robust to various regions of the spine -NEW -in v6.5 -185 -Salmona et al. In preparation -https://github.com/ivadomed/model-canal-seg - - Spinal canal segmentation -NEW -in v6.5 -cd ../t2 -# Segment the spinal canal -sct_deepseg sc_canal_t2 -i t2.nii.gz -qc ~/qc_singleSubj -# Check results using FSLeyes -fsleyes t2.nii.gz -cm greyscale t2_canal_seg.nii.gz -cm red -a 70.0 & -sct_deepseg sc_canal_t2 - -186 - - - - -Spinal cord to canal ratio -sct_compute_ascor -sct_compute_ascor -i-SC t2_seg.nii.gz -i-canal t2_canal_seg.nii.gz -perlevel -1 -o ascor.csv -NEW -in v7.2 -Adapted Spinal Cord Occupation Ratio -aSCOR(%) -Healthy controls -Patient -187 -# Presented by Sandrine -"Spinal cord parenchymal fraction (SCPF)", spinal cord reserve - -Full spine segmentation - -https://zenodo.org/records/13894354 - Spine segmentation -Deep learning based segmentation and identification of multiple spinal structures using TotalSpineSeg: Vertebrae, Intervertebral discs, Spinal cord and Spinal canal -NEW -in v6.5 -189 -# Presented by Nathan - - Spine segmentation -# Segment using totalspineseg -sct_deepseg totalspineseg -i t2.nii.gz -qc ~/qc_singleSubj -# Check results using FSLeyes -fsleyes t2.nii.gz -cm greyscale t2_step1_canal.nii.gz -cm YlOrRd -a 70.0 t2_step1_cord.nii.gz -cm YlOrRd -a 70.0 t2_step1_levels.nii.gz -cm subcortical -a 70.0 t2_step1_output.nii.gz -cm subcortical -a 70.0 t2_step2_output.nii.gz -cm subcortical -a 70.0 & -sct_deepseg -NEW -in v6.5 -190 -https://zenodo.org/records/13894354 -# Presented by Nathan - -https://github.com/ivadomed/SpineReports - Generating reports -Extracting spine morphometrics to generate personalized reports of the different structure segmented by totalspineseg is now possible using SpineReports -191 -# Presented by Nathan - -Spinal nerve rootlets segmentation - -193 -RootletSeg: Deep learning-based segmentation of nerve rootlets -Nerve rootlets can be used to estimate spinal levels -T2-w image -Nerve rootlets -Valošek et al. Imaging Neuroscience 2024 -Krejci et al. arXiv 2025 - Spinal nerve rootlets segmentation -NEW -in v7.0 -Fig ref: Cadotte et al., AJNR, 2015 -sct_deepseg rootlets -# Presented by Jan/Julien -Recently, the rootlets segmentation model (RootletSeg) was updated to segment both dorsal and ventral spinal nerve rootlets from T2-weighted and MP2RAGE images (including T1w). -The model provides level-specific (so-called multi-class) segmentation of the C2-Th1 dorsal and ventral spinal nerve rootlets. -Nerve rootlets can be used to obtain different spinal levels (e.g., C2, C3, C4, etc.). -These spinal levels can be used as an alternative to vertebral levels for the registration to the template to perform group-level analysis. - - - Spinal nerve rootlets segmentation -NEW -in v7.0 -# Segment the spinal nerve rootlets -sct_deepseg rootlets -i t2.nii.gz -qc ~/qc_singleSubj -# Check results using FSLeyes -fsleyes t2.nii.gz -cm greyscale t2_rootlets.nii.gz -cm subcortical -a 70.0 & -sct_deepseg rootlets -194 -Valošek et al. Imaging Neuroscience 2024 -Krejci et al. arXiv 2025 -# Presented by Jan/Julien -The rootlets segmentation model is available via the sct_deepseg function. -The model requires a single input: T2w or MP2RAGE image -It outputs level-specific segmentation of the dorsal spinal nerve rootlets - -Bédard et al. Imaging Neuroscience 2025 -sct_register_to_template -lrootlet - Rootlets-based Registration -Use automatic rootlets segmentation for registration to PAM50 template -Available in sct_register_to_template -lrootlet -195 -NEW -in v7.0 -# Presented by Sandrine -Typically, for template registration, we use the vertebrae to align the subjects. However, the vertebral levels do not correspond exactly to the spinal levels, which is limiting for fMRI group analysis that require a good alignment across subject - -The aim here is to use the automatic rootlets segmentation that Jan presented to improve the template registration. -Briefly, we first align the center of the rootlets segmentation with the PAM50 rootelts instead of the interverterbral discs. Then we continue with the same XY alignment of the spinal cord. - -sct_register_to_template -lrootlet - Rootlets-based Registration -Improves alignment across subjects -Potential to improve fMRI group maps -196 -Collaboration: Ken Weber (Stanford) -Bédard et al. Imaging Neuroscience 2025 -Activation maps (N=40) -# Presented by Sandrine -Some preliminary results. we show the an average of the ventral rootlets of the PAM50, of 233 subjects registered using the rootlets and of 233 subjects registered using the discs. - -We see that the shape of the rootlets is much better defined when using rootlets-based registration. -This has the potential to improve spatial normalization for fMRI analysis - -Upcoming features - - Spinal cord morphometry -Context: Analysis of SC morphometry based on segmentation -Using scikit-image ellipse fitting to compute AP and RL diameter is (sometimes) wrong -Problem: Over-estimated AP diameter in U-Shape cords -AP diameter (mm) -Upcoming features -198 -overestimation -# Presented by Sandrine - - - Spinal cord morphometry -New algorithm to compute AP diameter & asymmetry of the cord -Ongoing study (🇨🇭Zurich, 🇨🇦 Calgary, 🇨🇦 Toronto, 🇨🇦 Vancouver, 🇨🇿 Brno, 🇨🇿 Olomouc) -Would you like to participate? Email Julien! -Upcoming features -# Presented by Sandrine - - - Spinal cord asymmetry -sct_process_segmentation -symmetry -Healthy controls -Patient -Upcoming features -Legend red: original segmentation -blue: flipped hemi-cord yellow line: Hausdorff distance -# Presented by Sandrine - - - Update on PAM50 template -Fix mis-registration of WM/GM atlas in lumbar levels -Extend T2*w template towards lumbar cord -Add label for lumbo-sacral enlargement -WIP: Re-generate AMU & Zurich T2*w template and WM/GM atlas -Collaboration: Jan Valosek (Montreal/Zurich), Virginie Callot (AMU), Christian Kündig, Silvan Büeler, Gergely David (Zurich), Raphaelle Schlienger (AMU) -Upcoming features -AMU15 -Zurich42 -# Presented by Julien - - - Lumbar pathology diagnosis -Kaggle/RSNA challenge -Automatic diagnosis of neural foraminal narrowing (NFN), spinal canal stenosis (SCS), and subarticular stenosis (SAS -MRI -Segmentation -Attention map -TotalSpineSeg(*) -SpineDiagnosis(**) -Clinical report -Diagnosis: Foraminal stenosis at L4/L5 -Justification: compression of foramen at levels L4/L5 -# Presented by Thomas - - - Deep learning motion correction -Upcoming features -raw -moco(*) -mocoDL -dMRI -fMRI -(*)sct_dmri_moco -g 1 -param poly=0 -x nn -(*)sct_fmri_moco -g 1 -param poly=0 -x nn -P -A -S -I -R -L -S -I -R -L -A -P -# Presented by Julien - - -Poll Results - - Poll Results - - Conclusion -206 -Day Two - - Gray matter segmentation -Atlas-based analysis -Diffusion-weighted MRI -Functional MRI -Other features -Analysis pipelines with SCT -New and upcoming features -Conclusion -Day One - -Introduction -Installation -Segmentation -Vertebral labeling -Shape-based analysis -Registration to template -Register additional contrasts -We have reached the end of the course. We just have a few closing suggestions for you. - - Need help? -207 -Type command without argument, or with flag “-h”. - - Need help? -208 -http://forum.spinalcordmri.org/c/sct -Post any issue you are having on the sourceforge website. - -In order to help you efficiently, please be specific in the title (e.g., indicate output error) and also indicate the version you are running (e.g., v3.2.1). - -We welcome any suggestion for improvement / new feature requests! - - 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) -Online’23 -Online’24 - - Zoom pic 📸 - - Contribute to SCT -SCT is an open-source project -Contributions are welcome! 🎉 -Please see our contribution guidelines: https://github.com/spinalcordtoolbox/spinalcordtoolbox/wiki/Contributing -211 -Contributions can take the form of opening an issue, suggesting a feature, fixing a bug, implementing a feature, or even becoming a sponsor! - - Acknowledgements -Current: Julien Cohen-Adad, Joshua Newton, Mathieu Guay-Paquet, Jan Valosek, Naga Karthik, Nilser Laines Medina, Pierre-Louis Benveniste, Nathan Molinier, Sandrine Bédard, Rohan Banerjee, Maxime Bouthillier, Samuelle St-Onge, Thomas Dagonneau, Kalum Ost, Paul Hoareau. -Alumni: Abel Salmona, Ainsleigh Hill, Alexandru Foias, Alexandru Jora, Andreanne Lemay, Benjamin De Leener, Charley Gros, Christian Perone, Clara Giroux, George Peristerakis, Hee-Min Yang, Jérôme Carretero, Kateřina Krejci, Lucas Rouhier, Nicolas Pinon, Paul Bautin, P-O Quirion, Sara Dupont, Simon Lévy, Tanguy Duval, Thiago Rezende, Yehuda Warszawer -Core SCT developers -… and we thank all the collaborators and SCT users for their precious feedback!! ❤️ -Sponsors -Grants: \ No newline at end of file From bfe9286949d0477fccfe75b31c90c7236605c097 Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Wed, 19 Nov 2025 11:38:46 -0500 Subject: [PATCH 12/22] Revert "Temporarily turn off PR trigger on workflows" This reverts commit 5ca1c2a46a4e451d9c8056c573a0f7c419b138b2. --- .github/workflows/run_batch_script.yml | 4 ++-- .github/workflows/run_script_and_create_release.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run_batch_script.yml b/.github/workflows/run_batch_script.yml index dd4d7b0..5182ac3 100644 --- a/.github/workflows/run_batch_script.yml +++ b/.github/workflows/run_batch_script.yml @@ -15,8 +15,8 @@ name: "Run sct_run_batch -s process_data.sh" # - 'sct_course_data.zip': Files required to run the SCT course from start to finish. # - 'registration.zip', 'segmentation.zip', etc.: Files required by individual tutorials. -#on: -# pull_request: +on: + pull_request: jobs: run-course-script: diff --git a/.github/workflows/run_script_and_create_release.yml b/.github/workflows/run_script_and_create_release.yml index 760f21a..2851ad2 100644 --- a/.github/workflows/run_script_and_create_release.yml +++ b/.github/workflows/run_script_and_create_release.yml @@ -19,7 +19,7 @@ on: push: branches: - master -# pull_request: + pull_request: workflow_dispatch: inputs: release_title: From c98f50b8f8cbd2c230cbee37756e6f54d0917b96 Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Wed, 19 Nov 2025 11:51:17 -0500 Subject: [PATCH 13/22] Fix `-step1-only` syntax --- single_subject/batch_single_subject.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/single_subject/batch_single_subject.sh b/single_subject/batch_single_subject.sh index 5780d85..63c3a68 100755 --- a/single_subject/batch_single_subject.sh +++ b/single_subject/batch_single_subject.sh @@ -64,7 +64,7 @@ sct_deepseg -h # ====================================================================================================================== # Vertebral disc labeling -sct_deepseg totalspineseg -step1-only -i t2.nii.gz -qc ~/qc_singleSubj +sct_deepseg totalspineseg -step1-only 1 -i t2.nii.gz -qc ~/qc_singleSubj # Full spinal segmentation (Vertebrae, Intervertebral discs, Spinal cord and Spinal canal) # Segment using totalspineseg From 881261733fd58454aad28ade04b8efa679949499 Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Wed, 19 Nov 2025 12:53:13 -0500 Subject: [PATCH 14/22] `gmseg` -> `gm_seg` to match new `graymatter` output --- single_subject/batch_single_subject.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/single_subject/batch_single_subject.sh b/single_subject/batch_single_subject.sh index 63c3a68..4a0e871 100755 --- a/single_subject/batch_single_subject.sh +++ b/single_subject/batch_single_subject.sh @@ -253,7 +253,7 @@ sct_deepseg spinalcord -i t2s.nii.gz -qc ~/qc_singleSubj # Note that we use the flag -thr 0 in case some voxels in the GM segmentation are *not* included in the cord # segmentation. That would results in voxels in the WM segmentation having the value “-1”, which would cause issues # with the registration. -sct_maths -i t2s_seg.nii.gz -sub t2s_gmseg.nii.gz -thr 0 -o t2s_wmseg.nii.gz +sct_maths -i t2s_seg.nii.gz -sub t2s_gm_seg.nii.gz -thr 0 -o t2s_wm_seg.nii.gz @@ -263,15 +263,15 @@ sct_maths -i t2s_seg.nii.gz -sub t2s_gmseg.nii.gz -thr 0 -o t2s_wmseg.nii.gz # 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_wmseg.nii.gz -o csa_wm.csv -perslice 1 -angle-corr 0 -sct_process_segmentation -i t2s_gmseg.nii.gz -o csa_gm.csv -perslice 1 -angle-corr 0 +sct_process_segmentation -i t2s_wm_seg.nii.gz -o csa_wm.csv -perslice 1 -angle-corr 0 +sct_process_segmentation -i t2s_gm_seg.nii.gz -o csa_gm.csv -perslice 1 -angle-corr 0 # You can also use the binary masks to extract signal intensity from MRI data. # The example below will show how to use the GM and WM segmentations to quantify T2* signal intensity, 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 +sct_extract_metric -i t2s.nii.gz -f t2s_wm_seg.nii.gz -method bin -z 2:12 -o t2s_value.csv +sct_extract_metric -i t2s.nii.gz -f t2s_gm_seg.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. @@ -281,7 +281,7 @@ sct_extract_metric -i t2s.nii.gz -f t2s_gmseg.nii.gz -method bin -z 2:12 -o t2s_ # 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 +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_wm_seg.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 From cd149daa882bd00173ffbed484f3260450db1485 Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Wed, 19 Nov 2025 14:22:25 -0500 Subject: [PATCH 15/22] `batch_single_subject.sh`: Fix `aSCOR` typo (`-1` -> `1`) --- single_subject/batch_single_subject.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/single_subject/batch_single_subject.sh b/single_subject/batch_single_subject.sh index 4a0e871..90a45f0 100755 --- a/single_subject/batch_single_subject.sh +++ b/single_subject/batch_single_subject.sh @@ -438,7 +438,7 @@ fsleyes t2.nii.gz -cm greyscale t2_canal_seg_seg.nii.gz -cm red -a 70.0 & # Compute aSCOR (Adapted Spinal Cord Occupation Ratio) # i.e. Spinal cord to canal ratio using the canal seg -sct_compute_ascor -i-SC t2_seg.nii.gz -i-canal t2_canal_seg.nii.gz -perlevel -1 -o ascor.csv +sct_compute_ascor -i-SC t2_seg.nii.gz -i-canal t2_canal_seg.nii.gz -perlevel 1 -o ascor.csv # Segment the spinal nerve rootlets sct_deepseg rootlets -i t2.nii.gz -qc ~/qc_singleSubj From 60ebdebbe70660b6399e43134c3737bf52ea2418 Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Wed, 19 Nov 2025 16:55:22 -0500 Subject: [PATCH 16/22] `batch_single_subject.sh`: Revert back to `_gmseg` Keeping the old syntax will be better for ensuring backwards compatibility with the course data .zips, since we package up the _gmseg and _wmseg files to be used in other tutorials. --- single_subject/batch_single_subject.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/single_subject/batch_single_subject.sh b/single_subject/batch_single_subject.sh index 90a45f0..24ee0e5 100755 --- a/single_subject/batch_single_subject.sh +++ b/single_subject/batch_single_subject.sh @@ -246,14 +246,14 @@ sct_register_to_template -i t2_lumbar.nii.gz -s t2_lumbar_seg.nii.gz -ldisc t2_l # 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 graymatter -i t2s.nii.gz -qc ~/qc_singleSubj +sct_deepseg graymatter -i t2s.nii.gz -o t2s_gmseg.nii.gz -qc ~/qc_singleSubj # Spinal cord segmentation sct_deepseg spinalcord -i t2s.nii.gz -qc ~/qc_singleSubj # Subtract GM segmentation from cord segmentation to obtain WM segmentation # Note that we use the flag -thr 0 in case some voxels in the GM segmentation are *not* included in the cord # segmentation. That would results in voxels in the WM segmentation having the value “-1”, which would cause issues # with the registration. -sct_maths -i t2s_seg.nii.gz -sub t2s_gm_seg.nii.gz -thr 0 -o t2s_wm_seg.nii.gz +sct_maths -i t2s_seg.nii.gz -sub t2s_gmseg.nii.gz -thr 0 -o t2s_wmseg.nii.gz @@ -263,15 +263,15 @@ sct_maths -i t2s_seg.nii.gz -sub t2s_gm_seg.nii.gz -thr 0 -o t2s_wm_seg.nii.gz # 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_wm_seg.nii.gz -o csa_wm.csv -perslice 1 -angle-corr 0 -sct_process_segmentation -i t2s_gm_seg.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 +sct_process_segmentation -i t2s_gmseg.nii.gz -o csa_gm.csv -perslice 1 -angle-corr 0 # You can also use the binary masks to extract signal intensity from MRI data. # The example below will show how to use the GM and WM segmentations to quantify T2* signal intensity, 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_wm_seg.nii.gz -method bin -z 2:12 -o t2s_value.csv -sct_extract_metric -i t2s.nii.gz -f t2s_gm_seg.nii.gz -method bin -z 2:12 -o t2s_value.csv -append 1 +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. @@ -281,7 +281,7 @@ sct_extract_metric -i t2s.nii.gz -f t2s_gm_seg.nii.gz -method bin -z 2:12 -o t2s # 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_wm_seg.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 +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 From e51c8fb6fc6a09280817ef660f3a8ee0d407822e Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Thu, 20 Nov 2025 09:57:39 -0500 Subject: [PATCH 17/22] `batch_single_subject.sh`: Add cmd to generate `t2_seg_labeled.nii.gz` CSV generation will fail due to missing labeled seg file. --- single_subject/batch_single_subject.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/single_subject/batch_single_subject.sh b/single_subject/batch_single_subject.sh index 24ee0e5..53c5849 100755 --- a/single_subject/batch_single_subject.sh +++ b/single_subject/batch_single_subject.sh @@ -72,6 +72,11 @@ sct_deepseg totalspineseg -i t2.nii.gz -qc ~/qc_singleSubj # Check results using FSLeyes fsleyes t2.nii.gz -cm greyscale t2_step1_canal.nii.gz -cm YlOrRd -a 70.0 t2_step1_cord.nii.gz -cm YlOrRd -a 70.0 t2_step1_levels.nii.gz -cm subcortical -a 70.0 t2_step1_output.nii.gz -cm subcortical -a 70.0 t2_step2_output.nii.gz -cm subcortical -a 70.0 & # Check QC report: Go to your browser and do "refresh". + +# Optionally, you can use the generated disc labels to create a labeled segmentation +sct_label_utils -i t2_seg.nii.gz -project-centerline t2_step1_levels.nii.gz -o t2_seg_labeled.nii.gz + + # 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 # inter-vertebral disc level. The convention is: Value 3 —> C2-C3 disc, Value 4 —> C3-C4 disc, etc. From dc8264a0f14a29c3e78ee6070f81cfac48852012 Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Thu, 20 Nov 2025 10:02:28 -0500 Subject: [PATCH 18/22] `batch_single_subject.sh`: Remove sct_label_vertebrae comments Superseded by totalspineseg. --- single_subject/batch_single_subject.sh | 9 --------- 1 file changed, 9 deletions(-) diff --git a/single_subject/batch_single_subject.sh b/single_subject/batch_single_subject.sh index 53c5849..ce67068 100755 --- a/single_subject/batch_single_subject.sh +++ b/single_subject/batch_single_subject.sh @@ -77,15 +77,6 @@ fsleyes t2.nii.gz -cm greyscale t2_step1_canal.nii.gz -cm YlOrRd -a 70.0 t2_step sct_label_utils -i t2_seg.nii.gz -project-centerline t2_step1_levels.nii.gz -o t2_seg_labeled.nii.gz -# 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 -# inter-vertebral disc level. The convention is: Value 3 —> C2-C3 disc, Value 4 —> C3-C4 disc, etc. - -# OPTIONAL: 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 inter-vertebral disc" -#sct_label_vertebrae -i t2.nii.gz -s t2_seg.nii.gz -c t2 -initlabel label_c2c3.nii.gz -qc ~/qc_singleSubj - - # Shape-based analysis # ====================================================================================================================== From aa88fb2da4d2b41ae4f656f10f5b9a5aacabf8c9 Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Fri, 28 Nov 2025 13:16:02 -0500 Subject: [PATCH 19/22] `batch_single_subject.sh`: Update totalspineseg syntax/output fname --- single_subject/batch_single_subject.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/single_subject/batch_single_subject.sh b/single_subject/batch_single_subject.sh index ce67068..8a59e06 100755 --- a/single_subject/batch_single_subject.sh +++ b/single_subject/batch_single_subject.sh @@ -64,17 +64,17 @@ sct_deepseg -h # ====================================================================================================================== # Vertebral disc labeling -sct_deepseg totalspineseg -step1-only 1 -i t2.nii.gz -qc ~/qc_singleSubj +sct_deepseg spine -i t2.nii.gz -label-vert 1 -qc ~/qc_singleSubj # Full spinal segmentation (Vertebrae, Intervertebral discs, Spinal cord and Spinal canal) # Segment using totalspineseg -sct_deepseg totalspineseg -i t2.nii.gz -qc ~/qc_singleSubj +sct_deepseg spine -i t2.nii.gz -qc ~/qc_singleSubj # Check results using FSLeyes -fsleyes t2.nii.gz -cm greyscale t2_step1_canal.nii.gz -cm YlOrRd -a 70.0 t2_step1_cord.nii.gz -cm YlOrRd -a 70.0 t2_step1_levels.nii.gz -cm subcortical -a 70.0 t2_step1_output.nii.gz -cm subcortical -a 70.0 t2_step2_output.nii.gz -cm subcortical -a 70.0 & +fsleyes t2.nii.gz -cm greyscale t2_step1_canal.nii.gz -cm YlOrRd -a 70.0 t2_step1_cord.nii.gz -cm YlOrRd -a 70.0 t2_totalspineseg_discs.nii.gz -cm subcortical -a 70.0 t2_step1_output.nii.gz -cm subcortical -a 70.0 t2_step2_output.nii.gz -cm subcortical -a 70.0 & # Check QC report: Go to your browser and do "refresh". # Optionally, you can use the generated disc labels to create a labeled segmentation -sct_label_utils -i t2_seg.nii.gz -project-centerline t2_step1_levels.nii.gz -o t2_seg_labeled.nii.gz +sct_label_utils -i t2_seg.nii.gz -project-centerline t2_totalspineseg_discs.nii.gz -o t2_seg_labeled.nii.gz @@ -82,11 +82,11 @@ sct_label_utils -i t2_seg.nii.gz -project-centerline t2_step1_levels.nii.gz -o t # ====================================================================================================================== # 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 -discfile t2_step1_levels.nii.gz -o csa_c3c4.csv +sct_process_segmentation -i t2_seg.nii.gz -vert 3:4 -discfile t2_totalspineseg_discs.nii.gz -o csa_c3c4.csv # Aggregate CSA value per level -sct_process_segmentation -i t2_seg.nii.gz -vert 3:4 -discfile t2_step1_levels.nii.gz -perlevel 1 -o csa_perlevel.csv +sct_process_segmentation -i t2_seg.nii.gz -vert 3:4 -discfile t2_totalspineseg_discs.nii.gz -perlevel 1 -o csa_perlevel.csv # Aggregate CSA value per slices -sct_process_segmentation -i t2_seg.nii.gz -z 30:35 -discfile t2_step1_levels.nii.gz -perslice 1 -o csa_perslice.csv +sct_process_segmentation -i t2_seg.nii.gz -z 30:35 -discfile t2_totalspineseg_discs.nii.gz -perslice 1 -o csa_perslice.csv # A drawback of vertebral level-based CSA is that it doesn’t consider neck flexion and extension. # To overcome this limitation, the CSA can instead be computed using the distance to a reference point. @@ -98,7 +98,7 @@ sct_process_segmentation -i t2_seg.nii.gz -pmj t2_pmj.nii.gz -pmj-distance 64 -p # The above commands will output the metrics in the subject space (with the original image's slice numbers) # However, you can get the corresponding slice number in the PAM50 space by using the flag `-normalize-PAM50 1` -sct_process_segmentation -i t2_seg.nii.gz -discfile t2_step1_levels.nii.gz -perslice 1 -normalize-PAM50 1 -o csa_PAM50.csv +sct_process_segmentation -i t2_seg.nii.gz -discfile t2_totalspineseg_discs.nii.gz -perslice 1 -normalize-PAM50 1 -o csa_PAM50.csv @@ -129,7 +129,7 @@ sct_compute_compression -i t2_compressed_seg.nii.gz -vertfile t2_compressed_seg_ cd ../t2 # Create labels at C3 and T2 mid-vertebral levels. These labels are needed for template registration. -sct_label_utils -i t2_step1_levels.nii.gz -keep 3,9 -o t2_labels_vert.nii.gz +sct_label_utils -i t2_totalspineseg_discs.nii.gz -keep 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 @@ -146,7 +146,7 @@ sct_register_to_template -i t2.nii.gz -s t2_seg.nii.gz -ldisc t2_labels_vert.nii sct_register_to_template -i t2.nii.gz -s t2_seg.nii.gz -ldisc t2_labels_vert.nii.gz -qc ~/qc_singleSubj -ofolder advanced_param -c t2 -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 # Register t2->template with large FOV (e.g. C2-L1) using `-ldisc` option -# sct_register_to_template -i t2.nii.gz -s t2_seg.nii.gz -ldisc t2_step1_levels.nii.gz -c t2 +# sct_register_to_template -i t2.nii.gz -s t2_seg.nii.gz -ldisc t2_totalspineseg_discs.nii.gz -c t2 # Register t2->template in compressed cord (example command) # In case of highly compressed cord, the algo columnwise can be used, which allows for more deformation than bsplinesyn. From 8719e48a9dcfca4dc0c31dd617f5b612f20cbb97 Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Fri, 28 Nov 2025 13:54:29 -0500 Subject: [PATCH 20/22] `batch_single_subject.sh`: Update tutorial-specific command --- single_subject/batch_single_subject.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/single_subject/batch_single_subject.sh b/single_subject/batch_single_subject.sh index 8a59e06..dd42715 100755 --- a/single_subject/batch_single_subject.sh +++ b/single_subject/batch_single_subject.sh @@ -74,7 +74,9 @@ fsleyes t2.nii.gz -cm greyscale t2_step1_canal.nii.gz -cm YlOrRd -a 70.0 t2_step # Check QC report: Go to your browser and do "refresh". # Optionally, you can use the generated disc labels to create a labeled segmentation -sct_label_utils -i t2_seg.nii.gz -project-centerline t2_totalspineseg_discs.nii.gz -o t2_seg_labeled.nii.gz +# Note: This approach is no longer recommended. Instead, use the disc labels directly in subsequent commands (e.g. `sct_process_segmentation`). +sct_label_vertebrae -i t2.nii.gz -s t2_seg.nii.gz -c t2 -discfile t2_totalspineseg_discs.nii.gz +# FIXME: Remove this command once the web tutorials are updated to no longer use labeled segmentations From fd6d63dbb37c27165126decabbe9173966be1187 Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Mon, 1 Dec 2025 19:20:33 -0500 Subject: [PATCH 21/22] `batch_single_subject.sh`: Add cropping step to improve `sc_epi` --- single_subject/batch_single_subject.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/single_subject/batch_single_subject.sh b/single_subject/batch_single_subject.sh index dd42715..b0ed0bc 100755 --- a/single_subject/batch_single_subject.sh +++ b/single_subject/batch_single_subject.sh @@ -426,7 +426,10 @@ sct_analyze_lesion -m t2_lesion_seg.nii.gz -s t2_sc_seg.nii.gz -f label -qc ~/qc # Segment the spinal cord on gradient echo EPI data cd ../fmri/ -sct_deepseg sc_epi -i fmri_moco_mean.nii.gz -qc ~/qc_singleSubj +# Crop extraneous tissue using the t2-based mask generated earlier +sct_crop_image -i fmri_moco_mean.nii.gz -m mask_fmri.nii.gz -b 0 +# Segment the cord using the cropped image +sct_deepseg sc_epi -i fmri_moco_mean_crop.nii.gz -qc ~/qc_singleSubj # Canal segmentation cd ../t2 From 93cddf5fefec12f7b92b55789c4d74a0c25ee09a Mon Sep 17 00:00:00 2001 From: Joshua Newton Date: Mon, 1 Dec 2025 14:38:15 -0500 Subject: [PATCH 22/22] `run_script_and_create_release.yml`: Upload QC artifact --- .github/workflows/run_script_and_create_release.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/run_script_and_create_release.yml b/.github/workflows/run_script_and_create_release.yml index 2851ad2..805c58e 100644 --- a/.github/workflows/run_script_and_create_release.yml +++ b/.github/workflows/run_script_and_create_release.yml @@ -60,6 +60,12 @@ jobs: cd "${{ github.event.repository.name }}/single_subject" ./batch_single_subject.sh + - name: "Upload QC report for easier output verification" + uses: actions/upload-artifact@v4 + with: + name: batch_single_subject QC (${{ runner.os }}) + path: "~/qc_singleSubj" + - name: "Upload CSV files for easier tutorial updating" uses: actions/upload-artifact@v4 with: