Input images used :
1.png | C.png |
![]() |
![]() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import izip | |
from PIL import Image | |
import numpy as np | |
i1 = Image.open('1.png').convert(mode='L', dither=Image.NONE) | |
i2 = Image.open('C.png').convert(mode='L', dither=Image.NONE) | |
pixelThreshold = 200 | |
i1 = np.array(i1) | |
i1 = np.where(i1 > pixelThreshold, 255, 0) | |
i2 = np.array(i2) | |
i2 = np.where(i2 > pixelThreshold, 255, 0) | |
final1 = (i1+i2) | |
final1 = Image.fromarray(final1.astype(np.uint8)) | |
final1.show() | |
final1.save('test.png') |
# 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’)
LikeLike