Let lower precision float arrays pass through img_as_float#3110
Let lower precision float arrays pass through img_as_float#3110jni merged 2 commits intoscikit-image:masterfrom
img_as_float#3110Conversation
Adding small floating point numbers can cause inaccuracies. Reordered the computation to do a multiplication instead.
|
Hello @stefanv! Thanks for submitting the PR.
|
Codecov Report
@@ Coverage Diff @@
## master #3110 +/- ##
==========================================
+ Coverage 85.91% 85.93% +0.01%
==========================================
Files 336 336
Lines 27316 27336 +20
==========================================
+ Hits 23469 23490 +21
+ Misses 3847 3846 -1
Continue to review full report at Codecov.
|
| and can be outside the ranges [0.0, 1.0] or [-1.0, 1.0]. | ||
|
|
||
| """ | ||
| return convert(image, np.floating, force_copy) |
There was a problem hiding this comment.
Interesting, good call on the subclass!
| image = np.multiply(image, 2. / (imax_in - imin_in), | ||
| dtype=computation_type) | ||
| image += 1.0 / (imax_in - imin_in) | ||
| image = np.add(image, 0.5, dtype=computation_type) |
There was a problem hiding this comment.
Did this really lead to an inacurracy?
Interesting.
There was a problem hiding this comment.
Yes, it did. See the np.int8 test case that @stefanv added. It fails without this change, due to floating point arithmetic error.
|
@jni is there a chance this can be backported to 0.14.1? |
|
@meeseeksdev backport to v0.14.x |
|
@hmaarrfk apparently it can. =D |
…n-v0.14.x Backport PR #3110 on branch v0.14.x
This is an alternative approach to https://github.com/scikit-image/scikit-image/pull/3062/files
It also led me to identify a precision issue in the conversion from signed int -> float.