Posted in Python onFebruary 11, 2020
1、opencv
2、imageio
3、matplotlib
4、scipy
# coding:utf-8 import cv2 import imageio from scipy import misc from PIL import Image from matplotlib import pyplot as plt image_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读取图片的几种方式及图像宽和高的存储顺序
- Author -
* star *声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@