-
Notifications
You must be signed in to change notification settings - Fork 0
/
stitch_result.py
83 lines (73 loc) · 4.33 KB
/
stitch_result.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import PIL.Image as Image
import os
IMAGES_PATH_original = './data/ori_test/'
IMAGES_PATH_masked_ori = './data/masked_pic_test/'
IMAGES_PATH_masked_ce = './results/context_encoder_input/'
IMAGES_PATH_bak = './results/background/'
IMAGES_PATH_context_enc = './results/context_encoder/'
IMAGES_PATH_GLCIC = './results/GLCIC/'
IMAGES_PATH_attention = './results/contextual_attention/'
IMAGES_PATH_ours = './results/proposed/'
IMAGES_FORMAT = ['.jpg', '.JPG', '.png', '.PNG']
IMAGE_SIZE = 128
IMAGE_ROW = 6
IMAGE_COLUMN = 7
IMAGE_SAVE_PATH = './results/final.jpg'
# get all pics
image_names_ori = [name for name in os.listdir(IMAGES_PATH_original) for item in IMAGES_FORMAT if
os.path.splitext(name)[1] == item]
image_names_masked_ce = [name for name in os.listdir(IMAGES_PATH_masked_ori) for item in IMAGES_FORMAT if
os.path.splitext(name)[1] == item]
image_names_masked_ori = [name for name in os.listdir(IMAGES_PATH_masked_ori) for item in IMAGES_FORMAT if
os.path.splitext(name)[1] == item]
image_names_bak = [name for name in os.listdir(IMAGES_PATH_bak) for item in IMAGES_FORMAT if
os.path.splitext(name)[1] == item]
image_names_context_enc = [name for name in os.listdir(IMAGES_PATH_context_enc) for item in IMAGES_FORMAT if
os.path.splitext(name)[1] == item]
image_names_GLCIC = [name for name in os.listdir(IMAGES_PATH_GLCIC) for item in IMAGES_FORMAT if
os.path.splitext(name)[1] == item]
image_names_attention = [name for name in os.listdir(IMAGES_PATH_attention) for item in IMAGES_FORMAT if
os.path.splitext(name)[1] == item]
image_names_ours = [name for name in os.listdir(IMAGES_PATH_ours) for item in IMAGES_FORMAT if
os.path.splitext(name)[1] == item]
# compose function
def image_compose():
to_image = Image.new('RGB', (IMAGE_COLUMN * IMAGE_SIZE, IMAGE_ROW * IMAGE_SIZE)) # create a big picture
# iterativelly search for pic to compose
for y in range(1, IMAGE_ROW + 1):
for x in range(1, IMAGE_COLUMN + 1):
if y == 1:
from_image = Image.open(IMAGES_PATH_bak + str(x) + '.png').resize(
(IMAGE_SIZE, IMAGE_SIZE),Image.ANTIALIAS)
to_image.paste(from_image, ((x - 1) * IMAGE_SIZE, (y - 1) * IMAGE_SIZE))
else:
if x == 1:
from_image = Image.open(IMAGES_PATH_original + image_names_ori[y+4]).resize(
(IMAGE_SIZE, IMAGE_SIZE),Image.ANTIALIAS)
to_image.paste(from_image, ((x - 1) * IMAGE_SIZE, (y - 1) * IMAGE_SIZE))
elif x == 2:
from_image = Image.open(IMAGES_PATH_masked_ce + image_names_masked_ce[y+4]).resize(
(IMAGE_SIZE, IMAGE_SIZE),Image.ANTIALIAS)
to_image.paste(from_image, ((x - 1) * IMAGE_SIZE, (y - 1) * IMAGE_SIZE))
elif x == 3:
from_image = Image.open(IMAGES_PATH_context_enc + image_names_context_enc[y+4]).resize(
(IMAGE_SIZE, IMAGE_SIZE),Image.ANTIALIAS)
to_image.paste(from_image, ((x - 1) * IMAGE_SIZE, (y - 1) * IMAGE_SIZE))
elif x == 4:
from_image = Image.open(IMAGES_PATH_masked_ori + image_names_masked_ori[y+4]).resize(
(IMAGE_SIZE, IMAGE_SIZE),Image.ANTIALIAS)
to_image.paste(from_image, ((x - 1) * IMAGE_SIZE, (y - 1) * IMAGE_SIZE))
elif x == 5:
from_image = Image.open(IMAGES_PATH_GLCIC + image_names_GLCIC[y+4]).resize(
(IMAGE_SIZE, IMAGE_SIZE),Image.ANTIALIAS)
to_image.paste(from_image, ((x - 1) * IMAGE_SIZE, (y - 1) * IMAGE_SIZE))
elif x == 6:
from_image = Image.open(IMAGES_PATH_attention + image_names_attention[y+4]).resize(
(IMAGE_SIZE, IMAGE_SIZE),Image.ANTIALIAS)
to_image.paste(from_image, ((x - 1) * IMAGE_SIZE, (y - 1) * IMAGE_SIZE))
elif x == 7:
from_image = Image.open(IMAGES_PATH_ours + image_names_ours[y+4]).resize(
(IMAGE_SIZE, IMAGE_SIZE),Image.ANTIALIAS)
to_image.paste(from_image, ((x - 1) * IMAGE_SIZE, (y - 1) * IMAGE_SIZE))
return to_image.save(IMAGE_SAVE_PATH)
image_compose()