Q:

Using 32-bit Lab images in Tensorflow

I'm using skimage to convert RGB images to Lab colorspace but it seems that skimage uses float64 datatype while Tensorflow uses float32.  
Is there any way to convert the 64-bit Lab image to 32-bit datatype?  The documentation doesn't cover anything specific about this and I'm not sure if using image.astype(np.float32) is the way to go since it might damage the data precision (or not). 
Here's a part of the code:
from skimage import color, io
import numpy as np    

rgb = io.imread('Test.jpg') # Could be any shape
lab = color.rgb2lab(rgb)

converted = np.array(lab).astype(np.float32)
rgb = color.lab2rgb(converted)

The last line gives an error:
ValueError: Images of type float must be between -1 and 1. 

and here's the Stack Trace:
  File "C:\Anaconda3\lib\site-packages\skimage\color\colorconv.py", line 928, in lab2rgb
    return xyz2rgb(lab2xyz(lab))
  File "C:\Anaconda3\lib\site-packages\skimage\color\colorconv.py", line 855, in lab2xyz
    arr = _prepare_colorarray(lab).copy()
  File "C:\Anaconda3\lib\site-packages\skimage\color\colorconv.py", line 153, in _prepare_colorarray
    return dtype.img_as_float(arr)
  File "C:\Anaconda3\lib\site-packages\skimage\util\dtype.py", line 291, in img_as_float
    return convert(image, np.float64, force_copy)
  File "C:\Anaconda3\lib\site-packages\skimage\util\dtype.py", line 195, in convert
    raise ValueError("Images of type float must be between -1 and 1.") 
ValueError: Images of type float must be between -1 and 1. 

A:

Using x.astype(np.float32) is perfectly acceptable.   You'll seldom if ever need that level of accuracy. 
If you are not careful, however, you may accidentally cast an integer image (e.g., unsigned bytes, going from 0 to 255) into float.   So the safest approach, that will rescale as necessary, is
from skimage import img_as_float
image = img_as_float(image).astype(np.float32)

