-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsplit_comparison.py
62 lines (53 loc) · 2.14 KB
/
split_comparison.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
56
57
58
59
60
61
62
import figuregen
from figuregen.util import image
import numpy as np
# ---------- Data Gathering ----------
# define some colors (r,g,b)
yellow=[232, 181, 88]
l_blue=[94, 163, 188]
blue=[82, 110, 186]
orange=[186, 98, 82]
# generate test images
img_blue = np.tile([x / 255 for x in blue], (320, 640, 1))
img_l_blue = np.tile([x / 255 for x in l_blue], (320, 640, 1))
img_yellow = np.tile([x / 255 for x in yellow], (320, 640, 1))
img_orange = np.tile([x / 255 for x in orange], (320, 640, 1))
# load images
images = [
[
image.SplitImage([img_blue, img_l_blue, img_yellow], degree=-20, weights=[0.5, 0.8, 0.5]),
image.SplitImage([img_yellow, img_orange], degree=15, vertical=False, weights=[0.5, 1.0])
],
[
image.SplitImage([img_yellow, img_orange], weights=[1.0, 1.0], degree=30),
image.SplitImage([img_yellow, img_l_blue, img_blue], vertical=False, weights=[1, 2, 3], degree=0),
]
]
# ---------- Simple Grid with SplitImages ----------
n_rows = 2
top_cols = 2
top_grid = figuregen.Grid(num_rows=n_rows, num_cols=top_cols)
# fill grid with image data
for row in range(n_rows):
for col in range(top_cols):
s_img = images[row][col]
raw_img = figuregen.PNG(s_img.get_image())
e = top_grid.get_element(row,col).set_image(raw_img)
e.draw_lines(s_img.get_start_positions(), s_img.get_end_positions(), linewidth_pt=0.5, color=[0,0,0])
top_grid.set_col_titles('top', ['Horizontal Split', 'Vertical Split', 'C)', 'D)'])
# LAYOUT: Specify paddings (unit: mm)
top_lay = top_grid.layout
top_lay.set_padding(column=1.0, right=1.5)
top_lay.column_titles[figuregen.TOP].size = 5.0
if __name__ == "__main__":
width_cm = 15
basename = "split-comparison"
figuregen.figure([[top_grid]], width_cm=width_cm, filename=basename+'.pdf',
backend=figuregen.PdfBackend(intermediate_dir="log"))
figuregen.figure([[top_grid]], width_cm=width_cm, filename=basename+'.pptx')
figuregen.figure([[top_grid]], width_cm=width_cm, filename=basename+'.html')
try:
from figuregen.util import jupyter
jupyter.convert(basename+'.pdf', 300)
except:
print('Warning: pdf could not be converted to png')