title: Python - load lots of images without using all available ram
body: <p>I have about 1.5 GB of images that I need to process. The problem is that when I try loading them as np arrays I seem to use up all of my ram (8 GB).</p>
  
  <p>Here is my method for loading images:</p>
  
  <pre><code>def load_image( infilename ) :
      img = Image.open( infilename )
      img.load()
      data = np.asarray( img, dtype="int32" )
      img.close()
      del img
      return data
  </code></pre>
  
  <p>I thought closing and deleting the img would help, but it doesn't. Can this have something to do with garbage collection?</p>
  
  <p>Code to loop through all images in a list of file names:</p>
  
  <pre><code>for i in range(len(files)):
      imgArray = imgs.load_image(files[i])
      images.append(imgArray)
      shapes.append(np.shape(imgArray))
  </code></pre>
  
  <p>Is there a better way?</p>