1、opencv
2、imageio
3、matplotlib
4、scipy
# coding:utf-8import cv2import imageiofrom scipy import miscfrom PIL import Imagefrom matplotlib import pyplot as pltimage_path = "./images/000011.jpg"# 使用pillow读取图片,获取图片的宽和高img_pillow = Image.open(image_path)img_width = img_pillow.width # 图片宽度img_height = img_pillow.height # 图片高度print("width -> {}, height -> {}".format(img_width, img_height))img_cv = cv2.imread(image_path)img_imageio = imageio.imread(image_path)img_scipy = misc.imread(image_path)img_matplot = plt.imread(image_path)print(img_cv.shape)print(img_imageio.shape)print(img_scipy.shape)print(img_matplot.shape)
输出结果如下:
width -> 2000, height -> 1333
(1333, 2000, 3)
(1333, 2000, 3)
(1333, 2000, 3)
(1333, 2000, 3)
注意事项:读取出的图像矩阵的shape是按 高度、宽度、通道数 这个顺序,图像宽度是第一个维度
总结
以上所述是小编给大家介绍的python读取图片的几种方式及图像宽和高的存储顺序,希望对大家有所帮助!
新闻热点
疑难解答