Added a gitignore.
[utils.git] / icom-gen
CommitLineData
b2eb79ae 1#!/usr/bin/python
2
3import sys
4import Image
5
6if len(sys.argv) < 3:
7 sys.stderr.write("usage: icom-gen INFILE OUTFILE\n")
21e62b99 8 sys.exit(1)
b2eb79ae 9
10inf = Image.open(sys.argv[1])
11sz = inf.size
12tsz = (25, 25)
13out = []
14
15for 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
31f = open(sys.argv[2], "w")
32for line in out:
33 for p in line:
34 for c in p:
35 f.write(chr(c))
36f.close()