Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 729
Harsh Wardhan Avatar asked May 28 '16 23:05

Harsh Wardhan


1 Answers

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]]])
like image 119
dbort Avatar answered Oct 05 '22 15:10

dbort