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

Fix deepseg threshold (again) #2490

Merged
merged 3 commits into from
Oct 21, 2019
Merged

Fix deepseg threshold (again) #2490

merged 3 commits into from
Oct 21, 2019

Conversation

jcohenadad
Copy link
Member

@jcohenadad jcohenadad commented Oct 15, 2019

The recently-merged PR (#2479), which consisted in finding the optimal threshold per contrast, by minimizing the STD of CSA across contrasts, was implemented with a flaw: the binarization after resampling was not done properly. This PR fixes it, and updated the optimal threshold per contrast using this repository (commit a482d205120d76893c4f21c76e4535cc45bbce11).

Fixes #2488

@@ -548,7 +548,7 @@ def deep_segmentation_spinalcord(im_image, contrast_type, ctr_algo='cnn', ctr_fi
# Binarize the resampled image (except for soft segmentation, defined by threshold_seg=-1)
if threshold_seg >= 0:
logger.info("Binarizing the resampled segmentation...")
im_seg_r.data = im_seg_r.data.astype(np.uint8)
im_seg_r.data = (im_seg_r.data > 0.5).astype(np.uint8)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to change my mind but: was thinking of setting 0 instead of 0.5 so that "no voxel are threshold" during this step and everything is controlled by the "optimised threshold" just after the prediction (ie "everything is controlled by only one threshold"). Does that make sense? or it does not really matter?

Copy link
Member Author

@jcohenadad jcohenadad Oct 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, to have a proper (i.e. unbiased) thresholding, after resampling, it should be set to 0.5 (equivalent to nearest neighbor). Setting to 0 will introduce a bias in the partial volume cutoff.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right! Thanks for clarifying, makes sense!

@jcohenadad
Copy link
Member Author

jcohenadad commented Oct 19, 2019

And here are the results of the optimal threshold calculation (commit 845ee14d1b8fc8911585d44bbf9f9e972df98229):

contrasts = ['T1', 'T2', 'T2s', 'MTon', 'T1w', 'DWI']
Cumulative average optimal threshold: [0.15862069 0.70732759 0.89181034 0.61206897 0.14827586 0.01336207]

For comparison, here are optimization results from the previous PR:

['T1', 'T2', 'T2s', 'MTon', 'T1w', 'DWI']
[0.74353448 0.34353448 0.89008621 0.33060345 0.1125     0.01422414]

So, our current results make much more sense, because the T1 and T1w are now very close 👍

@charleygros
Copy link
Member

Make much more sense! 👍

@jcohenadad jcohenadad added this to the 4.1.0 milestone Oct 21, 2019
@jcohenadad jcohenadad added enhancement category: improves performance/results of an existing feature sct_deepseg_sc context: labels Oct 21, 2019
@jcohenadad
Copy link
Member Author

jcohenadad commented Oct 21, 2019

jca/2488-deepseg-thr (cb0b3cb)

t2/CSA:          73.87711295363036
mt/MTR(WM):      54.36934620641078
t2s/CSA_GM:      12.487834828856178
t2s/CSA_WM:      64.93830702088246
dmri/FA(CST_r):  0.7947085328716705
dmri/FA(CST_l):  0.7725978925271186

master (d1cdb30)

t2/CSA:          61.45526028879409
mt/MTR(WM):      54.244983073194035
t2s/CSA_GM:      12.487834828856178
t2s/CSA_WM:      64.93830702088246
dmri/FA(CST_r):  0.7942638038275048
dmri/FA(CST_l):  0.7732157398720358

@jcohenadad jcohenadad merged commit d5d903a into master Oct 21, 2019
@jcohenadad jcohenadad deleted the jca/2488-deepseg-thr branch October 21, 2019 18:37
jcohenadad added a commit that referenced this pull request Oct 23, 2019
jcohenadad added a commit that referenced this pull request Dec 18, 2019
* deepseg_sc/core: Fixed binarization after resampling

* batch_processing.sh: Now outputtting T1 seg in QC

* deepseg_sc/core: Updated optimal thresholds


Former-commit-id: 1b2501b61b54e73c92ecfc0251c48e3a2f8926c5 [formerly fc6b564 [formerly d5d903a]]
Former-commit-id: e5b619f3e07a431d75fb63e99de53e695686e086
Former-commit-id: ffcc4b2
jcohenadad added a commit that referenced this pull request Dec 18, 2019
* deepseg_sc/core: Fixed binarization after resampling

* batch_processing.sh: Now outputtting T1 seg in QC

* deepseg_sc/core: Updated optimal thresholds


Former-commit-id: d5d903a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement category: improves performance/results of an existing feature sct_deepseg_sc context:
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adjust deepseg_sc (again)
3 participants