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?
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?
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
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:
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