I am wondering what the most efficient methods for reading/writing image and PDF files as numpy arrays for processing.
So far I have seen scipy.ndimage.imread and using PIL and numpy, which yeild the following results:
import os
import glob
from scipy.ndimage import imread
from PIL import Image
import numpy as np
import timeit
iters = 2
def scipy_fun():
for x in glob.glob("*.jpg"):
px = imread(x)
def PIL_fun():
for x in glob.glob("*.jpg"):
with Image.open(x) as im:
px = np.array(im)
print(timeit.Timer(scipy_fun).timeit(number=iters))
print(timeit.Timer(PIL_fun).timeit(number=iters))
running the script shows similar results with marginally better from scipy:
2.8794324089019234
3.0174482765699095
Are there any faster ways to do this?
imageioappears to be a very good library. The output wasscipy: ~4 secs imageio: ~3 secs PIL: ~4 secs