spinalcord¶
S p i n a l c o r d s e g m e n t a t i o n a g n o s t i c t o M R I c o n t r a s t s Spinal cord segmentation agnostic to MRI contrasts
T h e c o n t r a s t a g n o s t i c s p i n a l c o r d s e g m e n t a t i o n u s e s a 3 D C N N m o d e l b a s e d o n t h e n n U N e t f r a m e w o r k . T r a i n i n g d a t a c o n s i s t s o f h e a l t h y c o n t r o l s f r o m t h e o p e n - s o u r c e S p i n e G e n e r i c M u l t i S u b j e c t d a t a b a s e a n d p a t h o l o g i e s f r o m p r i v a t e d a t a s e t s i n c l u d i n g D C M , M S , S C I ( A c u t e , I n t e r m e d i a t e a n d C h r o n i c ; P r e / P o s t - o p e r a t i v e ) p a t i e n t s . S e g m e n t a t i o n s h a v e b e e n t e s t e d w i t h t h e f o l l o w i n g c o n t r a s t s : [ T 1 w , T 2 w , T 2 s t a r , M T o n _ M T S , G R E _ T 1 w , D W I , m p 2 r a g e _ U N I T 1 , P S I R , S T I R , E P I ] , b u t o t h e r c o n t r a s t s t h a t a r e c l o s e v i s u a l m a t c h e s m a y a l s o w o r k w e l l w i t h t h i s m o d e l . The contrast agnostic spinal cord segmentation uses a 3D CNN model based on the nnUNet framework. Training data consists of healthy controls from the open-source Spine Generic Multi Subject database and pathologies from private datasets including DCM, MS, SCI (Acute, Intermediate and Chronic; Pre/Post-operative) patients. Segmentations have been tested with the following contrasts: [T1w, T2w, T2star, MTon_MTS, GRE_T1w, DWI, mp2rage_UNIT1, PSIR, STIR, EPI], but other contrasts that are close visual matches may also work well with this model.
Reference¶
@article{bedard2025towards,
title={Towards contrast-agnostic soft segmentation of the spinal cord},
author={Bédard, Sandrine and Karthik, Enamundram Naga and Tsagkas, Charidimos and Pravatà, Emanuele and Granziera, Cristina and Smith, Andrew and Weber II, Kenneth Arnold and Cohen-Adad, Julien},
journal={Medical Image Analysis},
pages={103473},
year={2025},
publisher={Elsevier}
}
P r o j e c t U R L : [ h t t p s : / / g i t h u b . c o m / s c t - p i p e l i n e / c o n t r a s t - a g n o s t i c - s o f t s e g - s p i n a l c o r d / ] ( h t t p s : / / g i t h u b . c o m / s c t - p i p e l i n e / c o n t r a s t - a g n o s t i c - s o f t s e g - s p i n a l c o r d / ) Project URL: https://github.com/sct-pipeline/contrast-agnostic-softseg-spinalcord/
usage: sct_deepseg spinalcord [-i <file> [<file> ...]] [-o <str>] [-install]
[-custom-url CUSTOM_URL [CUSTOM_URL ...]]
[-largest {0,1}] [-fill-holes {0,1}]
[-remove-small REMOVE_SMALL [REMOVE_SMALL ...]]
[-qc <folder>] [-qc-dataset <str>]
[-qc-subject <str>] [-qc-plane <str>]
[-qc-seg <file>] [-h] [-v <int>] [-r {0,1}]
[-test-time-aug]
INPUT/OUTPUT¶
- -i
I m a g e f i l e n a m e ( s ) t o s e g m e n t . I f s e g m e n t i n g m u l t i p l e f i l e s , s e p a r a t e f i l e n a m e s w i t h a s p a c e . Image filename(s) to segment. If segmenting multiple files, separate filenames with a space.
- -o
O u t p u t f i l e n a m e . T h e c h o s e n f i l e n a m e w i l l b e u s e d a s a b a s e n a m e , a n d m o d e l - s p e c i f i c s u f f i x e s w i l l b e a d d e d t o t h e e n d d e p e n d i n g o n t h e t y p e o f o u t p u t ( e . g . ‘ _ c o r d . n i i . g z ‘ , ‘ _ g m . n i i . g z ‘ , e t c . ) . Output file name. The chosen filename will be used as a base name, and model-specific suffixes will be added to the end depending on the type of output (e.g. ‘_cord.nii.gz’, ‘_gm.nii.gz’, etc.).
TASKS¶
- -install
I n s t a l l m o d e l s t h a t a r e r e q u i r e d f o r s p e c i f i e d t a s k . Install models that are required for specified task.
D e f a u l t : ` ` F a l s e ` ` Default:
False- -custom-url
U R L ( s ) p o i n t i n g t o t h e ` . z i p ` a s s e t f o r a m o d e l r e l e a s e . T h i s o p t i o n c a n b e u s e d w i t h ` - i n s t a l l ` t o i n s t a l l a s p e c i f i c v e r s i o n o f a m o d e l . T o u s e t h i s o p t i o n , n a v i g a t e t o t h e ‘ R e l e a s e s ‘ p a g e o f t h e m o d e l , f i n d r e l e a s e y o u w i s h t o i n s t a l l , a n d r i g h t - c l i c k + c o p y t h e U R L o f t h e ` . z i p ` l i s t e d u n d e r ‘ A s s e t s ‘ . E x a m p l e : ` s c t _ d e e p s e g s p i n a l c o r d - i n s t a l l - c u s t o m - u r l C U S T O M _ U R L ` ` s c t _ d e e p s e g s p i n a l c o r d - i t 2 . n i i . g z ` URL(s) pointing to the
.zipasset for a model release. This option can be used with-installto install a specific version of a model. To use this option, navigate to the ‘Releases’ page of the model, find release you wish to install, and right-click + copy the URL of the.ziplisted under ‘Assets’. Example:sct_deepseg spinalcord -install -custom-url CUSTOM_URLsct_deepseg spinalcord -i t2.nii.gz
PARAMETERS¶
- -largest
P o s s i b l e c h o i c e s : 0 , 1 Possible choices: 0, 1
K e e p t h e l a r g e s t c o n n e c t e d o b j e c t f r o m e a c h o u t p u t s e g m e n t a t i o n ; i f n o t s e t , a l l o b j e c t s a r e k e p t . Keep the largest connected object from each output segmentation; if not set, all objects are kept.
D e f a u l t : ` ` 0 ` ` Default:
0- -fill-holes
P o s s i b l e c h o i c e s : 0 , 1 Possible choices: 0, 1
I f s e t , s m a l l h o l e s i n t h e s e g m e n t a t i o n w i l l b e f i l l e d i n a u t o m a t i c a l l y . If set, small holes in the segmentation will be filled in automatically.
D e f a u l t : ` ` 0 ` ` Default:
0- -remove-small
M i n i m a l o b j e c t s i z e t o k e e p w i t h u n i t ( m m 3 o r v o x ) . A s i n g l e v a l u e c a n b e p r o v i d e d o r o n e v a l u e p e r p r e d i c t i o n c l a s s . S i n g l e v a l u e e x a m p l e : 1 m m 3 , 5 v o x . M u l t i p l e v a l u e s e x a m p l e : 1 0 2 0 1 0 v o x ( r e m o v e o b j e c t s s m a l l e r t h a n 1 0 v o x e l s f o r c l a s s 1 a n d 3 , a n d s m a l l e r t h a n 2 0 v o x e l s f o r c l a s s 2 ) . Minimal object size to keep with unit (mm3 or vox). A single value can be provided or one value per prediction class. Single value example: 1mm3, 5vox. Multiple values example: 10 20 10vox (remove objects smaller than 10 voxels for class 1 and 3, and smaller than 20 voxels for class 2).
- -test-time-aug
P e r f o r m t e s t - t i m e a u g m e n t a t i o n ( T T A ) b y f l i p p i n g t h e i n p u t i m a g e a l o n g a l l a x e s a n d a v e r a g i n g t h e r e s u l t i n g p r e d i c t i o n s . N o t e : T h e t i m e i t t a k e s t o r u n t h e m o d e l w i l l i n c r e a s e d u e t o t h e a d d i t i o n a l p r e d i c t i o n s . Perform test-time augmentation (TTA) by flipping the input image along all axes and averaging the resulting predictions. Note: The time it takes to run the model will increase due to the additional predictions.
D e f a u l t : ` ` F a l s e ` ` Default:
False
MISC ARGUMENTS¶
- -qc
T h e p a t h w h e r e t h e q u a l i t y c o n t r o l g e n e r a t e d c o n t e n t w i l l b e s a v e d . The path where the quality control generated content will be saved.
- -qc-dataset
I f p r o v i d e d , t h i s s t r i n g w i l l b e m e n t i o n e d i n t h e Q C r e p o r t a s t h e d a t a s e t t h e p r o c e s s w a s r u n o n . If provided, this string will be mentioned in the QC report as the dataset the process was run on.
- -qc-subject
I f p r o v i d e d , t h i s s t r i n g w i l l b e m e n t i o n e d i n t h e Q C r e p o r t a s t h e s u b j e c t t h e p r o c e s s w a s r u n o n . If provided, this string will be mentioned in the QC report as the subject the process was run on.
- -qc-plane
P o s s i b l e c h o i c e s : A x i a l , S a g i t t a l Possible choices: Axial, Sagittal
P l a n e o f t h e o u t p u t Q C . I f S a g i t t a l , i t i s h i g h l y r e c o m m e n d e d t o p r o v i d e t h e ` - q c - s e g ` o p t i o n , a s i t w i l l e n s u r e t h e o u t p u t Q C i s c r o p p e d t o a r e a s o n a b l e f i e l d o f v i e w . Plane of the output QC. If Sagittal, it is highly recommended to provide the
-qc-segoption, as it will ensure the output QC is cropped to a reasonable field of view.D e f a u l t : ` ` ‘ A x i a l ‘ ` ` Default:
'Axial'- -qc-seg
S e g m e n t a t i o n f i l e t o u s e f o r c r o p p i n g t h e Q C . T h i s o p t i o n i s u s e f u l w h e n y o u w a n t t o Q C a r e g i o n t h a t i s d i f f e r e n t f r o m t h e o u t p u t s e g m e n t a t i o n . F o r e x a m p l e , i t m i g h t b e u s e f u l t o p r o v i d e a d i l a t e d c o r d s e g m e n t a t i o n t o e x p a n d t h e Q C f i e l d o f v i e w . Segmentation file to use for cropping the QC. This option is useful when you want to QC a region that is different from the output segmentation. For example, it might be useful to provide a dilated cord segmentation to expand the QC field of view.
I f ` - q c - s e g ` i s n o t p r o v i d e d , t h e d e f a u l t b e h a v i o r w i l l d e p e n d o n t h e v a l u e o f ` - q c - p l a n e ` : If
-qc-segis not provided, the default behavior will depend on the value of-qc-plane:‘ A x i a l ‘ : W i t h o u t ‘ - q c - s e g ‘ , a s e n s i b l e c r o p r a d i u s b e t w e e n 1 5 - 4 0 v o x w i l l b e a u t o m a t i c a l l y u s e d , d e p e n d i n g o n t h e r e s o l u t i o n a n d s e g m e n t a t i o n t y p e . ‘Axial’: Without ‘-qc-seg’, a sensible crop radius between 15-40 vox will be automatically used, depending on the resolution and segmentation type.
‘ S a g i t t a l ‘ : W i t h o u t ‘ - q c - s e g ‘ , t h e f u l l i m a g e w i l l b e d i s p l a y e d b y d e f a u l t . ( F o r v e r y l a r g e i m a g e s , t h i s m a y c a u s e a c r a s h , s o u s i n g ` - q c - s e g ` i s h i g h l y r e c o m m e n d e d . ) ‘Sagittal’: Without ‘-qc-seg’, the full image will be displayed by default. (For very large images, this may cause a crash, so using
-qc-segis highly recommended.)
- -v
P o s s i b l e c h o i c e s : 0 , 1 , 2 Possible choices: 0, 1, 2
V e r b o s i t y . 0 : D i s p l a y o n l y e r r o r s / w a r n i n g s , 1 : E r r o r s / w a r n i n g s + i n f o m e s s a g e s , 2 : D e b u g m o d e . Verbosity. 0: Display only errors/warnings, 1: Errors/warnings + info messages, 2: Debug mode.
D e f a u l t : ` ` 1 ` ` Default:
1- -r
P o s s i b l e c h o i c e s : 0 , 1 Possible choices: 0, 1
R e m o v e t e m p o r a r y f i l e s . Remove temporary files.
D e f a u l t : ` ` 1 ` ` Default:
1