-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathplot_actions.py
61 lines (48 loc) · 1.46 KB
/
plot_actions.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
from PIL import Image
import sys, os
import numpy as np
import imageio
from scipy import ndimage
def cut_image(i, j):
img = Image.open('0.png')
# crop to 64 * 64
width = 64; height = 64
imgwidth, imgheight = img.size
N_width = imgwidth / width
N_height = imgheight / height
print i, j, j * N_width + i
box = (i*width, j*height, (i+1)*width, (j+1)*height)
a = img.crop(box)
a.convert('RGB')
return a
if __name__ == '__main__':
n_class = 6
img_list = []
for attr in ['body', 'bottomwear', 'topwear', 'hair']:#, 'weapon']:
path = attr + '/'
filename = '0.png'
#print path+filename
img_list.append(Image.open(path + filename))
# shoes
img_list.append(Image.open('shoes/1.png'))
# then merge all!
f = Image.new('RGBA', img_list[0].size, 'black')
for i in xrange(len(img_list)):
f = Image.alpha_composite(f, img_list[i].convert('RGBA'))
# save image
f.save('0.png')
i = 4
j_list = [9, 10, 11, 1, 2, 3, 13, 14, 15]
images = []
for j in j_list:
images.append(cut_image(i, j))
widths, heights = zip(*(i.size for i in images))
total_width = sum(widths)
max_height = max(heights)
new_im = Image.new('RGB', (total_width, max_height))
x_offset = 0
for im in images:
new_im.paste(im, (x_offset,0))
x_offset += im.size[0]
new_im.save('actions.png')
os.remove('0.png')