使用skimage.color.rgb2lab()将RGB三元组转换为LAB三元组

Har*_*han 4 python colors python-2.7

我可以使用skimage.color.rgb2lab()将图像从RGB颜色空间转换为LAB颜色空间.但是当我尝试将单个RGB三元组转换为LAB三元组时

rgb_color = [0.1,0.2,0.3]
lab_color = color.rgb2lab(rgb_color)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

ValueError: the input array must be have a shape == (.., ..,[ ..,] 3)), got (3)
Run Code Online (Sandbox Code Playgroud)

这样做的正确方法是什么?我正在使用Python 2.7.

dbo*_*ort 9

rgb2lab()期待3D(或4D)图像; 你传给它一个数字列表.

尝试给它一个像素的图像:

>>> 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]]])
Run Code Online (Sandbox Code Playgroud)