SCT_apply_transfo problems

Dear SCT Team,

We are finding problems when applying warpings to mask files. We have tried the sct_apply_transfo with nearest neighbour interpolation and we obtain the mask in the correct orientation and voxelsize but, unfortunately, it is an empty mask.
We have also applied sct_deepseg_sc to the structural image obtained after sct_register_to_template and the results are not the expected.
Any insights?
May the fact that we are working with cervical images have something to do with it?

Regards
Manel

Hi Manel,

Thank you for reaching out.

We have tried the sct_apply_transfo with nearest neighbour interpolation and we obtain the mask in the correct orientation and voxelsize but, unfortunately, it is an empty mask.

There could be many problems, e.g. empty source mask, wrong coordinate of destination image, or corrupted/wrong transformation. Can you provide a link to the mask + warping field + destination image + the syntax you were using, so we can reproduce your error?

We have also applied sct_deepseg_sc to the structural image obtained after sct_register_to_template and the results are not the expected.

What do you mean by “are not the expected”? Does the function crash? Is the output mask empty? Is the segmentation incorrect? if incorrect, are we talking only a few voxels of almost the entire segmentation? If you provide a link to your image + the syntax you run we would be able to assist. Also, please, always indicate SCT version you are running.

May the fact that we are working with cervical images have something to do with it?

No, SCT is primarily tested on cervical data.

Best,
Julien

Dear Julien,

When I said “are not the expected” I meant that the output mask is empty. We used the following syntax under SCT version 4.0.2

sct_apply_transfo -i crop_2018_lesionseg.nii -d anat2template.nii.gz -o reg_crop_2018_lesionseg.nii -w warp_anat2template.nii.gz

As requested I have sent you the following files:
crop_2018_MPRAGE.nii.gz – original T1
crop_2018_MPRAGE_seg.nii.gz – SCT segmentation
crop_2018_lesionseg.nii.gz – SCT lesion mask
labels_disc.nii.gz – SCT vertebral labels
warp_anat2template.nii.gz – SCT warping file
anat2template.nii.gz – original T1 to template
reg_crop_2018_lesionseg.nii.gz – SCT lesion mask registered to template using the warping file

Thanks
_
Manel

Hi Manel,

Two problems:

Problem 1: Used more than 2 discs for labels

the problem is that the warping field is defined only between C2-C3 disc and C4-C5 disc, because you used more than 2 labels with sct_register_to_template. I’ve added this information as a WARNING in the London’20 SCT course page 59. Since your lesion segmentation is defined outside the upper most label, it will not be wrapped when you apply the transformation. So, the solution is to only use two labels, and re-run the registration to the template.

Problem 2: The q/sform of your lesion segmentation is not the same as for your native MPRAGE image, resulting in inconsistent registration:

fslhd crop_2018_lesionseg.nii.gz | grep qto_xyz
qto_xyz:1	-0.114204 0.033926 0.992878 -78.421860 
qto_xyz:2	-0.989673 0.083261 -0.116680 120.223953 
qto_xyz:3	0.086626 0.995950 -0.024067 -159.768433 
qto_xyz:4	0.000000 0.000000 0.000000 1.000000 

fslhd crop_2018_MPRAGE.nii.gz | grep qto_xyz
qto_xyz:1	-0.038813 0.086602 0.995487 -95.888809 
qto_xyz:2	-0.999246 -0.003364 -0.038667 162.809860 
qto_xyz:3	0.000000 0.996237 -0.086667 51.091457 
qto_xyz:4	0.000000 0.000000 0.000000 1.000000

You should revise the method/software you use to generate those segmentations.

Solution

As a solution, I’ve removed one label from your label file, and copied the q/sform from the cropped MPRAGE data:

# Remove label 4
sct_label_utils -i labels_disc.nii.gz -remove 4 -o labels_disc_3-5.nii.gz 
# Segment the spinal cord
sct_deepseg_sc -i crop_2018_MPRAGE.nii.gz -c t1
# Register to the template (this time using two labels only)
sct_register_to_template -i crop_2018_MPRAGE.nii.gz -s crop_2018_MPRAGE_seg.nii.gz -ldisc labels_disc_3-5.nii.gz -c t1
# Copy q/sform of the MPRAGE to the lesion seg mask
sct_image -i crop_2018_MPRAGE.nii.gz -copy-header crop_2018_lesionseg.nii.gz 
# Apply transformation to the MS lesion mask (using linear to minimize loss in precision)
sct_apply_transfo -i crop_2018_lesionseg.nii.gz -w warp_anat2template.nii.gz -d $SCT_DIR/data/PAM50/template/PAM50_t1.nii.gz -x linear

Result (in the PAM50 space):
Screen Shot 2020-02-24 at 10.28.21 AM