Trouble warping to template

Thank you!

I appear to be having trouble registering to the diffusion scan as it is not a 3D volume? Perhaps I am using the wrong image file. This is what I have done:

sct_register_to_template -i dmri_crop.nii.gz -s t2_seg.nii.gz -l t2_labels_vert.nii.gz -ref subject -c t2 -param step=1,type=seg,algo=centermassrot,smooth=0:step=2,type=seg,algo=columnwise,smooth=0,smoothWarpXY=2 -qc ~/Documents/Research/CP_SDR/SCT_data/DTI_04/

you need to register with the DWI mean, not the 4D DWI volume. See e.g. https://spinalcordtoolbox.com/en/latest/user_section/getting-started.html#batch-processing-example

indeed, there are probably some confusions about what warping field you used for what data. The easiest way to debug, at this point, would be for you to share the data along with the analysis script. Please avoid absolute path-- i need to be able to reproduce your analysis without touching the script.

then, i will fix the script and upload it here.

Thank you very much! I will share both via email.

Hi,

Here is a script that works:

#!/bin/bash/

# t2
# ==============================================================================

# Segment spinal cord
sct_deepseg_sc -i t2.nii.gz -c t2 -qc qc

# Manual initialization of disc C2-C3
sct_label_utils -i t2.nii.gz -create-viewer 3 -o label_disc_c2c3.nii.gz

# Vertebral labeling
# Tips: given that the spine is smaller than in average adults, we used -scale-dist to adapt the scaling and disc detection.
sct_label_vertebrae -i t2.nii.gz -s t2_seg.nii.gz -c t2 -initlabel label_disc_c2c3.nii.gz -scale-dist 0.8 -qc qc

# Create labels at in the cord at C2 and C5 mid-vertebral levels
sct_label_utils -i t2_seg_labeled.nii.gz -vert-body 2,5 -o t2_labels_vert.nii.gz

# dwi
# ==============================================================================

# Bring t2 segmentation in dmri space to create mask (no optimization)
sct_maths -i dmri.nii.gz -mean t -o dmri_mean.nii.gz
sct_register_multimodal -i t2_seg.nii.gz -d dmri_mean.nii.gz -identity 1 -x linear

# Create Gaussian mask to increase accuracy of motion correction
sct_create_mask -i dmri_mean.nii.gz -p centerline,t2_seg_reg.nii.gz -f gaussian -size 35mm

# Motion correction
# Tips: if data have very low SNR you can increase the number of successive images that are averaged into group with "-g". Also see: sct_dmri_moco -h
sct_dmri_moco -i dmri.nii.gz -bvec bvecs.bvec -m mask_dmri_mean.nii.gz

# Segment cord on the DWI data
sct_deepseg_sc -i dmri_moco_dwi_mean.nii.gz -c dwi -qc qc

# Register to template directly to the dmri data, given the thick slices on the t2 scan
sct_register_to_template -i dmri_moco_dwi_mean.nii.gz -s dmri_moco_dwi_mean_seg.nii.gz -l t2_labels_vert.nii.gz -ref subject -c t1 -param step=1,type=seg,algo=centermassrot,smooth=0:step=2,type=seg,algo=bsplinesyn,smooth=0,iter=5,slicewise=1:step=3,type=im,algo=bsplinesyn,slicewise=1,iter=3 -qc qc

# Rename warping fields for clarity
mv warp_template2anat.nii.gz warp_template2dmri.nii.gz
mv warp_anat2template.nii.gz warp_dmri2template.nii.gz

# Warp template
sct_warp_template -d dmri_moco_dwi_mean.nii.gz -w warp_template2dmri.nii.gz -qc qc

# Compute DTI metrics
sct_dmri_compute_dti -i dmri_moco.nii.gz -bval bvals.txt -bvec bvecs.txt

# Compute FA in the white matter between C1 and C5
sct_extract_metric -i dti_FA.nii.gz -l 51 -v 1:5 -method map -o fa_in_wm.csv

Note: you did not share the bvals file so I cannot test the script entirely. But you can easily figure out how to adapt the script (just update the name of the bvals file).

Thank you very much for your assistance!

Hello! I seem to be getting an error at the motion correction step:

are you using the same data you sent me? If so, what is the output of: sct_version?

Yes I am! I am using version 4.1.0

can you please install the latest version from git’s master branch? Here are the instructions.

I downloaded the latest version and it works! Thank you!

1 Like

Hello @jcohenadad!

Following up, I seem to be getting a new error. When I run sct_dmri_moco -i dmri.nii.gz -bvec bvecs.bvec -m mask_dmri_mean.nii.gz, I get this error:

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/work/ANTs/ANTs/antsbin/staging/include/ITK-5.1/itkImageBase.hxx:177:
itk::ERROR: Image(0x7fe7de5bee60):
A spacing of 0 is not allowed: Spacing is [0, 0]

Once again, I would really appreciate your input! Thank you so much in advance :slight_smile:

Hi Adriana,

could you please post this in a new issue? the title of this thread is “Trouble warping to template”, so your latest issue is out of scope (it is important to keep issues organized, so others can easily find them based on their title)-- thanks!

Absolutely, thank you!

Hi @jcohenadad and SCT team!

I am currently trying to analyse DMRI data using spinalcordtoolbox commands as suggested by the tutorial online. Everything has gone smoothly until we have gotten to the warping to PAM50 template command:

sct_warp_template -d dmri_moco_dwi_mean.nii -w warp_template2dmri.nii.gz -qc …/qc

Basically, the warping templates are either incomplete or not accurately aligned with the cord. I wonder whether the sct_register_multimodal has worked properly either.

It is worth noting that the dmri data was acquired using ZOOMit as suggested by the generic acquisition protocol, and the FOV/slice acquisition of the T2 and DWI images are different.

I am unsure of how to resolve this issue if anyone has any solutions it would be much appreciated.

Thanks,

Alex

Hi Alexandra,

Thank you for reaching out. The issue you are experiencing could be caused by multiple things, so it is difficult for me to know what went wrong, without knowing exactly how the processing was done, and how the data look like.

As a first step, I suggest you look at the QC report of all steps (SC segmentation on the anat image, register multimodal, SC segmentation on the DWI scan, etc.). You could ZIP the QC folder and upload it here, so we can have a look and let you know if we notice something suspicious.

Cheers
Julien

Hi Julien,

Thank you for getting back to me. I have included the zip QC report for one of our patients. I just also wanted to mentiuon that the T2 labelling has been incorrect in some of our patients and we wondered if this has anything to do with it?

Kind regards,
Alex
qc.zip (1.8 MB)

This is definitely suspicious, given that the segmentation and labeling went well:

One possible source of error is that the qform/sform is corrupted, and/or the T2 and DWI scans were note acquired in the same patient coordinate (eg: participant was re-positioned in between). To verify this, can you open your T2w and dwi_mean data and overlay them on a viewer (using appropriate opacity level).

Hi Julien,

I used mcverter to convert the dicom files to nifti before preprocessing with sct toolbox using command: mcverter -o . -f fsl -n -d SubjDir/

Also, in regards to the sform and qform, whilst labelling th vertebrae in t2 Ubuntu would not let me label the vertebrae without running the sform command: sct_image -i (t2.nii or t2_seg.nii) -set-sform-to-qform

kind regards,
Alex

Hi Alex,

The fact that your images have different slice orientation is not the issue here. For example, see below an overlay of a T2w and a DWI scan, also acquired different slice orientation, number of slices, resolution, etc.:

The issue, as I suspected, is that either the q/sform is corrupted (eg: lost absolute coordinate system when converting from DICOM or after applying preprocessing methods with third-party software), and/or the patient was repositioned between the scans (laser marking re-done).

If this happens with most of your subjects, then there is something in your pipeline that is systematically wrong. To understand what is wrong, I suggest you describe the procedure to go from your DICOM data to your NIFTI images that then go into SCT’s software.

1 Like