I am facing some kind of problem when converting an integer image to a float image using scikit-image.
This is an example (the image is a 2 pixel image):
from numpy import array,uint8;
import skimage;
rgb = array([array([[0,0,0],[0,0,5]])])
i1 = skimage.img_as_float(rgb)#rgb.dtype ->dtype('int32')
i2 = skimage.img_as_float(rgb.astype(uint8))
i3 = skimage.img_as_float(rgb.astype(float))
print i1[0,1,:]
print i2[0,1,:]
print i3[0,1,:]
I expected this:
[ 0. 0. 5.]
[ 0. 0. 5.]
[ 0. 0. 5.]
But I got this:
[ 2.32830644e-10 2.32830644e-10 2.56113708e-09]
[ 0. 0. 0.01960784]
[ 0. 0. 5.]
It is normal to loss precision from float
to int
, but here I am losing the real information when passing from int
to float
using img_as_float
. I didn't found anything when reading the code on GitHub...
Why is this possible?