Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rgb2lab([1,1,1]) returns [0.,0.,0.] #7422

Open
jTiKey opened this issue May 15, 2024 · 2 comments
Open

rgb2lab([1,1,1]) returns [0.,0.,0.] #7422

jTiKey opened this issue May 15, 2024 · 2 comments
Labels

Comments

@jTiKey
Copy link

jTiKey commented May 15, 2024

Description:

For some reason rgb2lab([1,1,1]) returns [0.,0.,0.] instead of array([ 1.00000000e+02, -2.45493786e-03, 4.65342115e-03]).
It works fine on my windows machine but the DO app doesn't work properly.

Way to reproduce:

from skimage.color import rgb2lab
rgb2lab([1,1,1])

Version information:

3.11.8 (main, Feb  7 2024, 09:33:13) [GCC 11.4.0]
Linux-4.4.0-x86_64-with-glibc2.35 (Digital ocean App platform)
scikit-image version: 0.23.2
numpy version: 1.26.4
@jTiKey
Copy link
Author

jTiKey commented May 15, 2024

After some tries, looks like the interger is the issue, replacing the integer with float makes it work.

@mkcor
Copy link
Member

mkcor commented Jun 3, 2024

Thanks for using scikit-image, @jTiKey!

This is a matter of image data type, indeed: rgb2lab calls rgb2xyz which calls _prepare_colorarray which calls img_as_float32 or (in this case) img_as_float64 to convert the input array into floating-point representation... and:

import numpy as np
import skimage as ski

print(np.__version__)
1.26.4
print(ski.__version__)
0.23.2

arr = [1, 1, 1]
arr = np.asanyarray(arr)
print(arr.dtype)
int64

# Range of int64 goes up to 1/(2**64 - 1) so:
assert ski.util.dtype.img_as_float64(arr)[0] == 1/(2**64 - 1) * 2

See https://scikit-image.org/docs/stable/user_guide/data_types.html and references therein. Do you mind if I close this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants