Skip to content

Commit 0b3c453

Browse files
Update dataset to address feedback from tutorial PR (#2)
* `batch_single_subject.sh`: No longer crop for sct_dmri_moco * `batch_single_subject.sh`: Add QC for `_moco` commands * `batch_single_subject.sh`: Switch order of flags for sct_deepseg_sc * `batch_single_subject.sh`: Move GM/WM seg metric computation into new tutorial * `batch_single_subject.sh`: Clarify section headers * `batch_single_subject.sh`: Synchronize SCT commands between tutorials/slide deck * `tutorial-datasets.csv`: Remove no-longer-necessary MT1 files * `batch_single_subject.sh`: Add note about reusing MT seg/mask
1 parent c29b496 commit 0b3c453

2 files changed

Lines changed: 64 additions & 50 deletions

File tree

single_subject/batch_single_subject.sh

Lines changed: 58 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ cd ../t1
4949
sct_propseg -i t1.nii.gz -c t1 -qc ~/qc_singleSubj
5050
# Check QC report: Go to your browser and do "refresh". Notice that the segmentation is "leaking".
5151
# Try another algorithm based on deep-learning
52-
sct_deepseg_sc -i t1.nii.gz -c t1 -qc ~/qc_singleSubj -ofolder deepseg
52+
sct_deepseg_sc -i t1.nii.gz -c t1 -ofolder deepseg -qc ~/qc_singleSubj
5353
# Check QC report: Go to your browser and do "refresh". Notice that the leakage is fixed.
5454
# Optional: Check results in FSLeyes. In red: PropSeg, in green: DeepSeg. Tips: use the right arrow key to switch
5555
# overlay on/off.
@@ -85,7 +85,7 @@ sct_label_utils -i t2_seg_labeled.nii.gz -vert-body 3,9 -o t2_labels_vert.nii.gz
8585

8686

8787

88-
# Registratering T2 data to the PAM50 template
88+
# Registering T2 data to the PAM50 template
8989
# ======================================================================================================================
9090

9191
# Register t2->template.
@@ -132,16 +132,26 @@ sct_create_mask -i mt1.nii.gz -p centerline,mt1_seg.nii.gz -size 35mm -f cylinde
132132

133133
# Register template->mt1. The flag -initwarp ../t2/warp_template2anat.nii.gz initializes the registration using the
134134
# template->t2 transformation which was previously estimated
135-
sct_register_multimodal -i $SCT_DIR/data/PAM50/template/PAM50_t2.nii.gz -iseg $SCT_DIR/data/PAM50/template/PAM50_cord.nii.gz \
136-
-d mt1.nii.gz -dseg mt1_seg.nii.gz \
137-
-m mask_mt1.nii.gz -initwarp ../t2/warp_template2anat.nii.gz \
135+
sct_register_multimodal -i $SCT_DIR/data/PAM50/template/PAM50_t2.nii.gz \
136+
-iseg $SCT_DIR/data/PAM50/template/PAM50_cord.nii.gz \
137+
-d mt1.nii.gz \
138+
-dseg mt1_seg.nii.gz \
139+
-m mask_mt1.nii.gz \
140+
-initwarp ../t2/warp_template2anat.nii.gz \
138141
-param step=1,type=seg,algo=centermass:step=2,type=seg,algo=bsplinesyn,slicewise=1,iter=3 \
139-
-owarp warp_template2mt.nii.gz -qc ~/qc_singleSubj
142+
-owarp warp_template2mt.nii.gz \
143+
-qc ~/qc_singleSubj
140144
# Tips: Here we only use the segmentations (type=seg) to minimize the sensitivity of the registration procedure to
141145
# image artifacts.
142146
# Tips: Step 1: algo=centermass to align source and destination segmentations, then Step 2: algo=bpslinesyn to adapt the
143147
# shape of the cord to the mt modality (in case there are distortions between the t2 and the mt scan).
144148

149+
# OPTIONAL: If you don't have a corresponding anatomical image to register first (in this case, the T2 warping field we're using for `-initwarp`), 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 with:
150+
# sct_label_utils -i mt1_seg.nii.gz -create-seg -1,4 -o label_c3c4.nii.gz
151+
# Then, you can register to the template.
152+
# 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.
153+
# 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
154+
145155
# Warp template
146156
sct_warp_template -d mt1.nii.gz -w warp_template2mt.nii.gz -a 1 -qc ~/qc_singleSubj
147157
# Check results using Fsleyes. Tips: use the right arrow key to switch overlay on/off.
@@ -156,6 +166,7 @@ fsleyes mt1.nii.gz -cm greyscale -a 100.0 \
156166
# ======================================================================================================================
157167

158168
# Register mt0->mt1 using z-regularized slicewise translations (algo=slicereg)
169+
# Note: Segmentation and mask can be re-used from "MT registration" section
159170
sct_register_multimodal -i mt0.nii.gz -d mt1.nii.gz -dseg mt1_seg.nii.gz -m mask_mt1.nii.gz \
160171
-param step=1,type=im,algo=slicereg,metric=CC -x spline -qc ~/qc_singleSubj
161172
# Check results using Fsleyes. Tips: use the right arrow key to switch overlay on/off.
@@ -166,7 +177,7 @@ sct_compute_mtr -mt0 mt0_reg.nii.gz -mt1 mt1.nii.gz
166177

167178

168179

169-
# Gray/white matter segmentation
180+
# Gray/white matter: Segmentation
170181
# ======================================================================================================================
171182

172183
# Go to T2*-weighted data, which has good GM/WM contrast and high in-plane resolution
@@ -180,7 +191,26 @@ sct_maths -i t2s_seg.nii.gz -sub t2s_gmseg.nii.gz -o t2s_wmseg.nii.gz
180191

181192

182193

183-
# Improving registration results using gray/white matter segmentations
194+
# Gray/white matter: Computing metrics using binary segmentation masks
195+
# ======================================================================================================================
196+
197+
# Compute cross-sectional area (CSA) of the gray and white matter for all slices in the volume.
198+
# Note: Here we use the flag -angle-corr 0, because we do not want to correct the computed CSA by the cosine of the
199+
# angle between the cord centerline and the S-I axis: we assume that slices were acquired orthogonally to the cord.
200+
sct_process_segmentation -i t2s_wmseg.nii.gz -o csa_wm.csv -perslice 1 -angle-corr 0
201+
sct_process_segmentation -i t2s_gmseg.nii.gz -o csa_gm.csv -perslice 1 -angle-corr 0
202+
203+
# You can also use the binary masks to extract signal intensity from MRI data.
204+
# The example below will show how to use the GM and WM segmentations to quantify T2* signal intensity, as done in
205+
# [Martin et al. PLoS One 2018].
206+
# Quantify average WM and GM signal between slices 2 and 12.
207+
sct_extract_metric -i t2s.nii.gz -f t2s_wmseg.nii.gz -method bin -z 2:12 -o t2s_value.csv
208+
sct_extract_metric -i t2s.nii.gz -f t2s_gmseg.nii.gz -method bin -z 2:12 -o t2s_value.csv -append 1
209+
# Note: the flag -append enables to append a new result at the end of an already-existing csv file.
210+
211+
212+
213+
# Gray/white matter: Improving registration results using binary segmentation masks
184214
# ======================================================================================================================
185215

186216
# Register template->t2s (using warping field generated from template<->t2 registration)
@@ -209,27 +239,10 @@ sct_register_multimodal -i "${SCT_DIR}/data/PAM50/template/PAM50_t2.nii.gz" \
209239
-qc ~/qc_singleSubj
210240

211241

212-
# Computing metrics for gray/white matter (including atlas-based tract analysis)
213-
# ======================================================================================================================
214242

215-
# Metrics using WM/GM mask only (no atlas)
216-
cd ../t2s
217-
# Compute cross-sectional area (CSA) of the gray and white matter for all slices in the volume.
218-
# Note: Here we use the flag -angle-corr 0, because we do not want to correct the computed CSA by the cosine of the
219-
# angle between the cord centerline and the S-I axis: we assume that slices were acquired orthogonally to the cord.
220-
sct_process_segmentation -i t2s_wmseg.nii.gz -o csa_wm.csv -angle-corr 0
221-
sct_process_segmentation -i t2s_gmseg.nii.gz -o csa_gm.csv -angle-corr 0
222-
223-
# You can also use a single binary mask to extract signal intensity from MRI data.
224-
# The example below will show how to use the GM and WM segmentations to quantify T2* signal intensity, as done in
225-
# [Martin et al. PLoS One 2018].
226-
# Quantify average WM and GM signal between slices 2 and 12.
227-
sct_extract_metric -i t2s.nii.gz -f t2s_wmseg.nii.gz -method bin -z 2:12 -o t2s_value.csv
228-
sct_extract_metric -i t2s.nii.gz -f t2s_gmseg.nii.gz -method bin -z 2:12 -o t2s_value.csv -append 1
229-
# Note: the flag -append enables to append a new result at the end of an already-existing csv file.
243+
# Atlas-based analysis (Extracting metrics (MTR) in gray/white matter tracts)
244+
# ======================================================================================================================
230245

231-
# Atlas-based tract analysis
232-
cd ../mt
233246
# In order to use the PAM50 atlas to extract/aggregate image data, the atlas must first be transformed to the MT space
234247
sct_warp_template -d mt1.nii.gz -w warp_template2mt.nii.gz -a 1 -qc ~/qc_singleSubj
235248
# Check results
@@ -246,7 +259,9 @@ sct_extract_metric -i mtr.nii.gz -f label/atlas -method map -l 51 -o mtr_in_wm.c
246259
sct_extract_metric -i mtr.nii.gz -f label/atlas -method map -l 4,5 -z 5:15 -o mtr_in_cst.csv
247260
# You can specify the vertebral levels to extract MTR from. For example, to quantify MTR between C2 and C4 levels in the
248261
# dorsal column (combined label: #53) using weighted average:
249-
sct_extract_metric -i mtr.nii.gz -f label/atlas -method wa -l 53 -vert 2:4 -o mtr_in_dc.csv
262+
sct_extract_metric -i mtr.nii.gz -f label/atlas -method map -l 53 \
263+
-vert 2:4 -vertfile label/template/PAM50_levels.nii.gz \
264+
-o mtr_in_dc.csv
250265

251266

252267
# Diffusion-weighted MRI
@@ -261,38 +276,37 @@ sct_maths -i dmri.nii.gz -mean t -o dmri_mean.nii.gz
261276
sct_deepseg_sc -i dmri_mean.nii.gz -c dwi -qc ~/qc_singleSubj
262277
# Create mask (for subsequent cropping)
263278
sct_create_mask -i dmri_mean.nii.gz -p centerline,dmri_mean_seg.nii.gz -f cylinder -size 35mm
264-
# Crop data for faster processing
265-
sct_crop_image -i dmri.nii.gz -m mask_dmri_mean.nii.gz -o dmri_crop.nii.gz
266279

267280
# Motion correction (moco)
268-
sct_dmri_moco -i dmri_crop.nii.gz -bvec bvecs.txt
269-
270-
# Compute DTI metrics using dipy [1]
271-
sct_dmri_compute_dti -i dmri_crop_moco.nii.gz -bval bvals.txt -bvec bvecs.txt
272-
# Tips: the flag "-method restore" estimates the tensor with robust fit (RESTORE method [2])
281+
sct_dmri_moco -i dmri.nii.gz -m mask_dmri_mean.nii.gz -bvec bvecs.txt \
282+
-qc ~/qc_singleSubj -qc-seg dmri_mean_seg.nii.gz
273283

274284
# Segment SC on motion-corrected mean dwi data (check results in the QC report)
275-
sct_deepseg_sc -i dmri_crop_moco_dwi_mean.nii.gz -c dwi -qc ~/qc_singleSubj
285+
sct_deepseg_sc -i dmri_moco_dwi_mean.nii.gz -c dwi -qc ~/qc_singleSubj
286+
276287
# Register template->dwi via t2s to account for GM segmentation
277288
# Tips: Here we use the PAM50 contrast t1, which is closer to the dwi contrast (although we are not using type=im in
278289
# -param, so it will not make a difference here)
279290
# Note: the flag “-initwarpinv" provides a transformation dmri->template, in case you would like to bring all your DTI
280291
# metrics in the PAM50 space (e.g. group averaging of FA maps)
281292
sct_register_multimodal -i "${SCT_DIR}/data/PAM50/template/PAM50_t1.nii.gz" \
282293
-iseg "${SCT_DIR}/data/PAM50/template/PAM50_cord.nii.gz" \
283-
-d dmri_crop_moco_dwi_mean.nii.gz \
284-
-dseg dmri_crop_moco_dwi_mean_seg.nii.gz \
294+
-d dmri_moco_dwi_mean.nii.gz \
295+
-dseg dmri_moco_dwi_mean_seg.nii.gz \
285296
-initwarp ../t2s/warp_template2t2s.nii.gz \
286297
-initwarpinv ../t2s/warp_t2s2template.nii.gz \
287298
-owarp warp_template2dmri.nii.gz \
288299
-owarpinv warp_dmri2template.nii.gz \
289300
-param step=1,type=seg,algo=centermass:step=2,type=seg,algo=bsplinesyn,slicewise=1,iter=3 \
290301
-qc ~/qc_singleSubj
291-
292-
# Warp template
293-
sct_warp_template -d dmri_crop_moco_dwi_mean.nii.gz -w warp_template2dmri.nii.gz -qc ~/qc_singleSubj
302+
# Warp template (so 'label/atlas' can be used to extract metrics)
303+
sct_warp_template -d dmri_moco_dwi_mean.nii.gz -w warp_template2dmri.nii.gz -qc ~/qc_singleSubj
294304
# Check results in the QC report
295305

306+
# Compute DTI metrics using dipy [1]
307+
sct_dmri_compute_dti -i dmri_moco.nii.gz -bval bvals.txt -bvec bvecs.txt
308+
# Tips: the flag "-method restore" estimates the tensor with robust fit (RESTORE method [2])
309+
296310
# Compute FA within the white matter from individual level 2 to 5
297311
sct_extract_metric -i dti_FA.nii.gz -f label/atlas \
298312
-l 51 -method map \
@@ -314,7 +328,8 @@ sct_register_multimodal -i ../t2/t2_seg.nii.gz -d fmri_mean.nii.gz -identity 1
314328
sct_create_mask -i fmri.nii.gz -p centerline,t2_seg_reg.nii.gz -size 35mm -f cylinder
315329

316330
# Motion correction (using mask)
317-
sct_fmri_moco -i fmri.nii.gz -m mask_fmri.nii.gz
331+
sct_fmri_moco -i fmri.nii.gz -m mask_fmri.nii.gz \
332+
-qc ~/qc_singleSubj -qc-seg t2_seg_reg.nii.gz
318333

319334
# Register the template to the fMRI scan.
320335
# Note: here we don't rely on the segmentation because it is difficult to obtain one automatically. Instead, we rely on
@@ -353,6 +368,7 @@ sct_smooth_spinalcord -i t1.nii.gz -s t1_seg.nii.gz
353368

354369
# Align the spinal cord in the right-left direction using slice-wise translations.
355370
sct_flatten_sagittal -i t1.nii.gz -s t1_seg.nii.gz
371+
# Note: Use for visualization purposes only
356372

357373
# Return to parent directory
358374
cd ..

tutorial-datasets.csv

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,20 @@ data_coregistration,single_subject/data/t2/warp_template2anat.nii.gz
1111
data_coregistration,single_subject/data/mt/mt1.nii.gz
1212
data_mtr-computation,single_subject/data/mt/mt0.nii.gz
1313
data_mtr-computation,single_subject/data/mt/mt1.nii.gz
14-
data_mtr-computation,single_subject/data/mt/mt1_seg.nii.gz
15-
data_mtr-computation,single_subject/data/mt/mask_mt1.nii.gz
1614
data_gm-wm-segmentation,single_subject/data/t2s/t2s.nii.gz
15+
data_gm-wm-metric-computation,single_subject/data/t2s/t2s_gmseg.nii.gz
16+
data_gm-wm-metric-computation,single_subject/data/t2s/t2s_wmseg.nii.gz
17+
data_gm-wm-metric-computation,single_subject/data/t2s/t2s.nii.gz
1718
data_improving-registration-with-gm-seg,single_subject/data/t2s/t2s.nii.gz
1819
data_improving-registration-with-gm-seg,single_subject/data/t2s/t2s_wmseg.nii.gz
1920
data_improving-registration-with-gm-seg,single_subject/data/t2/warp_anat2template.nii.gz
2021
data_improving-registration-with-gm-seg,single_subject/data/t2/warp_template2anat.nii.gz
2122
data_improving-registration-with-gm-seg,single_subject/data/mt/mt1.nii.gz
2223
data_improving-registration-with-gm-seg,single_subject/data/mt/mt1_seg.nii.gz
2324
data_improving-registration-with-gm-seg,single_subject/data/mt/mask_mt1.nii.gz
24-
data_gm-wm-metric-computation,single_subject/data/t2s/t2s_gmseg.nii.gz
25-
data_gm-wm-metric-computation,single_subject/data/t2s/t2s_wmseg.nii.gz
26-
data_gm-wm-metric-computation,single_subject/data/t2s/t2s.nii.gz
27-
data_gm-wm-metric-computation,single_subject/data/mt/warp_template2mt.nii.gz
28-
data_gm-wm-metric-computation,single_subject/data/mt/mt1.nii.gz
29-
data_gm-wm-metric-computation,single_subject/data/mt/mtr.nii.gz
25+
data_atlas-based-analysis,single_subject/data/mt/warp_template2mt.nii.gz
26+
data_atlas-based-analysis,single_subject/data/mt/mt1.nii.gz
27+
data_atlas-based-analysis,single_subject/data/mt/mtr.nii.gz
3028
data_processing-dmri-data,single_subject/data/dmri/dmri.nii.gz
3129
data_processing-dmri-data,single_subject/data/dmri/bvals.txt
3230
data_processing-dmri-data,single_subject/data/dmri/bvecs.txt

0 commit comments

Comments
 (0)