-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmergeImages.py
More file actions
33 lines (24 loc) · 923 Bytes
/
mergeImages.py
File metadata and controls
33 lines (24 loc) · 923 Bytes
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
#!/usr/bin/env python
# coding: utf-8
import numpy as np
from PIL import Image
from glob import glob
import numpy as np
def get_images(file_path, name):
imgs = []
for file in file_path:
img_file_path = glob(file +"/*.jpg")[np.random.randint(500)]
img = Image.open(img_file_path)
imgs.append(img)
merge_images(name + "1.jpg", imgs[:10])
merge_images(name + "2.jpg", imgs[10:])
def merge_images(file_name, imgs):
min_shape = sorted( [(np.sum(i.size), i.size ) for i in imgs])[0][1]
imgs_comb = np.hstack( (np.asarray( i.resize(min_shape) ) for i in imgs ) )
imgs_comb = np.vstack( (np.asarray( i.resize(min_shape) ) for i in imgs ) )
imgs_comb = Image.fromarray( imgs_comb)
imgs_comb.save(file_name)
train_files = glob("C:/Users/mbura/Desktop/EE492/Dataset/train/*")
test_files = glob("C:/Users/mbura/Desktop/EE492/Dataset/test/*")
get_images(train_files, "Train")
get_images(test_files, "Test")