猿问

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

我想导入一些带有分割 RGB 值的图像,对于一些它可以工作的图像,对于其他一些图像,输出只给出一个像素的 RGB 值。


这是代码适用的图像:


if os.path.isfile(location1):  

    image = imageio.imread(location1)

print("Type : ", type(image[0][0]))

## Type : imageio.core.util.Image

input : image

output: 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: image

output: Image([[81, 78, 74, ..., 72, 71, 69],

      [74, 71, 67, ..., 70, 70, 68],

      [61, 58, 55, ..., 65, 65, 64],

   ...,

(我将不胜感激任何帮助)


largeQ
浏览 137回答 1
1回答

慕运维8079593

您加载的第二个图像似乎只是一个灰度图像(即不是带有颜色的图像,而只有灰度)。要将其转换为 RGB,请尝试以下操作:from skimage import colorimg = color.gray2rgb(your_image)此外,由于转换为 RGB 只是将每个灰度值重复 3 次,因此您可以使用此代码段import numpy as nprgb = np.stack((your_image, your_image, your_image), axis=-1)
随时随地看视频慕课网APP

相关分类

Python
我要回答