@@ -175,6 +175,33 @@ segment_sc_CA_if_does_not_exist(){
175
175
fi
176
176
}
177
177
178
+ # Check if manual segmentation already exists (under /derivatives/labels/). If it does, copy it locally. If
179
+ # it does not, perform segmentation using sct_deepseg_sc.
180
+ segment_sc_if_does_not_exist (){
181
+ local file=" $1 "
182
+ local contrast=" $2 "
183
+ # Find contrast
184
+ if [[ $contrast == " dwi" ]]; then
185
+ folder_contrast=" dwi"
186
+ else
187
+ folder_contrast=" anat"
188
+ fi
189
+ # Update global variable with segmentation file name
190
+ FILESEG=" ${file} _seg"
191
+ FILESEGMANUAL=" ${PATH_DATA} /derivatives/labels/${SUBJECT} /${folder_contrast} /${FILESEG} .nii.gz"
192
+ echo
193
+ echo " Looking for manual segmentation: $FILESEGMANUAL "
194
+ if [[ -e $FILESEGMANUAL ]]; then
195
+ echo " ✅ Found! Using manual segmentation."
196
+ rsync -avzh $FILESEGMANUAL ${FILESEG} .nii.gz
197
+ sct_qc -i ${file} .nii.gz -s ${FILESEG} .nii.gz -p sct_deepseg_sc -qc ${PATH_QC} -qc-subject ${file}
198
+ else
199
+ echo " ❌ Not found. Proceeding with automatic segmentation."
200
+ # Segment spinal cord
201
+ sct_deepseg_sc -i ${file} .nii.gz -c ${contrast} -qc ${PATH_QC} -qc-subject ${file}
202
+ fi
203
+ }
204
+
178
205
# Check if manual segmentation already exists. If it does, copy it locally. If
179
206
# it does not, perform seg.
180
207
segment_gm_if_does_not_exist (){
@@ -344,8 +371,10 @@ sct_dmri_moco -i ${file_dwi}.nii.gz -bvec ${file_bvec} -x spline -param metric=C
344
371
file_dwi=${file_dwi} _moco
345
372
file_dwi_mean=${file_dwi} _dwi_mean
346
373
347
- # Segment spinal cord (only if it does not exist) using the contrast-agnostic model (part of SCT v6.2)
348
- segment_sc_CA_if_does_not_exist ${file_dwi_mean} " dwi"
374
+ # Segment spinal cord (only if it does not exist) using sct_deepseg_sc
375
+ # Note: sct_deepseg_sc seems to work better for DWI than the contrast-agnostic model; details:
376
+ # https://github.com/valosekj/dcm-brno/issues/19
377
+ segment_sc_if_does_not_exist ${file_dwi_mean} " dwi"
349
378
file_dwi_seg=$FILESEG
350
379
351
380
# Register template->dwi (using T2w-to-template as initial transformation)
0 commit comments