I created a dummy function to let me know which image is loading and how long it takes:
from PIL import Image
from timeit import default_timer as timer
def ImageLoad(path: str):
print("Loading '" + path + "'... ", end='')
start = timer()
im = Image.open(path)
print("successfully (%.2fs)." % (timer()-start))
return im
But when I use it, it always indicate 0 second even though the images are huge (about 20K x 60K pixels):
Loading 'Image0.png'... successfully (0.00s).
Loading 'Image1.png'... successfully (0.00s).
I added another print after the function is called:
image = ImageLoad(path)
print("Image loaded").
I see the second print being displayed at least 40 seconds after, which makes perfect sense.
Why am I getting the the message immediately displayed despite the fact that the image is not loaded?
According to the Pillow docs:
This is a lazy operation; this function identifies the file, but the file remains open and the actual image data is not read from the file until you try to process the data
PIL.Image.open doesn't immediately open the image file. If you want to immediately load the file, call the load() method on the file.