Added icom utils.
authorfredrik <fredrik@959494ce-11ee-0310-bf91-de5d638817bd>
Wed, 21 Nov 2007 05:47:42 +0000 (05:47 +0000)
committerfredrik <fredrik@959494ce-11ee-0310-bf91-de5d638817bd>
Wed, 21 Nov 2007 05:47:42 +0000 (05:47 +0000)
git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/utils@1108 959494ce-11ee-0310-bf91-de5d638817bd

icom [new file with mode: 0755]
icom-dir [new file with mode: 0755]
icom-gen [new file with mode: 0755]

diff --git a/icom b/icom
new file mode 100755 (executable)
index 0000000..1b2bdb5
--- /dev/null
+++ b/icom
@@ -0,0 +1,34 @@
+#!/usr/bin/python
+
+import sys
+
+if len(sys.argv) < 3:
+    sys.stderr.write("usage: icom FILE1 FILE2\n")
+
+tsz = (25, 25)
+
+files = []
+
+for i in xrange(2):
+    f = open(sys.argv[i + 1])
+    lines = []
+    for y in xrange(tsz[1]):
+        line = []
+        for x in xrange(tsz[0]):
+            p = []
+            for c in f.read(3):
+                p.append(ord(c))
+            line.append(tuple(p))
+        lines.append(line)
+    files.append(lines)
+    f.close()
+
+sum = 0
+
+for y in xrange(tsz[1]):
+    for x in xrange(tsz[0]):
+        p = [f[y][x] for f in files]
+        for c in xrange(2):
+            sum += abs(p[0][c] - p[1][c])
+
+print sum
diff --git a/icom-dir b/icom-dir
new file mode 100755 (executable)
index 0000000..7565651
--- /dev/null
+++ b/icom-dir
@@ -0,0 +1,23 @@
+#!/usr/bin/python
+
+import sys, os
+from popen2 import popen2
+
+def combine(list):
+    for i in xrange(len(list) - 1):
+        for o in xrange(i + 1, len(list)):
+            yield list[i], list[o]
+
+if len(sys.argv) < 2:
+    sys.stderr.write("usage: icom-dir DIRECTORY\n")
+
+files = os.listdir(sys.argv[1])
+files.sort()
+pj = os.path.join
+
+for file1, file2 in combine(files):
+    co, ci = popen2(["icom", pj(sys.argv[1], file1), pj(sys.argv[1], file2)])
+    ci.close()
+    index = int(co.readline().split()[0])
+    co.close()
+    sys.stdout.write("%i %s %s\n" % (index, file1, file2))
diff --git a/icom-gen b/icom-gen
new file mode 100755 (executable)
index 0000000..e724144
--- /dev/null
+++ b/icom-gen
@@ -0,0 +1,35 @@
+#!/usr/bin/python
+
+import sys
+import Image
+
+if len(sys.argv) < 3:
+    sys.stderr.write("usage: icom-gen INFILE OUTFILE\n")
+
+inf = Image.open(sys.argv[1])
+sz = inf.size
+tsz = (25, 25)
+out = []
+
+for y in xrange(tsz[1]):
+    line = []
+    for x in xrange(tsz[0]):
+        sum = [0, 0, 0]
+        n = 0
+        for y2 in xrange(y * sz[1] / tsz[1], (y + 1) * sz[1] / tsz[1]):
+            for x2 in xrange(x * sz[0] / tsz[0], (x + 1) * sz[0] / tsz[0]):
+                p = inf.getpixel((x2, y2))
+                for c in xrange(3):
+                    sum[c] += p[c]
+                n += 1
+        for c in xrange(3):
+            sum[c] /= n
+        line.append(tuple(sum))
+    out.append(line)
+
+f = open(sys.argv[2], "w")
+for line in out:
+    for p in line:
+        for c in p:
+            f.write(chr(c))
+f.close()