Error with sct_analyze_lesion

Hi! I am trying get lesion metrics using sct_analyze_lesion. Lesions were successfully segmented from the t2 scan, but once I try to get metrics, it says there is an error. I ran the command as follows: sct_analyze_lesion -m MS_t2_lesion_seg.nii.gz -s MS_t2_seg.nii.gz -qc ~/qc_MS

Below is the terminal output:

Label connected regions of the masked image…
Lesion count = 5
Traceback (most recent call last):
File “/Users/me/sct_7.3/spinalcordtoolbox/scripts/sct_analyze_lesion.py”, line 1502, in
main(sys.argv[1:])
File “/Users/me/sct_7.3/spinalcordtoolbox/scripts/sct_analyze_lesion.py”, line 1460, in main
lesion_obj.analyze()
File “/Users/me/sct_7.3/spinalcordtoolbox/scripts/sct_analyze_lesion.py”, line 223, in analyze
self.measure()
File “/Users/me/sct_7.3/spinalcordtoolbox/scripts/sct_analyze_lesion.py”, line 976, in measure
assert len(label_lst) == self.lesion_count, “Lesion count has drifted (internal code issue, please report to SCT)”
AssertionError: Lesion count has drifted (internal code issue, please report to SCT)

Any help is greatly appreciated! Thank you :slight_smile:

Hi @hmac!
Thanks for reporting this issue. I might have a clue about what the culprit is (some lesion(s) might be outside of the spinal cord; please see this GitHub issue).
Would it be possible to share the spinal cord and lesion mask files here (MS_t2_lesion_seg.nii.gz, MS_t2_seg.nii.gz; no need to share the image itself) so I can debug the issue myself?
Thanks!
Jan

Hi Jan,

Ah I see. Yes I can see a detected lesion that is outside the segmented spinal cord. Can I run the command without the -s? I know that means it won’t be able to provide all the metrics.

I’ve attached the files. Thanks for your reply!

Thanks for providing the segmentation masks! I can confirm that one lesion is outside the cord (on the cord edge).

There are multiple options:

  1. Keep all the lesions and run sct_analyze_lesion without -s. However, you will not get all the lesion metrics, as you correctly pointed out.
  2. Check the lesion visually; if it’s a false positive, you can remove the lesion that is outside of the cord, e.g., using sct_maths -i " + $file_lesion + " -mul " + $file_sc + " -o " + $file_lesion.
  3. Check the lesion visually, and if you are sure that the lesion is correct, manually extend the lesion mask in an image viewer (e.g., FSLeyes, ITKsnap, 3D Slicer, etc.) to cover the lesion.

Hope this helps.

Jan

(post deleted by author)

Hi Jan,

Thank you! Option 2 got rid of it so I can run the command like normal for the other lesions.

I greatly appreciate your help :slight_smile:

1 Like