现在的位置: 首页 > 编程语言 > 正文

python读取图片的几种方式及图像宽和高的存储顺序

2020年02月18日 编程语言 ⁄ 共 821字 ⁄ 字号 评论关闭

1、opencv2、imageio3、matplotlib4、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读取图片的几种方式及图像宽和高的存储顺序,希望对大家有所帮助!

以上就上有关python读取图片的几种方式及图像宽和高的存储顺序的全部内容,学步园全面介绍编程技术、操作系统、数据库、web前端技术等内容。

抱歉!评论已关闭.