alex_bn_lee

导航

【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)

  最简单的图像显示(在 jupyter 内部显示),使用 Ipython.display(Image打开的图片) 函数,参考:Jupyter-notebook 显示图片的两种方法

posted on 2021-07-05 17:06  McDelfino  阅读(392)  评论(0)    收藏  举报