Loading a large number of images

edited August 2017 in Questions about Code

I'm working on a project where I cycle through and manipulate large number of images, but I keep running out of memory when trying to fill an array with my images. I have 2.3k images ranging from 400-700kb; the total size of the images is about 1.3 gb. I've increased the max memory allowance in Processing to 8gb but I'm still running out of memory.

My program gets stuck in setup loading my image files - (heres the code for reference)

for (int n = 0; n < imageCount; n++) { images[n] = loadImage(prefix + n + fileformat); }

Is there a more memory efficient way to work with a large number of images? It still seems strange that the program takes significantly more memory than the file size of the images. I've been able to make it work with an image count ~1000.

Thanks! B

Answers

  • Quick follow up - by loading each image in 'draw', it seems like I can avoid any memory issues. But I'd still like to find some alternative ways of loading the images to do more blending and manipulation.

  • Do not load images in draw. Draw is a loop, runs 60 times a second and loadImage is too expensive, will slow things right down.

    Images on disk are compressed. When loaded they will take 4 bytes per pixel, 1 for each of alpha, red, green and blue.

  • (loading images in draw is ok if you aren't interested in realtime interaction or speed, say if you're just iterating through a directory of images, manipulating them and saving them out again. But even then that's probably better done as a loop in setup)

  • Thank you both!

    Koogs - all I know is that when I try loading the images in setup, memory usage is off the charts, eventually crashing it. But when I load the images in draw, even at 60fps, i have consistent memory usage and no performance problems with basic manipulations.

    Thanks for the link kfrajer. I figured reading the images in batches might also be an option as well.

    As the program gets more complicated, I'll have to see what method holds up best.

Sign In or Register to comment.