python 读取image
在python中我们有两个库可以处理图像文件,scipy和matplotlib.
安装库
pip install matplotlib pillow scipy用法
from scipy.misc import imreaddata = imread(image_root)#data是 ndarray对象import matplotlib.image as mpimgdata = mpimg.imread(image_root)#data是 ndarray对象skimage
安装 pip install -U scikit-image
PIL
安装 pip install pillow
from PIL import Imageimport numpy as npimg_obj = Image.open(file_path)img_array = np.array(img_obj, dtype=np.uint8)# 无论是 jpg 还是 png 都能正确读取\matplotlib
安装 pip install matplotlib
from matplotlib.image import imreadimg = imread(img_path) # 返回 ndarray# 这个imread 读 png 的时候,返回ndarray 的类型是 uint8# 读 png 的时候,返回 ndarray 是 float32, 8-bit png 也能读出 3-channel,活在梦里以上所述是小编给大家介绍的python读取image详解整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!