Python Image Library Image Overlay on 1000 Images

I need to create an overlay / composition of 1000 images that are the same size on top of each other. They will all have the same level of transparency that any pixel that has no image in any of the 1000 images will be white, and a pixel that has an image in each of the 1000 images will be black in the final 1000 overlay.

I am new to domain and am trying to figure out how to do this. I realized that it is possible to use blend or paste (not sure about the difference between them at this stage), but they only accept 2 images as arguments. How can I superimpose all 1000?

+3


source to share


2 answers


Actually, I decided to make a heatmap using matplotlib and numpy instead of creating overlaid images.



0


source


you need to loop over 1000 images, store them in an auxiliary array and overlay them on the same picture, the code will be like this:

import numpy as np
import matplolib.pyplot as plt
from PIL import Image

img_list = 'list of name of your images '
fig= plt.figure(1)

for i in img_list:
   aux=Image.open(i)
   aux=np.array(aux)
   plt.imshow(aux)
   plt.show()
plt.imsave('name.png')

      



if it doesn't work try the same script, but use a new image and overlay image each time as arguments to insert like this:

import numpy as np
from PIL import Image

img_list = 'list of names of your images '

i=0

background = Image.new(img_list[1].mode ,img_list[1].size)

while i < len(img_list):
   aux = Image.open(img_list[i])
   background = background.paste(aux,(0,0),aux)
   i=i+1
background.show()

      

0


source







All Articles