forked from tinankh/GOD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_svg.py
55 lines (39 loc) · 1.61 KB
/
create_svg.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import sys
import imageio
import numpy as np
im = imageio.imread(sys.argv[1])
height, width = im.shape
print('<?xml version="1.0" standalone="no"?>')
print('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">')
print('<svg width="{}px" height="{}px" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">'.format(width, height))
print('<image x="0" y="0" width="{}" height="{}" xlink:href="{}"> </image>'.format(width, height, sys.argv[1]))
lnfa = []
zblue = []
zred = []
result_file = open(sys.argv[2], 'r').readlines()
# get most meaningful grid origin
for line in result_file:
window = line.split(' ')
lnfa.append(max(list(map(float,window[4:6]))))
meaningful = result_file[np.argmin(np.array(lnfa))]
gridx = meaningful.split(' ')[6]
gridy = meaningful.split(' ')[7]
# get list of significant (for foreign grids) and none significant windows
for line in result_file:
window = line.split(' ')
if (window[6] == '-1'):
zblue.append(list(map(int, window[0:4])))
else:
if (window[6] != gridx or window[7] != gridy):
zred.append(list(map(int, window[0:4])))
# draw blue windows
for z in zblue:
print('<rect x="{}" y="{}" width="{}" height="{}" fill="blue" fill-opacity="0.2"></rect>'
.format(z[0],z[1],z[2]-z[0],z[3]-z[1]))
# draw red windows over the blue windows
for z in zred:
print('<rect x="{}" y="{}" width="{}" height="{}" fill="red" fill-opacity="0.2"></rect>'
.format(z[0],z[1],z[2]-z[0],z[3]-z[1]))
print('</svg>')