-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimagesToSingle.py
24 lines (22 loc) · 944 Bytes
/
imagesToSingle.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
import numpy as np
import glob
from PIL import Image
initialPath = "./mnist_dcgan_dcgan/images/"
for k in range(1, 101):
imageFolderPath = initialPath + "epoch_{}".format(k)
print(imageFolderPath)
list_im = glob.glob(imageFolderPath + '/image_*.png')
imgs = [Image.open(i) for i in list_im]
# pick the image which is the smallest, and resize the others to match it (can be arbitrary image shape here)
min_shape = sorted([(np.sum(i.size), i.size) for i in imgs[:10]])[0][1]
prevRows = None
for j in range(4):
imgs_comb = np.hstack((np.asarray(i.resize(min_shape))
for i in imgs[10*j:10*(j+1)]))
if prevRows is None:
prevRows = imgs_comb
else:
prevRows = np.vstack((prevRows, imgs_comb))
# save that beautiful picture
imgs_comb = Image.fromarray(prevRows)
imgs_comb.save(initialPath + "epoch_{}/fullarray.png".format(k))