-
Notifications
You must be signed in to change notification settings - Fork 4
/
weeknd.py
27 lines (21 loc) · 846 Bytes
/
weeknd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import os, numpy, PIL
from PIL import Image
# Access all PNG files in directory
allfiles=os.listdir('weeknd/')
imlist=['weeknd/'+filename for filename in os.listdir('weeknd') if filename[-4:] in [".png",".PNG"]]
print(imlist)
# Assuming all images are the same size, get dimensions of first image
w,h=Image.open(imlist[0]).size
N=len(imlist)
# Create a numpy array of floats to store the average (assume RGB images)
arr=numpy.zeros((h,w,3),numpy.float)
# Build up average pixel intensities, casting each image as an array of floats
for im in imlist:
imarr=numpy.array(Image.open(im),dtype=numpy.float)
arr=arr+imarr/N
# Round values in array and cast as 8-bit integer
arr=numpy.array(numpy.round(arr),dtype=numpy.uint8)
# Generate, save and preview final image
out=Image.fromarray(arr,mode="RGB")
out.save("Average.png")
out.show()