"Joint PDF summed to zero" error at the motion correction step for DTI algorithm

Hello,

I’m encountering this error when I run the motion correction after generating a mask and segmenting the spinal cord on the DTI sequence, which looks pretty good on QC.

Spinal Cord Toolbox (7.0)

sct_dmri_moco -i 2025-08-17-001_AXIAL_DTI_AND_DIFFUSION_20160515110901_23.nii.gz -m mask_2025-08-17-001_AXIAL_DTI_AND_DIFFUSION_20160515110901_23_dwi_mean.nii.gz -bvec 2025-08-17-001_AXIAL_DTI_AND_DIFFUSION_20160515110901_23.bvec -qc ~/qc_singleSubj -qc-seg dmri_dwi_mean_seg.nii.gz
--


Input parameters:
  Input file ............ 2025-08-17-001_AXIAL_DTI_AND_DIFFUSION_20160515110901_23.nii.gz
  Group size ............ 3
Creating temporary folder (C:\Users\sbaig\AppData\Local\Temp\sct_2025-09-17_19-55-14_moco-wrapper_5ctg4f2p)

Copying input data to tmp folder and convert to nii...

Get dimensions of data...
  166 x 66 x 20

Data orientation: RPI
  Treated as axial

Set suffix of transformation file name, which depends on the orientation:
Orientation is axial, suffix is 'Warp.nii.gz'. The estimated transformation is a 3D warping field, which is composed of a stack of 2D Tx-Ty transformations

Identify b=0 and DWI images...
  WARNING: bvecs file is 3xn instead of nx3. Consider using sct_dmri_transpose_bvecs.
  Transpose bvecs...
  Number of b=0: 1 [0]
  Number of DWI: 20 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]

Split along T dimension...

Merge and average b=0 data...
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Merge within groups:   0%|                              | 0/7 [00:00<?, ?iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Merge within groups:  29%|######2               | 2/7 [00:00<00:00, 14.41iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Merge within groups:  57%|############5         | 4/7 [00:00<00:00, 10.02iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Merge within groups:  86%|##################8   | 6/7 [00:00<00:00, 11.25iter/s]Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Merge within groups: 100%|######################| 7/7 [00:00<00:00, 11.82iter/s]

Merge across groups...

-------------------------------------------------------------------------------
  Estimating motion on b=0 images...
-------------------------------------------------------------------------------

Input parameters:
  Input file ............ b0.nii
  Reference file ........ data_T0000.nii.gz
  Polynomial degree ..... 2
  Smoothing kernel ...... 1
  Gradient step ......... 1
  Metric ................ MI
  Sampling .............. None
  Todo .................. estimate_and_apply
  Mask  ................. mask.nii
  Output mat folder ..... mat_b0groups

Data dimensions:
  166 x 66 x 20 x 1

Copy file_target to a temporary file...
Image header specifies datatype 'int32', but array is of type '<class 'numpy.uint8'>'. Header metadata will be overwritten to use '<class 'numpy.uint8'>'.

Register. Loop across Z (note: there is only one Z if orientation is axial)
Z=0/0:   0%|                                            | 0/1 [00:00<?, ?iter/s]
Traceback (most recent call last):
  File "C:\Users\sbaig\sct_7.0\spinalcordtoolbox\scripts\sct_dmri_moco.py", line 216, in <module>
    main(sys.argv[1:])
  File "C:\Users\sbaig\sct_7.0\spinalcordtoolbox\scripts\sct_dmri_moco.py", line 201, in main
    fname_output_image = moco_wrapper(param)
  File "C:\Users\sbaig\sct_7.0\spinalcordtoolbox\moco.py", line 330, in moco_wrapper
    file_mat_b0, _ = moco(param_moco)
  File "C:\Users\sbaig\sct_7.0\spinalcordtoolbox\moco.py", line 610, in moco
    failed_transfo[it] = register(param, file_data_splitZ_splitT[it], file_target_splitZ[iz], file_mat[iz][it],
  File "C:\Users\sbaig\sct_7.0\spinalcordtoolbox\moco.py", line 754, in register
    status, output = run_proc(cmd, verbose=1 if param.verbose == 2 else 0, env=env, **kw)
  File "C:\Users\sbaig\sct_7.0\spinalcordtoolbox\utils\sys.py", line 334, in run_proc
    raise RuntimeError(output)
RuntimeError: setting mask C:\Users\sbaig\AppData\Local\Temp\sct_2025-09-17_19-55-14_moco-wrapper_5ctg4f2p\mask_bin.nii
Exception caught:
itk::ExceptionObject (000000E78519DA60)
Location: "unknown"
File: D:\a\build_ANTs\build_ANTs\antsbin\staging\include\ITK-5.1\itkMattesMutualInformationImageToImageMetricv4.hxx
Line: 312
Description: itk::ERROR: MattesMutualInformationImageToImageMetricv4(000002964D39B810): Joint PDF summed to zero
Total runtime; 1.615 seconds.

Dear @sabaig,

Thank you for your question! There have been several instances of this error in recent months. The following comments contain advice for how to handle this issue:

I would recommend checking the source dMRI files as well as the segmentation file for any discontinuities or issues. (The axial QC can sometimes not show the full picture, so I would look at the sagittal view in a program such as FSLeyes.)

Also, if you are able to, could you please share a sample image? It would help us to diagnose any potential issues.

Kind regards,
Joshua

1 Like