valosekj / dcm-brno

GNU General Public License v3.0
0 stars 0 forks source link

`sct_dmri_moco` is crashing: `itk::ERROR: MattesMutualInformationImageToImageMetricv4` #14

Closed valosekj closed 2 months ago

valosekj commented 2 months ago

sct_dmri_moco is crashing on the following error: itk::ERROR: MattesMutualInformationImageToImageMetricv4

https://github.com/valosekj/dcm-brno/blob/f8fedacbb7998eda66f63f6ad67e48ae45d42dce/scripts/01_process_data.sh#L340

detailed output ```console -- Spinal Cord Toolbox (git-master-65e44b5068fe5d8a094e3e0571566c01d2d460ab) sct_dmri_moco -i sub-2320B6468B_ses-6468B_acq-ZOOMit_dir-AP_dwi_crop.nii.gz -bvec sub-2320B6468B_ses-6468B_acq-ZOOMit_dir-AP_dwi.bvec -x spline -- Input parameters: Input file ............ sub-2320B6468B_ses-6468B_acq-ZOOMit_dir-AP_dwi_crop.nii.gz Group size ............ 3 Creating temporary folder (/tmp/sct_2024-07-05_03-20-12_moco-wrapper_uyw9_l8n) Copying input data to tmp folder and convert to nii... Get dimensions of data... 50 x 57 x 30 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: 7 [0, 1, 13, 25, 37, 49, 61] Number of DWI: 63 [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 62, 63, 64, 65, 66, 67, 68, 69] 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'. 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'. 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'. 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'. 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'. 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'. 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'. 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'. 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'. 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'. 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'. Image header specifies datatype 'int16', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'. Merge across groups... ------------------------------------------------------------------------------- Estimating motion on b=0 images... ------------------------------------------------------------------------------- Input parameters: Input file ............ b0.nii Reference file ........ data_T0001.nii.gz Polynomial degree ..... 2 Smoothing kernel ...... 1 Gradient step ......... 1 Metric ................ MI Sampling .............. None Todo .................. estimate_and_apply Mask ................. Output mat folder ..... mat_b0groups Data dimensions: 50 x 57 x 30 x 7 Copy file_target to a temporary file... Register. Loop across Z (note: there is only one Z if orientation is axial) Image header specifies datatype 'int16', but array is of type 'float32'. Header metadata will be overwritten to use 'float32'. ------------------------------------------------------------------------------- Estimating motion across groups... ------------------------------------------------------------------------------- Input parameters: Input file ............ datasub-groups.nii Reference file ........ datasub_0_mean.nii.gz Polynomial degree ..... 2 Smoothing kernel ...... 1 Gradient step ......... 1 Metric ................ MI Sampling .............. None Todo .................. estimate_and_apply Mask ................. Output mat folder ..... mat_groups Data dimensions: 50 x 57 x 30 x 21 Copy file_target to a temporary file... Register. Loop across Z (note: there is only one Z if orientation is axial) Traceback (most recent call last): File "/home/valosek/code/sct_v6.3/spinalcordtoolbox/scripts/sct_dmri_moco.py", line 232, in main(sys.argv[1:]) File "/home/valosek/code/sct_v6.3/spinalcordtoolbox/scripts/sct_dmri_moco.py", line 217, in main fname_output_image = moco_wrapper(param) File "/home/valosek/code/sct_v6.3/spinalcordtoolbox/moco.py", line 340, in moco_wrapper file_mat_datasub_group, _ = moco(param_moco) File "/home/valosek/code/sct_v6.3/spinalcordtoolbox/moco.py", line 609, in moco failed_transfo[it] = register(param, file_data_splitZ_splitT[it], file_target_splitZ[iz], file_mat[iz][it], File "/home/valosek/code/sct_v6.3/spinalcordtoolbox/moco.py", line 753, in register status, output = run_proc(cmd, verbose=1 if param.verbose == 2 else 0, env=env, **kw) File "/home/valosek/code/sct_v6.3/spinalcordtoolbox/utils/sys.py", line 342, in run_proc raise RuntimeError(output) RuntimeError: Exception caught: itk::ExceptionObject (0x37610e0) Location: "unknown" File: /__w/build_ANTs/build_ANTs/antsbin/staging/include/ITK-5.1/itkMattesMutualInformationImageToImageMetricv4.hxx Line: 312 Description: itk::ERROR: MattesMutualInformationImageToImageMetricv4(0x372efc0): Joint PDF summed to zero ```
valosekj commented 2 months ago

Changing the cropping from SC seg to centerline (https://github.com/valosekj/dcm-brno/issues/13) did not help.

SC seg (contrast-agnostic) ```bash # Separate b=0 and DWI volumes; the command will create also a file with the mean DWI ('_dwi_mean.nii.gz') sct_dmri_separate_b0_and_dwi -i ${file_dwi}.nii.gz -bvec ${file_bvec} # Segment spinal cord (only if it does not exist) using the contrast-agnostic model (part of SCT v6.2) # Note: this is just an initial segmentation to crop the data segment_sc_CA_if_does_not_exist "${file_dwi}"_dwi_mean "dwi" file_dwi_seg=$FILESEG # Crop data for faster processing sct_crop_image -i "${file_dwi}".nii.gz -m "${file_dwi_seg}".nii.gz -dilate 15x15x0 -o "${file_dwi}"_crop.nii.gz file_dwi="${file_dwi}_crop" # Motion correction on the cropped data sct_dmri_moco -i ${file_dwi}.nii.gz -bvec ${file_bvec} -x spline ```
Centerline ```bash # Separate b=0 and DWI volumes; the command will create also a file with the mean DWI ('_dwi_mean.nii.gz') sct_dmri_separate_b0_and_dwi -i ${file_dwi}.nii.gz -bvec ${file_bvec} # Get the centerline sct_get_centerline -i "${file_dwi}"_dwi_mean.nii.gz -c dwi # Crop data around the centerline for faster processing sct_crop_image -i "${file_dwi}".nii.gz -m "${file_dwi}"_dwi_mean_centerline.nii.gz -dilate 25x25x0 -o "${file_dwi}"_crop.nii.gz file_dwi="${file_dwi}_crop" # Motion correction on the cropped data sct_dmri_moco -i ${file_dwi}.nii.gz -bvec ${file_bvec} -x spline ```
valosekj commented 2 months ago

Increasing the param -g ("group nvols successive dMRI volumes for more robustness") to 5 (from default 3) did not help.

sct_dmri_moco -i ${file_dwi}.nii.gz -bvec ${file_bvec} -x spline -g 5

But maybe I should have tried also decrease to -g 2...

valosekj commented 2 months ago

Finding this forum post --> increasing the mask size

sct_crop_image -i "${file_dwi}".nii.gz -m "${file_dwi}"_dwi_mean_centerline.nii.gz -dilate 15x15x0 -o "${file_dwi}"_crop.nii.gz
15x15x0 Screenshot 2024-07-05 at 7 56 49 AM

--> crashing

25x25x0 Screenshot 2024-07-05 at 7 57 09 AM

--> crashing

35x35x0 Screenshot 2024-07-05 at 7 57 47 AM

--> working 🎉