Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyze midsagittal lesion length and width #96

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

valosekj
Copy link
Member

@valosekj valosekj commented Sep 20, 2024

This PR adds a codebase to compare the midsagittal lesion length and width (recently added in spinalcordtoolbox/spinalcordtoolbox#4617) computed using different methods:

  • manually measured metrics
  • metrics computed using sct_analyze_lesion from GT masks (located under derivatives/labels)
  • metrics computed using sct_analyze_lesion from the lesion and SC masks obtained using SCIsegV2
  • metrics computed using sct_analyze_lesion from the lesion obtained using SCIsegV2 and SC obtained using the contrast-agnostic model

Note: The contrast-agnostic model is tried to see how it performs compared to the SCIsegV2 model. Comments below show some screenshots of SC seg obtained using the contrast-agnostic model.

At the same time, this PR aims to investigate an alternative method for getting the midsagittal slice (proposed in spinalcordtoolbox/spinalcordtoolbox#4631).

For details, visit this README.

@valosekj
Copy link
Member Author

valosekj commented Sep 20, 2024

RESULTS FROM contrast-agnostic model (version: 2.4)

Adding -largest 1 for sct_deepseg in 8d9b7b9 as the contrast agnostic model segments areas outside of the cord for some subjects (especially lumbar cord with metal implants):

image

@valosekj
Copy link
Member Author

valosekj commented Sep 20, 2024

RESULTS FROM contrast-agnostic model (version: 2.4)

When calling sct_analyze_lesion on the spinal cord obtained by the contrast-agnostic model v2.4 and lesion segmentation obtained by SCIsegV2:

# Compute the midsagittal lesion length and width based on the spinal cord obtained using the contrast-agnostic model v2.4 and lesion segmentation obtained using SCIsegV2
sct_analyze_lesion -m ${file_t2}_lesion_seg.nii.gz -s ${file_t2}_sc_seg_contrast-agnostic.nii.gz -qc ${PATH_QC} -qc-subject ${SUBJECT}

image

sct_analyze_lesion fails because SC seg might not cover the lesion:

full error output
+ sct_analyze_lesion -m sub-zh04_ses-02_acq-sag_T2w_lesion_seg.nii.gz -s sub-zh04_ses-02_acq-sag_T2w_sc_seg_contrast-agnostic.nii.gz -qc /home/GRAMES.POLYMTL.CA/p118175/results/sci-zurich_midsagittal_measures_2024-09-20/qc -qc-subject sub-zh04/ses-02

--
Spinal Cord Toolbox (git-master-197ef3494a1c73d8b8acb14fcd809f31e16b5265)

sct_analyze_lesion -m sub-zh04_ses-02_acq-sag_T2w_lesion_seg.nii.gz -s sub-zh04_ses-02_acq-sag_T2w_sc_seg_contrast-agnostic.nii.gz -qc /home/GRAMES.POLYMTL.CA/p118175/results/sci-zurich_midsagittal_measures_2024-09-20/qc -qc-subject sub-zh04/ses-02
--

Creating temporary folder (/tmp/sct_2024-09-20_12-02-42_analyze-lesion_fwwtdhau)
cp sub-zh04_ses-02_acq-sag_T2w_lesion_seg.nii.gz /tmp/sct_2024-09-20_12-02-42_analyze-lesion_fwwtdhau
cp sub-zh04_ses-02_acq-sag_T2w_sc_seg_contrast-agnostic.nii.gz /tmp/sct_2024-09-20_12-02-42_analyze-lesion_fwwtdhau

Orient input image(s) to RPI orientation...
^[[33mFile sub-zh04_ses-02_acq-sag_T2w_lesion_seg.nii.gz already exists. Will overwrite it.^[[0m
^[[33mFile sub-zh04_ses-02_acq-sag_T2w_sc_seg_contrast-agnostic.nii.gz already exists. Will overwrite it.^[[0m

Label connected regions of the masked image...
^[[33mImage header specifies datatype 'uint8', but array is of type 'int64'. Header metadata will be overwritten to use 'int64'.^[[0m
/home/GRAMES.POLYMTL.CA/p118175/code/spinalcordtoolbox/spinalcordtoolbox/scripts/sct_analyze_lesion.py:394: RuntimeWarning: divide by zero encountered in scalar divide
  axial_damage_ratio_dict[slice] = lesion_area / sc_area
Lesion count = 1
Midsagittal slice of the spinal cord: 10

Measures on lesion #1...
  (S-I) length: 11926.41 mm
  Max. equivalent diameter: 0.41 mm
  Maximum axial damage ratio: inf
  (S-I) length in the midsagittal slice: 8719.91 mm
  (A-P) width in the midsagittal slice: 0.01 mm
  Volume: 727.35 mm^3

Orient output image to initial orientation...
^[[33mFile sub-zh04_ses-02_acq-sag_T2w_lesion_seg_label.nii.gz already exists. Will overwrite it.^[[0m


Averaged measures across all lesions...
  volume [mm3] = 727.35 +/- 0.0
  length [mm] = 11926.41 +/- 0.0
  max_equivalent_diameter [mm] = 0.41 +/- 0.0
  max_axial_damage_ratio [] = inf +/- nan

Minimum tissue bridges across all lesions for the midsagittal slice (sagittal slice 10)...
WARNING: Lesion #1 does not exist in the midsagittal slice
  Minimum dorsal bridge width [mm]: nan
  Minimum ventral bridge width [mm]: nan

Total volume = 727.35 mm^3
Lesion count = 1

Save results files...

... measures saved in the files:

  - ./sub-zh04_ses-02_acq-sag_T2w_lesion_seg_label.nii.gz
cp /tmp/sct_2024-09-20_12-02-42_analyze-lesion_fwwtdhau/sub-zh04_ses-02_acq-sag_T2w_lesion_seg_label.nii.gz ./sub-zh04_ses-02_acq-sag_T2w_lesion_seg_label.nii.gz

  - ./sub-zh04_ses-02_acq-sag_T2w_lesion_seg_analysis.xls
cp /tmp/sct_2024-09-20_12-02-42_analyze-lesion_fwwtdhau/sub-zh04_ses-02_acq-sag_T2w_lesion_seg_analysis.xls ./sub-zh04_ses-02_acq-sag_T2w_lesion_seg_analysis.xls

  - ./sub-zh04_ses-02_acq-sag_T2w_lesion_seg_analysis.pkl
cp /tmp/sct_2024-09-20_12-02-42_analyze-lesion_fwwtdhau/sub-zh04_ses-02_acq-sag_T2w_lesion_seg_analysis.pkl ./sub-zh04_ses-02_acq-sag_T2w_lesion_seg_analysis.pkl

*** Generating Quality Control (QC) html report ***
Traceback (most recent call last):
  File "/home/GRAMES.POLYMTL.CA/p118175/code/spinalcordtoolbox/spinalcordtoolbox/scripts/sct_analyze_lesion.py", line 1085, in <module>
    main(sys.argv[1:])
  File "/home/GRAMES.POLYMTL.CA/p118175/code/spinalcordtoolbox/spinalcordtoolbox/scripts/sct_analyze_lesion.py", line 1048, in main
    sct_analyze_lesion(
  File "/home/GRAMES.POLYMTL.CA/p118175/code/spinalcordtoolbox/spinalcordtoolbox/reports/qc2.py", line 580, in sct_analyze_lesion
    axes[idx_row, idx_col].set_xlim(np.min(np.where(im_label_data_cur)[1]) - 20,
  File "/home/GRAMES.POLYMTL.CA/p118175/code/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 2953, in min
    return _wrapreduction(a, np.minimum, 'min', axis, None, out,
  File "/home/GRAMES.POLYMTL.CA/p118175/code/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 88, in _wrapreduction
    return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
ValueError: zero-size array to reduction operation minimum which has no identity

The issue comes from L542 in reports/qc2.py, which restricts the lesion mask to the spinal cord mask. This effectively zeros the lesion as it is not covered by the cord seg.

@valosekj
Copy link
Member Author

valosekj commented Oct 2, 2024

As the C-A model does not perform well on lumbar images with metal artifacts, I dropped it in 3a88281. The further analysis will continue with the SCIsegV2 model only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant