Error when running sct_dmri_moco

Hi! julien:
I have two questions:
(1)It occurred some errors when i running sct_dmri_moco,my code is:

sct_seperate_b0_and_dwi -i dmri.nii -bvec bvec.TXT
sct_propseg -i dmri_dwi_mean.nii  -c dwi -qc qc_seg
sct_create_mask -i dmri_dwi_mean.nii  -p centerline,dmri_dwi_mean_seg.nii -size 35mm
sct_crop_image -i dmri.nii -m mask_dmri_dwi_mean.nii -o dmri_crop.nii
sct_dmri_moco -i dmri_crop.nii -bvec bvec.TXT

and followed by this error:

Register. Loop across Z (note: there is only one Z if orientation is axial)
Z=0/0:   0%|                                            | 0/3 [00:00<?, ?iter/s]
Traceback (most recent call last):
  File "/Users/ljx/sct_dev/scripts/", line 155, in <module>
  File "/Users/ljx/sct_dev/scripts/", line 150, in main
  File "/Users/ljx/sct_dev/spinalcordtoolbox/", line 320, in moco_wrapper
    file_mat_b0, _ = moco(param_moco)
  File "/Users/ljx/sct_dev/spinalcordtoolbox/", line 610, in moco
    file_data_splitZ_splitT_moco[it], im_mask=input_mask)
  File "/Users/ljx/sct_dev/spinalcordtoolbox/", line 750, in register
    status, output =, verbose=1 if param.verbose == 2 else 0, env=env, **kw)
  File "/Users/ljx/sct_dev/scripts/", line 310, in run
    raise RunError(output)
sct_utils.RunError: Warning: bad time point - too little intensity variation0 0
libc++abi.dylib: terminating with uncaught exception of type itk::ExceptionObject: /Users/runner/runners/2.169.1/work/ANTs/ANTs/antsbin/staging/include/ITK-5.1/itkImageBase.hxx:177:
itk::ERROR: Image(0x7f9f279bc290): A spacing of 0 is not allowed: Spacing is [0, 0]

I want to label the vertebrae on DTI image,but the dmri image’s quality isn’t good,so SCT can’t do this well . I label the subject’s T1 image,then register labeled T1 image to dmri space,and this work is done.but the question is i don’t know how to set the parameters ,thanks your help!
data is


Please note that the syntax is incorrect: sct_seperate_b0_and_dwi should be sct_dmri_separate_b0_and_dwi. To prevent errors and to ensure reproducibility, I suggest you write your syntax in a batch script instead of manual copy/paste.

Now, regarding your error: it is caused by an empty slice at z=0, see below:

The motion correction algorithm doesn’t know how to perform motion correction on empty slices, hence the crash. I’ve just opened an issue to ignore those cases, but in the meantime, the following workaround should work for you:

sct_dmri_separate_b0_and_dwi -i dmri.nii -bvec bvec.TXT
# Segment the cord
sct_propseg -i dmri_dwi_mean.nii  -c dwi -qc qc
# Remove the slice(s) from the segmentation where there is no signal on the image
sct_maths -i dmri_dwi_mean_seg.nii -mul dmri_dwi_mean.nii -o dmri_dwi_mean_seg_mul.nii
sct_maths -i dmri_dwi_mean_seg_mul.nii -bin 0.0001 -o dmri_dwi_mean_seg_mul_thr.nii
# Create a mask around the cord
sct_create_mask -i dmri_dwi_mean.nii  -p centerline,dmri_dwi_mean_seg_mul_thr.nii -size 35mm
# Crop the dMRI data
sct_crop_image -i dmri.nii -m mask_dmri_dwi_mean.nii -o dmri_crop.nii
# Perform motion correction
sct_dmri_moco -i dmri_crop.nii -bvec bvec.TXT

There are various ways you can do that. Here is an example of commands:

# Segment the cord on the T1w scan
sct_deepseg_sc -i T1.nii -c t1 -qc qc
# Label vertebrae
# Note: unfortunately, automatic C2/C3 disc detection failed, so I had to specify the z-slice number for C2/C3 disc
sct_label_vertebrae -i T1.nii -s T1_seg.nii -c t1 -initz 115,3 -qc qc
# Create labels at C3 and C5 vertebral bodies, for registration to the template
sct_label_utils -i T1_seg_labeled.nii -vert-body 3,5 -o labels_3-5.nii.gz
# Segment the cord on the motion-corrected dMRI data
sct_deepseg_sc -i dmri_crop_moco_dwi_mean.nii -c dwi -qc qc
# Register the dMRI scan with the PAM50 template
sct_register_to_template -i dmri_crop_moco_dwi_mean.nii -s dmri_crop_moco_dwi_mean_seg.nii -l labels_3-5.nii.gz -ref subject -c t1 -qc qc
# Warp PAM50 objects on the dMRI space
sct_warp_template -w warp_template2anat.nii.gz -d dmri_crop_moco_dwi_mean.nii -qc qc

Here here is the output QC: (789.5 KB)