Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import png
- from sys import argv
- from itertools import tee, izip
- img = png.Reader(argv[1]).read()
- def group(it, num):
- res = []
- for el in it:
- res.append(el)
- if len(res) == num:
- yield tuple(res)
- res = []
- w = img[0]
- h = img[1]
- pic = img[2]
- coef = [float(c) for c in argv[3:6]]
- gamma = float(argv[6])
- w = png.Writer(w, h, greyscale=True, alpha=True)
- outpic = []
- for line in pic:
- outline = []
- for x,y,z,a in group(line, 4):
- l = (coef[0]*x + coef[1]*y + coef[2]*z)/255.
- if not a:
- a = 255
- else:
- a = max(0, min(255, int(255*(1 - l**gamma))))
- outline += [255, a]
- outpic.append(outline)
- with open(argv[2], 'w') as f:
- w.write(f, outpic)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement