I can convert an image from RGB color space to LAB color space using skimage.color.rgb2lab(). But when I try converting a single RGB triplet to LAB triplet
rgb_color = [0.1,0.2,0.3]
lab_color = color.rgb2lab(rgb_color)
I get the following error:
ValueError: the input array must be have a shape == (.., ..,[ ..,] 3)), got (3)
What is the correct way to do it? I'm using Python 2.7.
rgb2lab()
expects a 3D (or 4D) image; you're passing it a 1D list of numbers.
Try giving it a one-pixel image:
>>> from skimage import color
>>> rgb_color = [[[0.1,0.2,0.3]]] # Note the three pairs of brackets
>>> lab_color = color.rgb2lab(rgb_color)
>>> lab_color
array([[[ 20.47616557, -0.65320961, -18.63011548]]])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With