Bug when using float32 arrays and Lab2Rgb
I am doing a LAB to RGB conversion. If my LAB matrix is float64, the bounds for the axes must be -100, 100. Upon analysis of the output RGB image, the results look correct. However, if the LAB matrix is float32 the bounds are checked and forced to -1 1 which yields an RGB image that is incorrect. Upon further inspect, the problem looks like it comes from the convert function in dtype.py. image = np.asarray(image) dtypeobj = np.dtype(dtype) dtypeobj_in = image.dtype dtype = dtypeobj.type dtype_in = dtypeobj_in.type if dtype_in == dtype: if force_copy: image = image.copy() return image at the "if dtype_in == dtype:" the types are float32 and float64 causing the if to be skipped. Eventually the code reaches the point: if kind_in == 'f': if np.min(image) < -1.0 or np.max(image) > 1.0: raise ValueError("Images of type float must be between -1 and 1.") if kind == 'f': # floating point -> floating point if itemsize_in > itemsize: prec_loss() return dtype(image) and the bounds are checked, outside of [-1 1] and an error is thrown. Isaac
Hi Isaac On Tue, Apr 16, 2013 at 7:34 PM, Isaac Gerg <isaac.gerg@gergltd.com> wrote:
I am doing a LAB to RGB conversion.
If my LAB matrix is float64, the bounds for the axes must be -100, 100. Upon analysis of the output RGB image, the results look correct.
Thanks for spotting this bug. Not all functions should call img_as_float on their input arguments, as you point out. A pull request would be very welcome, or otherwise please file an issue on GitHub. Stéfan
participants (2)
-
Isaac Gerg
-
Stéfan van der Walt