【594】图像读取与显示(mask图像)

  图像转数组

from keras.preprocessing import image 
img_path = target_img_paths[9]
img = image.load_img(img_path)
x = image.img_to_array(img)

x.shape 

# (448, 500, 3)

# 获取数组包含的值,三个通道的值一样
set(x.reshape(448*500*3))

# {1.0, 2.0, 3.0}

  只包含几个数值的图像显示

from IPython.display import Image, display
from tensorflow.keras.preprocessing.image import load_img
import PIL
from PIL import ImageOps

# Display input image #7
# 正常图片显示
display(Image(filename=input_img_paths[9]))

# Display auto-contrast version of corresponding target (per-pixel categories)
# 只含有 3 个数字的图像显示
img = PIL.ImageOps.autocontrast(load_img(target_img_paths[9]))
display(img)

原文地址:https://www.cnblogs.com/alex-bn-lee/p/14973299.html