-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_numpy.py
63 lines (46 loc) · 1.53 KB
/
make_numpy.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
import glob
import matplotlib.pyplot as plt
import numpy as np
import PIL.Image as pilimg
shape = 28
def x2numpy(directory, name):
images = glob.glob(directory + '/*.jpg')
np_image = []
for fname in images:
im = pilimg.open(fname)
im = im.resize((shape,shape))
img = np.array(im)
img = img.reshape(img.shape[0], img.shape[1], 1)
np_image.append(img)
np_image = np.array(np_image)
print('x shape: ', np_image.shape)
np.save('D:/' + name + ".npy", np_image)
print('saved')
def y2numpy(directory, name):
images = glob.glob(directory + '/*.jpg')
np_image = []
for fname in images:
im = pilimg.open(fname)
im = im.resize((shape,shape))
img = np.array(im)
img = img.reshape(img.shape[0], img.shape[1], 1)
for i in range(10):
np_image.append(img)
np_image = np.array(np_image)
print('y shape: ', np_image.shape)
np.save('D:/' + name + ".npy", np_image)
print('saved')
def image2numpy(directory):
im = pilimg.open('./lsm3.jpg')
im = im.resize((shape,shape)).convert('L')
img = np.array(im)
print(img.shape)
img = img.reshape(img.shape[0], img.shape[1], 1)
print('x shape: ', img.shape)
np.save("lsm64.npy", img)
print('saved')
x2numpy('D:/Bitcamp/Project/Frontalization/Numpy/X_10_per_person/', 'X_10_per_person')
y2numpy('D:/Bitcamp/Project/Frontalization/Numpy/Y_10_per_person/', 'Y_10_per_person')
# image2numpy('aa')
# numpy_image('x_test')
# numpy_image('y_test')