Sct_deepseg_sc and sct_propseg create a different coordinate origins

Sometimes, the sct_deepseg_sc gives better results when creating the spinal cord mask in comparison to the sct_propseg.

However, only the sct_propseg can produce a CBF mask.

In my dataset, I discovered that the coordinate origin is slightly different for the sct_deepseg_sc spinal cord mask in comparison with the sct_propseg’s CBF mask.

The difference is tiny (negligible), but the correction is required:

c3d MR_frame_0001_CSF_seg.nii.gz deepseg/MR_frame_0001_seg.nii.gz -copy-transform -o deepseg/MR_frame_0001_seg_transformed.nii.gz

I would like to check what is the best way to produce both masks together in terms of the accuracy of the resulting masks?

Hi @gianni,

Thank you for taking the time to describe your issue, and for providing the c3d command that you used. I’m going to take a look at this issue now. :slight_smile:

Just to check, though: Are you able to share the data files you’re working with, so that I can try to reproduce the results you noticed?

As well, could you please share the exact sct_propseg and sct_deepseg_sc commands that you used?

Kind regards,
Joshua

As an illustration, here are the key commands that I used.

dicom2itk -i .

Some other data image series may require “dicom2itk --fix_gantry -i .”

mkdir -p propseg deepseg

sct_deepseg_sc -i MR_frame_0001.nii.gz -c t2 -ofolder deepseg

sct_propseg -i MR_frame_0001.nii.gz -c t2 -CSF -o segmentation_mask_spine_init_with_centerline.nii.gz -init-centerline deepseg/MR_frame_0001_seg.nii.gz

Repair

c3d MR_frame_0001_CSF_seg.nii.gz deepseg/MR_frame_0001_seg.nii.gz -copy-transform -o deepseg/MR_frame_0001_seg_transformed.nii.gz

Check to see if the repair is working

c3d MR_frame_0001_CSF_seg.nii.gz deepseg/MR_frame_0001_seg_transformed.nii.gz -add -o spinal_cord_fusion_mask.nii.gz

Change the pixel data type to match other program’s standard.

c3d segmentation_mask_spine_init_with_centerline.nii.gz -type uchar -o segmentation_mask_spine_init_with_centerline_uchar.nii.gz

Hi @gianni,

I’ve tried out the commands you’ve provided, but I am unable to reproduce the issue with my own testing data. Specifically, for this command:

I cannot see any difference in “spinal_cord_fusion_mask.nii.gz”, regardless of whether the fixed segmentation or the original segmentation is used.

So, just to make sure I’m understanding correctly:

When you say “the coordinate origin is slightly different”, could you please give a specific example of what kind of difference you’re seeing?

For example, do you some kind of numerical comparison between the image headers of both the propseg CSF image and the deepseg segmentation image? Or, alternatively, do you have some kind of error message from c3d?

Even better, providing the data files themselves would be very beneficial for reproducing the issue, if you could. :slight_smile:

Thank you kindly,
Joshua

I suspect this issue is caused by a mismatch between the qform and sform in the images, and the fact that c3d is ITK-based (and hence relies on the qform). See notably https://github.com/spinalcordtoolbox/spinalcordtoolbox/issues/3283

As a starting point, @gianni maybe you could show us the output of:

sct_image -i MR_frame_0001_CSF.nii.gz -header
sct_image -i MR_frame_0001_CSF_seg.nii.gz -header
sct_image -i deepseg/MR_frame_0001_seg.nii.gz -header
1 Like

Sorry for the delay in replying. I am printing the headers for all the produced files.

sct_image -i MR_frame_0001_CSF_seg.nii.gz -header

sizeof_hdr      348
data_type       UINT8
dim             [3, 266, 709, 56, 1, 1, 1, 1]
vox_units       mm
time_units      Unknown
datatype        2
nbyper          1
bitpix          8
pixdim          [1.0, 0.976562, 0.976562, 1.0, 0.0, 0.0, 0.0, 0.0]
vox_offset      352
cal_max         0.000000
cal_min         0.000000
scl_slope       1.000000
scl_inter       0.000000
phase_dim       0
freq_dim        0
slice_dim       0
slice_name      Unknown
slice_code      0
slice_start     0
slice_end       0
slice_duration  0.000000
toffset         0.000000
intent          Unknown
intent_code     0
intent_name
intent_p1       0.000000
intent_p2       0.000000
intent_p3       0.000000
qform_name      Aligned Anat
qform_code      2
qto_xyz:1       0.000000 0.000000 1.000000 -26.064796
qto_xyz:2       -0.976562 0.000000 0.000000 105.070923
qto_xyz:3       0.000000 -0.976562 0.000000 -38.056087
qto_xyz:4       0.000000 0.000000 0.000000 1.000000
qform_xorient   Anterior-to-Posterior
qform_yorient   Superior-to-Inferior
qform_zorient   Left-to-Right
sform_name      Scanner Anat
sform_code      1
sto_xyz:1       0.000000 0.000000 1.000000 -26.064796
sto_xyz:2       -0.976562 0.000000 0.000000 105.070923
sto_xyz:3       0.000000 -0.976562 0.000000 -38.056087
sto_xyz:4       0.000000 0.000000 0.000000 1.000000
sform_xorient   Anterior-to-Posterior
sform_yorient   Superior-to-Inferior
sform_zorient   Left-to-Right
file_type       NIFTI-1+
file_code       1
descrip
aux_file



sct_image -i MR_frame_0001_centerline.nii.gz -header

sizeof_hdr      348
data_type       INT8
dim             [3, 266, 709, 56, 1, 1, 1, 1]
vox_units       mm
time_units      Unknown
datatype        256
nbyper          1
bitpix          8
pixdim          [1.0, 0.976562, 0.976562, 1.0, 1.0, 1.0, 1.0, 1.0]
vox_offset      352
cal_max         0.000000
cal_min         0.000000
scl_slope       1.000000
scl_inter       0.000000
phase_dim       0
freq_dim        0
slice_dim       0
slice_name      Unknown
slice_code      0
slice_start     0
slice_end       0
slice_duration  0.000000
toffset         0.000000
intent          Unknown
intent_code     0
intent_name
intent_p1       0.000000
intent_p2       0.000000
intent_p3       0.000000
qform_name      Aligned Anat
qform_code      2
qto_xyz:1       0.000000 0.000000 1.000000 -26.064796
qto_xyz:2       -0.976562 0.000000 0.000000 105.070923
qto_xyz:3       0.000000 -0.976562 0.000000 -38.056087
qto_xyz:4       0.000000 0.000000 0.000000 1.000000
qform_xorient   Anterior-to-Posterior
qform_yorient   Superior-to-Inferior
qform_zorient   Left-to-Right
sform_name      Scanner Anat
sform_code      1
sto_xyz:1       -0.000000 0.000000 1.000000 -26.064796
sto_xyz:2       -0.976562 -0.000000 -0.000000 105.070923
sto_xyz:3       0.000000 -0.976562 0.000000 -38.056087
sto_xyz:4       0.000000 0.000000 0.000000 1.000000
sform_xorient   Anterior-to-Posterior
sform_yorient   Superior-to-Inferior
sform_zorient   Left-to-Right
file_type       NIFTI-1+
file_code       1
descrip
aux_file



sct_image -i MR_frame_0001_seg.nii.gz -header

sizeof_hdr      348
data_type       INT8
dim             [3, 266, 709, 56, 1, 1, 1, 1]
vox_units       mm
time_units      Unknown
datatype        256
nbyper          1
bitpix          8
pixdim          [1.0, 0.976562, 0.976562, 1.0, 1.0, 1.0, 1.0, 1.0]
vox_offset      352
cal_max         0.000000
cal_min         0.000000
scl_slope       1.000000
scl_inter       0.000000
phase_dim       0
freq_dim        0
slice_dim       0
slice_name      Unknown
slice_code      0
slice_start     0
slice_end       0
slice_duration  0.000000
toffset         0.000000
intent          Unknown
intent_code     0
intent_name
intent_p1       0.000000
intent_p2       0.000000
intent_p3       0.000000
qform_name      Aligned Anat
qform_code      2
qto_xyz:1       0.000000 0.000000 1.000000 -26.064796
qto_xyz:2       -0.976562 0.000000 0.000000 105.070923
qto_xyz:3       0.000000 -0.976562 0.000000 -38.056087
qto_xyz:4       0.000000 0.000000 0.000000 1.000000
qform_xorient   Anterior-to-Posterior
qform_yorient   Superior-to-Inferior
qform_zorient   Left-to-Right
sform_name      Scanner Anat
sform_code      1
sto_xyz:1       -0.000000 0.000000 1.000000 -26.064796
sto_xyz:2       -0.976562 -0.000000 -0.000000 105.070923
sto_xyz:3       0.000000 -0.976562 0.000000 -38.056087
sto_xyz:4       0.000000 0.000000 0.000000 1.000000
sform_xorient   Anterior-to-Posterior
sform_yorient   Superior-to-Inferior
sform_zorient   Left-to-Right
file_type       NIFTI-1+
file_code       1
descrip
aux_file



sct_image -i segmentation_mask_spine_init_with_centerline.nii.gz -header

sizeof_hdr      348
data_type       INT8
dim             [3, 266, 709, 56, 1, 1, 1, 1]
vox_units       mm
time_units      Unknown
datatype        256
nbyper          1
bitpix          8
pixdim          [1.0, 0.976562, 0.976562, 1.0, 1.0, 1.0, 1.0, 1.0]
vox_offset      352
cal_max         0.000000
cal_min         0.000000
scl_slope       1.000000
scl_inter       0.000000
phase_dim       0
freq_dim        0
slice_dim       0
slice_name      Unknown
slice_code      0
slice_start     0
slice_end       0
slice_duration  0.000000
toffset         0.000000
intent          Unknown
intent_code     0
intent_name
intent_p1       0.000000
intent_p2       0.000000
intent_p3       0.000000
qform_name      Aligned Anat
qform_code      2
qto_xyz:1       0.000000 0.000000 1.000000 -26.064796
qto_xyz:2       -0.976562 0.000000 0.000000 105.070923
qto_xyz:3       0.000000 -0.976562 0.000000 -38.056087
qto_xyz:4       0.000000 0.000000 0.000000 1.000000
qform_xorient   Anterior-to-Posterior
qform_yorient   Superior-to-Inferior
qform_zorient   Left-to-Right
sform_name      Scanner Anat
sform_code      1
sto_xyz:1       -0.000000 0.000000 1.000000 -26.064796
sto_xyz:2       -0.976562 -0.000000 -0.000000 105.070923
sto_xyz:3       0.000000 -0.976562 0.000000 -38.056087
sto_xyz:4       0.000000 0.000000 0.000000 1.000000
sform_xorient   Anterior-to-Posterior
sform_yorient   Superior-to-Inferior
sform_zorient   Left-to-Right
file_type       NIFTI-1+
file_code       1
descrip
aux_file



sct_image -i deepseg/MR_frame_0001_seg.nii.gz -header

sizeof_hdr      348
data_type       UINT8
dim             [3, 266, 709, 56, 1, 1, 1, 1]
vox_units       Unknown
time_units      Unknown
datatype        2
nbyper          1
bitpix          8
pixdim          [1.0, 0.976562, 0.976562, 1.0, 1.0, 1.0, 1.0, 1.0]
vox_offset      352
cal_max         0.000000
cal_min         0.000000
scl_slope       1.000000
scl_inter       0.000000
phase_dim       0
freq_dim        0
slice_dim       0
slice_name      Unknown
slice_code      0
slice_start     0
slice_end       0
slice_duration  0.000000
toffset         0.000000
intent          Unknown
intent_code     0
intent_name
intent_p1       0.000000
intent_p2       0.000000
intent_p3       0.000000
qform_name      Aligned Anat
qform_code      2
qto_xyz:1       0.000000 0.000000 1.000000 -26.064796
qto_xyz:2       -0.976562 0.000000 0.000000 105.070923
qto_xyz:3       0.000000 -0.976562 0.000000 -38.056091
qto_xyz:4       0.000000 0.000000 0.000000 1.000000
qform_xorient   Anterior-to-Posterior
qform_yorient   Superior-to-Inferior
qform_zorient   Left-to-Right
sform_name      Aligned Anat
sform_code      2
sto_xyz:1       0.000000 0.000000 1.000000 -26.064796
sto_xyz:2       -0.976562 -0.000000 0.000000 105.070923
sto_xyz:3       0.000000 -0.976562 0.000000 -38.056091
sto_xyz:4       0.000000 0.000000 0.000000 1.000000
sform_xorient   Anterior-to-Posterior
sform_yorient   Superior-to-Inferior
sform_zorient   Left-to-Right
file_type       NIFTI-1+
file_code       1
descrip
aux_file

@jcohenadad I think that you are right. The c3d program is slightly outdated. When I downloaded the latest nightly c3d build, it fused the two masks without any errors. I can’t believe it! :slight_smile: Thank you very much.

2 Likes