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
Make sct_get_centerline robust to intensities with range [0, 1] #1746
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is resolved for me. I tested it on all 3 of the contrasts for which it failed in this manner, and the segmentations are now successfully generated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to fix the issue inside sct_image instead?
def apply_intensity_normalization(fname_in, fname_out): | ||
img = Image(fname_in) | ||
img_normalized = img.copy() | ||
p2, p98 = np.percentile(img.data, (2, 98)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't int16 range -32,768 to 32,767?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am sorry, I am not sure to understand: does the below comment helps? Otherwise, May I ask you to re-explain to me? Thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to fix the issue inside sct_image instead?
Maybe! But I am not sure to see how, Could you please help me? Merci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry @charleygros i meant line 71 (below), where it says: out_range=(0, 255) (equivalent 8bit unsigned), whereas later in the code the data is converted to int16, hence we loose precision. Or am i missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe skimage.img_as_uint could be useful here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be a better solution, merci!
Just one question: The documentation says:
Negative input values will be clipped.
--> Could we assume that images will always have positive values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i suggest we do, but we should check for it. If there are neg values, a "warning" should be sent.
The issue here is:
Concerning the -32,768 to 32,767:
|
@charleygros I will look into it and provide suggestions UPDATE 2018-05-18 10.20: There is already code inside msct_image.changeType() which is supposed to deal with that issue. Obviously this code is not working. So we should just fix that part, without the need to add a rescaling in |
Image with intensities between -31.689 and 31.115999:
leads to:
|
in response to this comment: can't we do a rescaling, by adjusting the in_min and in_max to the out_min and out_max, as done here? That would solve issue with neg values. |
Travis showed error of I would suggest to:
|
Let's do a comparative test as in #1757 before merging. I'll take care of that and add results in this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's wait for the comparative tests before merging
The logs and pickles are under Gdrive/NeuroPoly/Projects/SCT/testing:
As expected,
However, that should result in at least two fails less, whereas there is only one fail less compared to master, which means that this PR does break compatibility in other datasets. Investigating... UPDATE 2018-05-22 10.26: When pulling UPDATE 2018-05-22 11.10: I've re-run, making sure UPDATE 2018-05-22 11.18: When running the job in interactive mode, i confirm the running branch is UPDATE 2018-05-22 11.24: Realizing now that the modified function was under /spinalcordtoolbox (i though it was only under /scripts), meaning that SCT should have been reinstalled. Nice way to loose 2h... UPDATE 2018-05-22 14.17: After reinstalling with UPDATE 2018-05-22 17.09: Updated violin plots and (now with working installation). |
@jcohenadad: By comparing the two pickles (master and cg_i1740):
we obtain the following result:
I will investigate further this subject UPDATE 2018-05-22 10.13: I have run locally this subject on the branch UPDATE 2018-05-22 10.17: For this subject (['milan_20160628-marcella_DCD-20110907']), the different status is due to: |
* add a intensity scaling prior to int16 conversion to prevent intensity < 1 * Add refs in the header of the functions * add ref optic deepseg_sc * convert to uint16 * for intensities between 0 and 1 the data was not rescaled, we removed the "if" condition * use changeType * the if condition is crucial for binary images as input. * use skimage.img_as_uint + be robust to negative values with an intensity translation * img_as_int instead of img_as_uint * replace the skimage functions --> rescale in uint16 range then convert to uint16 Former-commit-id: dea98c9
Requirements
Output cord segmentation is empty on image with reasonable contrast #1740
Description of the Change
If all intensities of the image are < 1, then this line:
https://github.com/neuropoly/spinalcordtoolbox/blob/master/spinalcordtoolbox/centerline/optic.py#L95
leads to a binarization of the input image --> fail of OptiC
Solution: make an intensity scaling prior to the int16 conversion.
Changes tested on ~ 50 images --> seems to do not affect OptiC.
Steps and Constraints
To test the pull request, please reinstall the toolbox because the changes are made in spinalcordtoolbox/optic