ivadomed / model_seg_sci

Deep-learning based segmentation of the spinal cord and intramedually lesions in traumatic and non-traumatic SCI
MIT License
12 stars 2 forks source link

` generate_new_lesion.py` - lesion volume can be zero after resampling #39

Closed valosekj closed 1 year ago

valosekj commented 1 year ago

In the current version of generate_new_lesion.py, the lesion volume can be zero after resampling.

See the last 4 lines of the following terminal output:

Healthy subject: sub-geneva03_080, Patho subject: sub-zh13_ses-01_013
Healthy subject /Users/valosek/data/data.neuro.polymtl.ca/data-multi-subject-nnunet/Dataset526_SpineGenericMultiSubject/imagesTr/sub-geneva03_080_0000.nii.gz: LPI, (64, 320, 320), (0.8, 0.8, 0.8)
Reoriented to RPI
Pathological subject /Users/valosek/data/data.neuro.polymtl.ca/sci-zurich-nnunet/Dataset525_tSCILesionsZurichDummy/imagesTr/sub-zh13_ses-01_013_0000.nii.gz: AIL, (512, 512, 19), (0.625, 0.625, 3.3000002)
Reoriented to RPI
Voxel size = 1.2890625
Number of non-zero voxels = 2258
Volume of non-zero voxels = 2910.70 mm^3
Lesion/SC intensity difference (higher value means that the lesion is more hyperintense): 0.26508099493863346
Intensity ratio: 4.509520527230534
Trying to insert lesion at (30, 156, 166)
Voxel size = 0.5119990706443787
Number of non-zero voxels = 19
Volume of non-zero voxels = 9.73 mm^3
Trying to insert lesion at (31, 157, 187)
Voxel size = 0.5119990706443787
Number of non-zero voxels = 19
Volume of non-zero voxels = 9.73 mm^3
Trying to insert lesion at (29, 146, 110)
Voxel size = 0.5119990706443787
Number of non-zero voxels = 632
Volume of non-zero voxels = 323.58 mm^3
Lesion inserted at (29, 146, 110)
Resampling new_target and new_lesion to the spacing of pathology subject (/Users/valosek/data/data.neuro.polymtl.ca/sci-zurich-nnunet/Dataset525_tSCILesionsZurichDummy/imagesTr/sub-zh13_ses-01_013_0000.nii.gz).
Before resampling: (64, 320, 320), (0.7999985, 0.8, 0.8)
Lesion volume before resampling: 323.5834126472473 mm3
After resampling: (16, 410, 410), (3.199994, 0.62439024, 0.62439024)
Lesion volume before resampling: 0.0 mm3

Related TODOs:

https://github.com/ivadomed/model_seg_sci/blob/acaed534a6b11b0b2f1319ca6c3942027f6a748b/generate_new_lesions/generate_new_lesion.py#L269-L270

https://github.com/ivadomed/model_seg_sci/blob/acaed534a6b11b0b2f1319ca6c3942027f6a748b/generate_new_lesions/generate_new_lesion.py#L289

https://github.com/ivadomed/model_seg_sci/blob/acaed534a6b11b0b2f1319ca6c3942027f6a748b/generate_new_lesions/generate_new_lesion.py#L315

The command I use:

python generate_new_lesion.py
-dir-pathology
~/data/data.neuro.polymtl.ca/sci-zurich-nnunet/Dataset525_tSCILesionsZurichDummy/imagesTr
-dir-lesions
~/data/data.neuro.polymtl.ca/sci-zurich-nnunet/Dataset525_tSCILesionsZurichDummy/labelsTr
-dir-masks-pathology
~/data/data.neuro.polymtl.ca/sci-zurich-nnunet/Dataset525_tSCILesionsZurichDummy/masksTr
-dir-healthy
~/data/data.neuro.polymtl.ca/data-multi-subject-nnunet/Dataset526_SpineGenericMultiSubject/imagesTr/
-dir-masks-healthy
~/data/data.neuro.polymtl.ca/data-multi-subject-nnunet/Dataset526_SpineGenericMultiSubject/masksTr
-dir-save
~/data/data.neuro.polymtl.ca/data-multi-subject-nnunet/Dataset526_SpineGenericMultiSubject/labelsTr
-num
267
-seed
99
-resample
-qc

The following commands were used to generate the datasets (see scripts in dataset-conversion):

python convert_bids_to_nnUNetv2.py --path-data ~/extrassd1/janvalosek/data/sci-zurich --path-out ~/extrassd1/janvalosek/data/sci-zurich-nnunet --dataset-name tSCILesionsZurichDummy --dataset-number 525 --split 0.6 0.2 0.2 --seed 99 --include-masks_folders --create-dummy-dataset

python convert_bids_to_nnUNetv2_spine-generic.py --path-data ~/extrassd1/janvalosek/data/data-multi-subject --path-out ~/extrassd1/janvalosek/data/data-multi-subject-nnunet --dataset-name SpineGenericMutliSubject --dataset-number 526 --seed 99

Note: path to the QC is now hardcoded (which is not ideal):

https://github.com/ivadomed/model_seg_sci/blob/b8382f87c1264391570097bb22dc9f52093dc7c3/generate_new_lesions/generate_new_lesion.py#L347

naga-karthik commented 1 year ago

With the latest version of the augmentation script, this is no longer the case mainly because the resampling is now done at the beginning.

However, these commands copied from above are still useful when debugging.

python convert_bids_to_nnUNetv2.py --path-data ~/extrassd1/janvalosek/data/sci-zurich --path-out ~/extrassd1/janvalosek/data/sci-zurich-nnunet --dataset-name tSCILesionsZurichDummy --dataset-number 525 --split 0.6 0.2 0.2 --seed 99 --include-masks_folders --create-dummy-dataset

python convert_bids_to_nnUNetv2_spine-generic.py --path-data ~/extrassd1/janvalosek/data/data-multi-subject --path-out ~/extrassd1/janvalosek/data/data-multi-subject-nnunet --dataset-name SpineGenericMutliSubject --dataset-number 526 --seed 99

Closing this issue now.