-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLandmarks_Resize_Images.py
45 lines (31 loc) · 1.27 KB
/
Landmarks_Resize_Images.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
""" Script to rescale images in a folder """
from PIL import Image
import os
# directories of the images to be rescaled
path = "./test/images/"
dirs = os.listdir( path )
# create new directorie for the folders of rescaled images
new_folder = "./test/images_resized/"
#for d in dirs:
# new_path = os.path.join(new_folder, d)
# try:
# os.mkdir(new_path)
# except OSError:
# print ("Creation of the directory %s failed" % new_path)
# else:
# print ("Successfully created the directory %s " % new_path)
def resize(h, w):
for item in dirs:
# create new subfolder for each set of rescaled images
new_path = os.path.join(new_folder, item)
# current path of the image to be rescaled
full_path = os.path.join(path, item)
files = os.listdir(full_path)
for file in files:
file_path = full_path + '/' + file
im = Image.open(file_path)
imResize = im.resize((h, w), Image.ANTIALIAS)
# input path to the new directory
imResize.save(new_path + '/' + file, 'JPEG', quality = 90)
print(file + ' resized and saved')
resize(300, 300)