title: Load just part of an image in python
body: <p>This might be a silly question, but...</p>
  
  <p>I have several thousand images that I would like to load into Python and then convert into numpy arrays. Obviously this goes a little slowly. But, I am actually only interested in a small portion of each image. (The same portion, just 100x100 pixels in the center of the image.) </p>
  
  <p>Is there any way to load just part of the image to make things go faster?</p>
  
  <p>Here is some sample code where I generate some sample images, save them, and load them back in. </p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  import Image, time
  
  #Generate sample images
  num_images = 5
  
  for i in range(0,num_images):
      Z = np.random.rand(2000,2000)
      print 'saving %i'%i
      plt.imsave('%03i.png'%i,Z)
  
  %load the images
  for i in range(0,num_images):
      t = time.time()
  
      im = Image.open('%03i.png'%i)
      w,h = im.size
      imc = im.crop((w-50,h-50,w+50,h+50))
  
      print 'Time to open: %.4f seconds'%(time.time()-t)
  
      #convert them to numpy arrays
      data = np.array(imc)
  </code></pre>