title: python image to pixel conversion performance
body: <p>I am trying to convert jpeg to pixels after resizing it. The program works pretty well with fewer images. When I tried this with more number of images (say 10k) it runs for 2 to 3 hours. Is there a way to improve the performance?</p>
  
  <pre><code>import os as s
  import numpy as np
  import scipy
  from PIL import Image
  from scipy import ndimage
  import warnings
  warnings.filterwarnings('ignore')
  def imaget_to_pxl(path,size):
      img_to_pxls=np.zeros(shape=(1,size*size*3))
      img_name={'name':0}
      N=1
      #print img_to_pxls.shape
      for i in s.listdir(path):
          if i.endswith('.jpg'):
              new_size=(size,size)
              im = Image.open(path+i, 'r')#.resize(new_size)
              pixel_values = list(im.getdata())
              if im.mode == 'RGB':
                  my_image = scipy.misc.imresize(im, size=new_size)#.reshape((1,-1))
                  img_to_pxls=np.concatenate((img_to_pxls,my_image.reshape((1,-1))))
  
      return img_to_pxls
  </code></pre>