读取图片格式有多个代码库,比如opencv-PIL-matplotlib-Skimage-Pytorch。
PIL读取图片函数是open,其他基本是imread方法。
PIL读取图片的格式是image,其他基本是numpy的array数组。
具体可以参考 https://www.jianshu.com/p/dd08418c306f
但还有一个不同点,matplotlib读取的数据会有一些问题,比如我这里遇到的是:
"Sizes of input arguments do not match"
代码如下:
用cv读取照片
import cv2
filepath = "1.jpg"
image = cv2.imread(filepath)
image.shape
>>> (1920, 2160, 3)
用matplotlib读取照片:
import matplotlib.image as Img
filepath = "1.jpg"
image2 = Img.imread(filepath)
image2.shape
>>> (1920, 2160)
查看了图片格式,是正常的jpg,RGB三通道。
测试了另一个jpg图片,用matplotlib和opencv读出来的图片shape又是一样的。