在 Python 中将图像导入为"imageio.core.util.Image"类型的 RGB 像素



我想导入一些具有拆分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],
   ...,

(感谢任何帮助)

这似乎是您加载的第二张图像只是灰度图像(即不是带有颜色的图像,而是灰色级别的图像)。要将其转换为RGB,请尝试以下内容:

from skimage import color
img = color.gray2rgb(your_image)

另外,由于转换为RGB只是要重复每个灰色值三遍,因此您可以使用此片段

import numpy as np
rgb = np.stack((your_image, your_image, your_image), axis=-1)

最新更新