Loop through all pixels of 2 images and replace the black pixels with white
<p>I have 2 co-located images, both created in a similar way and both have the size of 7,221 x 119 pixels.</p>

<p>I want to loop through all the pixels of both images. If the pixels are black on the first image and also black on the second image then turn it into white, otherwise, no change.</p>

<p>How can I do it with python?</p>

<p>This should hopefully be pretty close to what you're looking for.</p>

<pre><code>from PIL import Image
from PIL import ImageFilter

im            = Image.open('a.png')
imb           = Image.open('b.png')
pix           = im.load()
width, height = im.size
for w in xrange(width):
    for h in xrange(height):
        r,g,b,a = pix[(w,h)]
        rb, gb, bb, ab = pix[(w,h)]
        if not (r+g+b+rb+gb+bb): #all values 0
            pix[w,h] = (255,255,255,255)
im.save('test','BMP')
</code></pre>

python image