python RGB转LAB报错 color.rgb2lab

我在学习python,在csdn复制了一段图像处理的代码,运行后报错:
发生异常: ValueError
the input array must have size 3 along channel_axis, got (771, 1024, 4)
File "D:\python\photo.py", line 14, in
lab_img = color.rgb2lab(cimage)
请问这是什么问题,我查了一圈都没找到解决方法,感谢。
代码如下:


```python
from skimage.io import imread
from skimage import color
import numpy as np
import matplotlib.pyplot as plt
plt.ion()

# 读取图片
cimage = imread('D:\python\photo.jpg')
fig, ax = plt.subplots(figsize=(20, 20))
ax.imshow(cimage)
ax.axis('off')

# RGB转为LAB
lab_img = color.rgb2lab(cimage)
x, y, z = lab_img.shape

# 显示颜色
to_plot = cimage.reshape(x * y, 3)
colors_map = to_plot.astype(np.float) / 256

# 创建数据
scatter_x = []
scatter_y = []
for xi in range(x):
    for yi in range(y):
        L_val = lab_img[xi, yi][0]
        A_val = lab_img[xi, yi][1]
        B_val = lab_img[xi, yi][2]
        scatter_x.append(A_val)
        scatter_y.append(B_val)

plt.figure(figsize=(20, 20))
plt.xlabel("a* from green to red")
plt.ylabel("b* from blue to yellow")
plt.scatter(scatter_x, scatter_y, c=colors_map)
# 显示
plt.show()


```

我已经在问题中把报错贴出来了:
发生异常: ValueError
the input array must have size 3 along channel_axis, got (771, 1024, 4)
File "D:\python\photo.py", line 14, in
lab_img = color.rgb2lab(cimage)

原因是color.rgb2lab()所需的图片是RGB3通道的,而你的'D:\python\photo.jpg'图片是RGBA4通道的。把图片换成3通道即可。或者代码里做下转换:

# RGB转为LAB
lab_img = color.rgb2lab(cimage)

改成

# RGBA转为RGB
cimage = color.rgba2rgb(cimage)

# RGB转为LAB
lab_img = color.rgb2lab(cimage)

给你个3通道的测试图片:

img

你把报错复制出来发给我