上面这些库都被广泛用于图像处理和计算机视觉任务;
不同的图像读取库(OpenCV,Pillow,matplotlib和skimage)的读取速度,是怎么样的一个情况?
下面分别从读取速度,以及转换到RGB通道的numpy格式两方面进行比较,
Python代码如下:
"""
比较opencv,pillow,matplotlib,skimage读取图像的速度;"""
import cv2
from PIL import Imageimport time
import matplotlib.image as mpimg # mpimg 用于读取图片
import numpy as npfrom skimage import iodef opencv_i():st = time.time()img = cv2.imread("./images.jpg")print(f"cv2 read take time {time.time() - st} s")img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)end = time.time()print(f"opencv2 total take time {end - st} s,to rgb numpy format")def pillow_i():st = time.time()im = Image.open("./images.jpg")print(f"pillow read take time {time.time() - st} s")output = np.array(im)end = time.time()print(f"pillow rgb numpy,total take time {end - st} s,to rgb numpy format")def matplot_i():st = time.time()lena = mpimg.imread('./images.jpg') end = time.time()print(f"matplot read take time {end - st} s,to rgb numpy format")def skimage_i():st = time.time()img = io.imread('images.jpg')end = time.time()print(f"skimage read take time {end - st} s,to rgb numpy format")print("-"*30)
opencv_i()
print("-"*30)
pillow_i()
print("-"*30)
matplot_i()
print("-"*30)
skimage_i()
运行结果如下:
从结果可以看到速度方面,opencv 最快,matplotlib 与 skimage库略微慢一点, pillow库相差的更多一点;
由于每个人的运行环境,图像大小,数量等因素的差异,本结果仅仅作为一个小小的参考;
个人水平有限,有问题随时联系;
欢迎一键三连~