-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Update rescale_intensity to prevent under/overflow and produce proper output dtype #4585
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
Conversation
except TypeError: # uint10, uint12, uint14 | ||
# otherwise, return uint16 | ||
return np.uint16 | ||
|
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.
add an else here to raise a TypeError
for example in the case of typos (flat
instead of float
). With the current version, output_dtype
will be None if none of the ifs is True, and np.array([1, 2, 3], dtype=None)
does not error...
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 understand and support the first part of your suggestion.
But why should output_dtype
be None
. The way I understand the new behavior is
out_range
is an actual range -> output dtype isfloat64
out_range
is already a dtype (corresponding to the input dtype) -> use same type for output
None
would just result in the returned output being of dtype float64
wouldn't it?
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.
@lagru probably what I wrote was not clear, please tell me if it's clearer now. The function should never return None, it should return a valid value or error out.
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.
Ah, then we are in agreement. 👍
One possibility we did not consider would be to accept for |
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.
Thanks for the work! Only some nitpicks, feel free to ignore. All in all I find this function quite hard to fully grasp.
@emmanuelle @lagru Thank you for the reviews! I've addressed all of your comments.
I don't like that solution very much, it seems clunky and it will complicate the code quite a lot. I would consider adding At any rate, I think we can discuss this separately and address it in a separate PR, since this is already a big improvement on existing behaviour. None of the above proposals would allow existing code to continue working when the output dtype was incorrectly being inferred from the input dtype (as in my fix for |
Co-Authored-By: Lars Grüter <lagru@users.noreply.github.com>
Thanks for keeping me honest, @lagru! 😂 |
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.
@jni You're welcome. 😉 Nice work!
Thanks for the fix! After this is merged I'd raise another issue (I think independent of this one) on this function with a proposed fix. Cheers |
@m-albert why do you need to wait until this is merged? |
@scikit-image/core I've addressed the concerns about changed behaviours by adding more explicit notes in the release notes, as well as |
Thank you @jni, merging! |
Description
Fixes #4583
out_range
is a dtype, then the output will be in that dtype (currently it is the input dtype, which is insane).out_range
is a range of numbers, the output will be of type float and the caller will be responsible for converting to the correct dtype. This is a breaking change in some circumstances. See our use ofrescale_intensity
withinequalize_adapthist
which I had to fix.Checklist
Gallery example in./doc/examples
(new features only)Benchmark in./benchmarks
, if your changes aren't covered by anexisting benchmark
For reviewers
later.
__init__.py
.doc/release/release_dev.rst
.