Stack multiple images in python pillow
<p>I am trying to do some image stacking in python pillow.  What I would like to do is take a large number of images (say 10), and then for each pixel, take the median value like this: <a href="http://petapixel.com/2013/05/29/a-look-at-reducing-noise-in-photographs-using-median-blending/" rel="nofollow">http://petapixel.com/2013/05/29/a-look-at-reducing-noise-in-photographs-using-median-blending/</a>.</p>

<p>Right now, I can do it in an incredibly brute force manner (using getpixel and put pixel), but it takes a very long time.</p>

<p>Here is what I have so far:</p>

<pre><code>import os
from PIL import Image
files = os.listdir("./")
new_im = Image.new('RGB', (4000,3000))
ims={}
for i in range(10,100):
    ims[i]={}           
    im=Image.open("./"+files[i])
    for x in range(400):
        ims[i][x]={}            
        for y in range(300):
            ims[i][x][y]=im.getpixel((x,y))

for x in range(400):
    for y in range(300):
        these1=[]
        these2=[]
        these3=[]
        for i in ims:
            these1.append(ims[i][x][y][0])
            these2.append(ims[i][x][y][1])
            these3.append(ims[i][x][y][2])
        these1.sort()
        these2.sort()
        these3.sort()
        new_im.putpixel((x,y),(these1[len(these1)/2],these2[len(these2)/2],these3[len(these3)/2]))

new_im.show()
</code></pre>