Advertisement
Peaser

ImgMerge

Aug 1st, 2014
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. from PIL import Image
  2. import sys,os
  3.  
  4. dimensions = (1920,1080)
  5.  
  6. try:
  7.     workpath = sys.argv[1] #<--THIS NEEDS TO BE A DIRECTORY
  8.     if not os.path.isdir(workpath): raise Exception, "Not a directory."
  9. except Exception, e:
  10.     print e
  11.     sys.exit(0)
  12.  
  13. def avAll(object):
  14.     """LIST OF TUPLES(LEN=3)"""
  15.     a,b,c=[],[],[]
  16.     a.append([i[0] for i in object])
  17.     b.append([i[1] for i in object])
  18.     c.append([i[2] for i in object])
  19.     a = [sum(i)/len(i) for i in a]
  20.     b = [sum(i)/len(i) for i in b]
  21.     c = [sum(i)/len(i) for i in c]
  22.     return (a,b,c)
  23.  
  24. files = [i for i in os.listdir(workpath)]
  25. pix = []
  26. for i in files:
  27.     pic1 = Image.open(workpath+'/'+i).resize(dimensions)
  28.     p1dat = pic1.getdata()
  29.     pix.append(p1dat)
  30. vecs = zip(*pix)
  31.  
  32. total = [avAll(i) for i in vecs]
  33. def fix(a):
  34.     t = []
  35.     for i in a:
  36.         t2 = []
  37.         for z in i:
  38.             t2.append(z[0])
  39.         t.append(tuple(t2))
  40.     return t
  41. total = fix(total)
  42. img = Image.new('RGB', dimensions, "white")
  43. img.putdata(total)
  44. img.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement