1

I know that Python's skimage's img_as_float function returns values between 0 and 1. However, when I run this piece of code, I can't explain why I am getting an output that does not make sense to me.

>>> img_as_float([1,2])
array([1.62630326e-19, 2.71050543e-19])

How were 1 and 2 transformed into these numbers? I thought that img_as_float outputs everything in float64 between 0 and 1, so I thought it would make sense for 1/256 and 2/256 to be the outputs.

Any help would be greatly appreciated. Currently very stuck at work because of this confusing issue.

Ethan Yim
  • 85
  • 1
  • 6
  • 1
    1/256 and 2/256 would make sense if you had passed an array of 8-bit values. I'm guessing that your values are being interpreted as 64-bit, as your results are in the vicinity of 1/2⁶⁴. – jasonharper Jun 18 '20 at 04:20
  • but 1/2⁶⁴ is equal to 5.4210109e-20 ... – Ethan Yim Jun 18 '20 at 04:23
  • That's why I said "vicinity of", rather than "exactly equal to". – jasonharper Jun 18 '20 at 04:24
  • 1
    Does this answer your question? [Array conversion using scikit-image: from integer to float](https://stackoverflow.com/questions/21429261/array-conversion-using-scikit-image-from-integer-to-float) – Max Feinberg Jun 18 '20 at 04:31
  • 2
    the extra factor of 2 is because the array is interpreted as a *signed* int, so the divisor would be `2**63-1`, not `2**64`. However, `1.62630326e-19/(1/(2^63-1))` is almost exactly 1.5, and I have NO IDEA where the 1.5 factor could come from! – Juan Jun 19 '20 at 02:13

0 Answers0