Harsh Wardhan Harsh Wardhan - 4 months ago 76x
Python Question

Convert RGB triplets to LAB triplets using skimage.color.rgb2lab()

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:

rgb_color = [[[0.1,0.2,0.3]]]
lab_color = color.rgb2lab(rgb_color)