summaryrefslogtreecommitdiff
path: root/2dhist_to_img
blob: b0ed12f79f0164831ae8aa5cec006378ca50dbf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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