sct-pipeline / contrast-agnostic-softseg-spinalcord

Contrast-agnostic spinal cord segmentation project with softseg
MIT License
4 stars 3 forks source link

Segmentation doesn't go as high as C1 disc label #117

Closed sandrinebedard closed 2 months ago

sandrinebedard commented 2 months ago

Description

Using the contrast-agnostic model on T1w data, in 2 cases out of 267 (data-multi-subject), the segmentation did not go as high as the discs label 1 (in hte derivatives), here is an example of subject sub-stanford05 image

Here is the error generated :

--
Spinal Cord Toolbox (git-master-a866fc666681eca5e7e075b2f6174be0d670f6dd)

sct_label_vertebrae -i sub-stanford05_space-other_T1w.nii.gz -s sub-stanford05_space-other_T1w_seg.nii.gz -c t1 -discfile sub-stanford05_space-other_T1w_label-discs_dlabel.nii.gz
--

Creating temporary folder (/tmp/sct_2024-09-03_09-13-38_label-vertebrae_4sp6e_s4)

Copying input data to tmp folder...

Straighten spinal cord...
Creating temporary folder (/tmp/sct_2024-09-03_09-13-43_straighten-spinalcord_9guvk2ts)
Copy files to tmp folder...
Fitting centerline using B-spline approximation
Error on approximation = 5.63 mm
Error on approximation = 0.24 mm
Error on approximation = 0.43 mm
Error on approximation = 0.22 mm
Error on approximation = 0.06 mm
Error on approximation = 0.04 mm
Error on approximation = 0.03 mm
Error on approximation = 0.03 mm
Create the straight space and the safe zone
Length of spinal cord: 188.44254190714548
Size of spinal cord in z direction: 177.08689029594262
Ratio length/size: 1.0641247445941686
Safe zone boundaries (curved space): [-157.96712229534836, 19.119768000594263]
Safe zone boundaries (straight space): [-163.64494810094982, 24.797593806195707]
Pad input volume to account for spinal cord length...
Time to generate centerline: 29.0 ms
Image header specifies datatype 'float32', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Warping field generated: tmp.curve2straight.nii.gz
Image header specifies datatype 'float32', but array is of type 'float64'. Header metadata will be overwritten to use 'float64'.
Warping field generated: tmp.straight2curve.nii.gz
Apply transformation to input image...
/home/GRAMES.POLYMTL.CA/sebeda/spinalcordtoolbox/bin/isct_antsApplyTransforms -d 3 -i data.nii -o tmp.anat_rigid_warp.nii.gz -t tmp.curve2straight.nii.gz -r tmp.centerline_pad_crop.nii.gz -n 'BSpline[3]' # in /tmp/sct_2024-09-03_09-13-43_straighten-spinalcord_9guvk2ts
Generate output files...
mv /tmp/sct_2024-09-03_09-13-43_straighten-spinalcord_9guvk2ts/tmp.curve2straight.nii.gz ./warp_curve2straight.nii.gz
File created: ./warp_curve2straight.nii.gz
mv /tmp/sct_2024-09-03_09-13-43_straighten-spinalcord_9guvk2ts/tmp.straight2curve.nii.gz ./warp_straight2curve.nii.gz
File created: ./warp_straight2curve.nii.gz
cp /tmp/sct_2024-09-03_09-13-43_straighten-spinalcord_9guvk2ts/tmp.anat_rigid_warp.nii.gz ./straight_ref.nii.gz
File created: ./data_straight.nii
Remove temporary files...
rm -rf /tmp/sct_2024-09-03_09-13-43_straighten-spinalcord_9guvk2ts

Resample to 0.5mm isotropic...
load data...

Apply straightening to segmentation...
/home/GRAMES.POLYMTL.CA/sebeda/spinalcordtoolbox/bin/isct_antsApplyTransforms -d 3 -i segmentation.nii -o segmentation_straight.nii -t warp_curve2straight.nii.gz -r data_straightr.nii -n Linear # in /tmp/sct_2024-09-03_09-13-38_label-vertebrae_4sp6e_s4
File /tmp/sct_2024-09-03_09-13-38_label-vertebrae_4sp6e_s4/segmentation_straight.nii already exists. Will overwrite it.

Apply straightening to disc labels...

Dilate labels before warping...
Creating temporary folder (/tmp/sct_2024-09-03_09-15-18_apply-transfo-3d-label_jd6o8xxa)
/home/GRAMES.POLYMTL.CA/sebeda/spinalcordtoolbox/bin/isct_antsApplyTransforms -d 3 -i /tmp/sct_2024-09-03_09-15-18_apply-transfo-3d-label_jd6o8xxa/dilated_data.nii -o labeldisc_straight.nii.gz -t warp_curve2straight.nii.gz -r data_straightr.nii -n NearestNeighbor # in /tmp/sct_2024-09-03_09-13-38_label-vertebrae_4sp6e_s4

Take the center of mass of each registered dilated labels...
File labeldisc_straight.nii.gz already exists. Will overwrite it.
During disc labeling, center of mass calculation failed due to discontinuities in segmented spinal cord; please check the quality of your segmentation. Using interpolated centerline as a fallback.
Traceback (most recent call last):
  File "/home/GRAMES.POLYMTL.CA/sebeda/spinalcordtoolbox/spinalcordtoolbox/scripts/sct_label_vertebrae.py", line 501, in <module>
    main(sys.argv[1:])
  File "/home/GRAMES.POLYMTL.CA/sebeda/spinalcordtoolbox/spinalcordtoolbox/scripts/sct_label_vertebrae.py", line 359, in main
    label_vert('segmentation_straight.nii', 'labeldisc_straight.nii.gz')
  File "/home/GRAMES.POLYMTL.CA/sebeda/spinalcordtoolbox/spinalcordtoolbox/vertebrae/core.py", line 42, in label_vert
    label_discs(fname_seg, discs)
  File "/home/GRAMES.POLYMTL.CA/sebeda/spinalcordtoolbox/spinalcordtoolbox/vertebrae/core.py", line 514, in label_discs
    cx, cy = [int(x) for x in np.round(center_of_mass(slices)).tolist()]
  File "/home/GRAMES.POLYMTL.CA/sebeda/spinalcordtoolbox/spinalcordtoolbox/vertebrae/core.py", line 261, in center_of_mass
    raise EmptyArrayError("Center of mass can't be calculated on empty arrays.")
spinalcordtoolbox.types.EmptyArrayError: Center of mass can't be calculated on empty arrays

Removing this label solved the problem.

Maybe we should consider how we can make the segmentation go higher?

jcohenadad commented 2 months ago

Maybe we should consider how we can make the segmentation go higher?

In some situations this was indeed a problem. Making the segmentation go higher would however require quite a bit of work, I think (ie: revisit ALL our ground truth and re-train a model). What do you think @naga-karthik ?

jcohenadad commented 2 months ago

@sandrinebedard as discussed:

sandrinebedard commented 2 months ago

Closing since now openned in : https://github.com/spinalcordtoolbox/spinalcordtoolbox/issues/4627