-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_small_images.py
More file actions
30 lines (26 loc) · 1.15 KB
/
Copy pathcreate_small_images.py
File metadata and controls
30 lines (26 loc) · 1.15 KB
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
'''
This program resizes the facial images to be used as GUI buttons
'''
from PIL import Image
import pandas as pd
import my_func
from sklearn.model_selection import train_test_split
import numpy as np
def re_size(im, orig_size, fig_size, outfile):
'''read in the image array, convert to image and save the resized image'''
im = np.asarray(im, np.uint8)
im.resize(orig_size)
pil_im = Image.fromarray(im)
resized_im = pil_im.resize(fig_size)
resized_im.save(outfile)
if __name__ == '__main__':
data_ori = pd.read_csv(r"..\data\training.csv")
# use a subset of the data
data = data_ori.iloc[:200]
images = data.Image.map(my_func.str_split) # Transfer Image into arrays
data = data.drop('Image', 1)
data_pos = data[['left_eye_center_x', 'left_eye_center_y', 'right_eye_center_x', 'right_eye_center_y']]
images_train, images_test, data_pos_train, data_pos_test = train_test_split(images, data_pos, test_size = 0.2, random_state = 312)
for i in range(images_test.shape[0]):
im = images_test.iloc[i]
re_size(im, (96, 96), (60, 60), outfile=r"..\figures\small_images\image_{}.png".format(i))