Python: PIL (Pillow) & Numpy intersect images


Input images used :

1.png C.png

Advertisements

Published by

Aarsh Talati

Software Developer

One thought on “Python: PIL (Pillow) & Numpy intersect images”

  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(Image.open(os.path.join(file_o,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.show()
    composite.save(‘composite.png’)

    Like

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s