b2eb79ae |
1 | #!/usr/bin/python |
2 | |
3 | import sys |
4 | import Image |
5 | |
6 | if len(sys.argv) < 3: |
7 | sys.stderr.write("usage: icom-gen INFILE OUTFILE\n") |
21e62b99 |
8 | sys.exit(1) |
b2eb79ae |
9 | |
10 | inf = Image.open(sys.argv[1]) |
11 | sz = inf.size |
12 | tsz = (25, 25) |
13 | out = [] |
14 | |
15 | for y in xrange(tsz[1]): |
16 | line = [] |
17 | for x in xrange(tsz[0]): |
18 | sum = [0, 0, 0] |
19 | n = 0 |
20 | for y2 in xrange(y * sz[1] / tsz[1], (y + 1) * sz[1] / tsz[1]): |
21 | for x2 in xrange(x * sz[0] / tsz[0], (x + 1) * sz[0] / tsz[0]): |
22 | p = inf.getpixel((x2, y2)) |
23 | for c in xrange(3): |
24 | sum[c] += p[c] |
25 | n += 1 |
26 | for c in xrange(3): |
27 | sum[c] /= n |
28 | line.append(tuple(sum)) |
29 | out.append(line) |
30 | |
31 | f = open(sys.argv[2], "w") |
32 | for line in out: |
33 | for p in line: |
34 | for c in p: |
35 | f.write(chr(c)) |
36 | f.close() |