I have a directory of images in order. Typically my code will be using data from a sequential subset of images (e.g. images 5-10), and the naive options for accessing these are:
Create a wrapper object with a method that loads the image when needed and reads my data (e.g. a pixel value). This has little memory overhead but will be slow as it will need to load each image every time.
Store all the images in memory. This will be fast but obviously there's a limit to how many images we can store.
I would like to find:
- Some method by which I can define how to read the image corresponding to an index or a path, and then allows me to access, say
magic_image_collection[index]without me having to worry about whether it's going to return the object in memory or read it afresh. This would ideally keep the appropriate images or thenmost recently accessed images in memory.