我想导入一些带有分割 RGB 值的图像,对于一些它可以工作的图像,对于其他一些图像,输出只给出一个像素的 RGB 值。这是代码适用的图像:if os.path.isfile(location1): image = imageio.imread(location1)print("Type : ", type(image[0][0]))## Type : imageio.core.util.Imageinput : imageoutput: Image([[[167, 126, 94], [210, 184, 147], [245, 234, 188], ...,这是代码不起作用的图像。if os.path.isfile(location2): image = imageio.imread(location2)print("TYpe : ", type(image[0][0]))## TYpe : <class 'numpy.uint8'>input: imageoutput: Image([[81, 78, 74, ..., 72, 71, 69], [74, 71, 67, ..., 70, 70, 68], [61, 58, 55, ..., 65, 65, 64], ...,(我将不胜感激任何帮助)
1 回答

慕运维8079593
TA贡献1876条经验 获得超5个赞
您加载的第二个图像似乎只是一个灰度图像(即不是带有颜色的图像,而只有灰度)。要将其转换为 RGB,请尝试以下操作:
from skimage import color
img = color.gray2rgb(your_image)
此外,由于转换为 RGB 只是将每个灰度值重复 3 次,因此您可以使用此代码段
import numpy as np
rgb = np.stack((your_image, your_image, your_image), axis=-1)
添加回答
举报
0/150
提交
取消