Added icom utils.
[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")
8
9inf = Image.open(sys.argv[1])
10sz = inf.size
11tsz = (25, 25)
12out = []
13
14for y in xrange(tsz[1]):
15 line = []
16 for x in xrange(tsz[0]):
17 sum = [0, 0, 0]
18 n = 0
19 for y2 in xrange(y * sz[1] / tsz[1], (y + 1) * sz[1] / tsz[1]):
20 for x2 in xrange(x * sz[0] / tsz[0], (x + 1) * sz[0] / tsz[0]):
21 p = inf.getpixel((x2, y2))
22 for c in xrange(3):
23 sum[c] += p[c]
24 n += 1
25 for c in xrange(3):
26 sum[c] /= n
27 line.append(tuple(sum))
28 out.append(line)
29
30f = open(sys.argv[2], "w")
31for line in out:
32 for p in line:
33 for c in p:
34 f.write(chr(c))
35f.close()