Info: I have 30,000 jpg images that I need to convert into (NumPy) pixel arrays.
Problem: I have tried using Pillow to do the image conversions but it does about 2 images a second which would take hours to complete.
from PIL import Image
for img_num in range(30_000):
img = Image.open(img_dir+img_num+extension)
img_list.append(np.array(img))
Question: What is the best and fastest way to convert a large number of jpg images to pixel arrays using python.
I think what is taking the longest is the append()
function.
Also, you are appending 30000 images to img_list
, this means this single variable is extremely heavy in memory, do you actually need it? (if you image had 1000 pixels, you'd already be trying to allocate more than 30Mb)
In PIL
and openCV
the read or
open` functions directly make them jumpy arrays.