summaryrefslogtreecommitdiff
path: root/2dhist_to_img
diff options
context:
space:
mode:
Diffstat (limited to '2dhist_to_img')
-rwxr-xr-x2dhist_to_img40
1 files changed, 40 insertions, 0 deletions
diff --git a/2dhist_to_img b/2dhist_to_img
new file mode 100755
index 0000000..b0ed12f
--- /dev/null
+++ b/2dhist_to_img
@@ -0,0 +1,40 @@
+#!/usr/bin/python
+
+import sys
+import math
+
+# read sparse matrix
+a = {}
+amax = []
+amin = []
+for line in sys.stdin:
+ point = line.split('\t')
+ val = int(point[0])
+ pos = (int(point[1]), int(point[2]))
+ a[pos] = val
+
+ # update array size
+ if len(amax) == 0:
+ amax = [pos[0], pos[1]]
+ amin = [pos[0], pos[1]]
+ for i in [0,1]:
+ amin[i] = min(amin[i], pos[i])
+ amax[i] = max(amax[i], pos[i])
+
+vbase = 0
+if len(sys.argv) > 1:
+ vbase = int(sys.argv[1])
+
+# print matrix result
+if len(amax) == 0:
+ print 0
+ exit(0)
+for x in range(amin[0], amax[0]):
+ for y in range(amin[1], amax[1]):
+ v = vbase
+ if (x,y) in a:
+ v = v + a[(x,y)]
+ sys.stdout.write(str(v) + '\t')
+ sys.stdout.write('\n')
+
+
contact: Jan Huwald // Impressum