为了账号安全,请及时绑定邮箱和手机立即绑定

在 Python 中将图像导入为“imageio.core.util.Image”

在 Python 中将图像导入为“imageio.core.util.Image”

largeQ 2021-11-16 10:41:06
我想导入一些带有分割 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)


查看完整回答
反对 回复 2021-11-16
  • 1 回答
  • 0 关注
  • 136 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信