Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import png
  4. from sys import argv
  5. from itertools import tee, izip
  6.  
  7. img = png.Reader(argv[1]).read()
  8.  
  9. def group(it, num):
  10.     res = []
  11.     for el in it:
  12.         res.append(el)
  13.         if len(res) == num:
  14.             yield tuple(res)
  15.             res = []
  16.  
  17. w = img[0]
  18. h = img[1]
  19. pic = img[2]
  20. coef = [float(c) for c in argv[3:6]]
  21. gamma = float(argv[6])
  22.  
  23. w = png.Writer(w, h, greyscale=True, alpha=True)
  24.  
  25. outpic = []
  26.  
  27. for line in pic:
  28.     outline = []
  29.     for x,y,z,a in group(line, 4):
  30.         l = (coef[0]*x + coef[1]*y + coef[2]*z)/255.
  31.         if not a:
  32.             a = 255
  33.         else:
  34.             a = max(0, min(255, int(255*(1 - l**gamma))))
  35.         outline += [255, a]
  36.     outpic.append(outline)
  37.  
  38. with open(argv[2], 'w') as f:
  39.     w.write(f, outpic)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement