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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

* star *   2021-04-21 我要评论

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

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们