-
Notifications
You must be signed in to change notification settings - Fork 0
Home
This wiki page collects frequently asked questions and examples of script usage.
The config YAML file (<CONFIG_FILE>) contains two main pieces of information:
- The type of correction wanted (i.e.
FILES_SEG
,FILES_LESION
,FILES_LABEL
, ...) - A list of the images to correct/create new labels
Below is an example YAML file:
FILES_SEG:
- sub-001_T1w.nii.gz
- sub-002_T2w.nii.gz
FILES_GMSEG:
- sub-001_T1w.nii.gz
- sub-002_T2w.nii.gz
FILES_LESION:
- sub-001_T1w.nii.gz
- sub-002_T2w.nii.gz
FILES_LABEL:
- sub-001_T1w.nii.gz
- sub-002_T1w.nii.gz
FILES_COMPRESSION:
- sub-001_T1w.nii.gz
- sub-002_T1w.nii.gz
FILES_PMJ:
- sub-001_T1w.nii.gz
- sub-002_T1w.nii.gz
FILES_ROOTLETS:
- sub-001_T1w.nii.gz
- sub-002_T1w.nii.gz
FILES_CENTERLINE:
- sub-001_T1w.nii.gz
- sub-002_T1w.nii.gz
This section shows several correction workflows (segmentation corrections, lesion corrections, ...).
The workflow is the following:
- Loop across subjects listed in the <CONFIG_FILE> YAML file.
- Correct the segmentation mask using editing tools. Tip: Toggle the lesion overlay on/off to help validate the accuracy of the label.
- Press Save button to save the manually corrected segmentation mask. Note: The
manual_correction.py
will automatically save manually-corrected segmentation masks under thederivatives/labels/
folder at the root ofOUTPUT_PATH
according to the BIDS convention.
Example command:
python manual_correction.py -path-img <INPUT_PATH>/data_processed -config <CONFIG_FILE> -path-out <OUTPUT_PATH>
Spinal cord segmentation corrections:
FILES_SEG:
- sub-001_T1w.nii.gz
- sub-002_T2w.nii.gz
Gray matter segmentation corrections:
FILES_GMSEG:
- sub-001_T2star.nii.gz
- sub-002_T2star.nii.gz
MS lesion corrections:
FILES_LESION:
- sub-edm005_ses-M0_PSIR.nii.gz
- sub-edm008_ses-M0_PSIR.nii.gz
- sub-edm010_ses-M0_PSIR.nii.gz
Examples of MS lesion corrections: 1
Spinal cord segmentation corrections across all subjects using the wildcard *
:
FILES_SEG:
- sub-*_ses-M0_T2w.nii.gz
ℹ️ If your input images have been preprocessed (e.g., reoriented to RPI and resampled) and thus contain the suffix _RPI_r
, the config YAML file will have the following format. Also, you will have to use the -suffix-files-in _RPI_r
flag.
FILES_SEG:
- sub-*_ses-M0_T2w_RPI_r.nii.gz
ℹ️ Once all corrections are done, you can generate a QC report by adding the flag -qc-only
to the command above. Note that SCT is required for generating QC report.
ℹ️ You can load an additional contrast using -load-other-contrast
flag.
ℹ️ You can open an additional orthoview in FSLeyes using the --fsleyes-second-orthoview
flag.
Here is a video for correcting manual SC segmentation: Youtube manual
Here are several helpful videos reviewing how to correct manual MS lesion segmentations: 1, 2, 3, 4.
The workflow is the following:
- Loop across subjects listed in the <CONFIG_FILE> YAML file.
- Correct the vertebral labeling based on the labeling convention.
- Press Save and Quit button to save the manually corrected vertebral labeling. Note: The
manual_correction.py
will automatically save manually-corrected vertebral labeling under thederivatives/labels/
folder at the root ofOUTPUT_PATH
according to the BIDS convention.
Example command:
python manual_correction.py -path-img <INPUT_PATH>/data_processed -config <CONFIG_FILE> -path-out <OUTPUT_PATH>
FILES_LABEL:
- sub-001_T2w.nii.gz
- sub-002_T2w.nii.gz
ℹ️ You can specify discs to label using -label-disc-list
flag. For example, if you want to correct only the disc C2/C3, specify -label-disc-list 3
.
Here is a video for correcting vertebral labeling: Youtube manual
This is an example of how to label spinal cord compressions using sagittal and axial images.
The workflow is the following:
- Loop across subjects listed in the <CONFIG_FILE> YAML file.
- Open the axial and sagittal images in FSLeyes.
- Look at the clinical data provided with compression information.
- Locate the compression in the sagittal view.
- In the axial view, toggle to the maximum compressed slice around the compression
- Press
alt
+E
(Windows) oroption
+E
(macOS) to open edit mode. Select size 1 and click on the pencil. - Place the label at the center of the spinal cord of the axial image.
- Repeat steps 4 to 8 for the number of compressions.
- Save and quit.
Example command:
python manual_correction.py -path-img <INPUT_PATH>/data_processed -config <CONFIG_FILE> -path-out <OUTPUT_PATH> -load-other-contrast acq-sagittal_T2w
ℹ️ You can display sagittal and axial images in two separate ortho views: View
-> OrthoView
and then Settings
-> Ortho View 2
-> View settings
-> Display space
. See the video tutorial here.
Spinal cord compression labeling:
FILES_COMPRESSION:
- sub-001_acq-axial_T2w.nii.gz
- sub-002_acq-axial_T2w.nii.gz
This is an example of how to label SCI lesions using sagittal and axial images.
- Loop across subjects listed in the <CONFIG_FILE> YAML file.
- Open the sagittal and axial images in FSLeyes.
- Display the sagittal and axial images in two separate ortho views:
View
->OrthoView
and thenSettings
->Ortho View 2
->View settings
->Display space
. See the video tutorial here. - Press
alt
+E
(Windows) oroption
+E
(macOS/Linux) to open edit mode. Use fill value 1 and click on the pencil. - Segment the lesion in the sagittal image (i.e., in the left OrthoView with the sagittal plane). You can use the axial plane for additional information.
- Save the lesion with the
_lesion.nii.gz
suffix. - If the subject also has apparent hemorrhage (T2w hypo-intensity), segment the hemorrhage as a new mask, i.e., in the sagittal plane, create a new mask (
Edit
->Create mask
orcmd
+N
(macOS/Linux)). Use fill value 1. - Save the hemorrhage with the
lesion_hemorrhage.nii.gz
suffix.
ℹ️ Be careful about switching between the overlays when segmenting the lesion and hemorrhage.
Example command:
python manual_correction.py -path-img <INPUT_PATH>/<DATASET> -config <CONFIG_FILE> -load-other-contrast acq-axial_T2w
SCI lesion segmentation:
FILES_LESION:
- sub-001_acq-sag_T2w.nii.gz
- sub-002_acq-sag_T2w.nii.gz
- sub-003_acq-sag_T2w.nii.gz
Example command:
python manual_correction.py -path-img <INPUT_PATH>/data_processed -config <CONFIG_FILE>
The workflow is the following:
- Loop across subjects listed in the <CONFIG_FILE> YAML file.
- The script opens a GUI that allows you to select a few points on the SC so as to extract the centerline.
- Press Save and Quit button to save the manually extracted centerline. Note: The
manual_correction.py
will automatically save the manually extracted centerline under thederivatives/labels/
folder at the root ofOUTPUT_PATH
according to the BIDS convention.
ℹ️ Note that two centerline files (.nii.gz
and .csv
) will be generated
Spinal cord centerline extraction:
FILES_CENTERLINE:
- sub-001_T1w.nii.gz
- sub-002_T2w.nii.gz
The workflow is the following:
- Loop across subjects listed in the <CONFIG_FILE> YAML file.
- Open the image in FSLeyes.
- Locate spinal nerve rootlet number 2 -- in the sagittal plane, find vertebrae C1 and scroll through the sagittal slices to identify where the nerve exits the spinal canal through the intervertebral foramen
- Hide the sagittal plane to save space and zoom the axial plane
- Press
alt
+E
(Linux/Windows) oroption
+E
(macOS) to open edit mode. Set the Selection size to 2 and the Fill value to 2. Click on the pencil and label the nerve. - Once the nerve rootlet for spinal level number 2 is segmented, identify spinal nerve rootlet number 3 (see Step 3). Then, change the Fill value to 3 and label the nerve.
- Repeat Step 6 for each nerve rootlet. Do not forget to change the Fill value for each nerve!
- Save and quit.
ℹ️ Note that we segment only the dorsal nerve rootlets.
After you finish manual corrections, upload the manually-corrected segmentations to git-annex (see internal documentation).
You can use the copy_files_to_derivatives.py
script provided within this repository to copy manually corrected labels (segmentations, disc labels, etc.) from your local derivatives/labels folder to the already existing git-annex BIDS dataset's derivatives/labels folder.
If automatically generated SC segmentations are fine and you just want to add them to git-annex, you can use -add-seg-only
option of the manual_correction.py
script. Example command:
python manual_correction.py -path-img <INPUT_PATH>/data_processed/ -path-out <OUTPUT_PATH>/<DATASET_NAME> -config <CONFIG_FILE> -add-seg-only