Python: PIL (Pillow) & Numpy intersect images

Input images used :

1.png C.png


One Comment

  1. # Here’s how to intersect a multitude of images
    from PIL import Image
    import numpy as np
    import os

    images = []
    file_o = r’.\tmp’
    for i, filename in enumerate(os.listdir(file_o)):
    images.append(,filename)).convert(mode=’L’, dither=Image.NONE))

    # threshold the image
    t_images = []
    pixelThreshold = 200
    for image in images:
    image = np.array(image)
    t_images.append(np.where(image > pixelThreshold, 255, 0))

    composite = t_images[0]
    for i, image in enumerate(t_images):
    if i >= 1:
    composite = (composite + image)

    composite = np.where(composite > pixelThreshold, 255, 0)
    composite = Image.fromarray(composite.astype(np.uint8))‘composite.png’)



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s