Create resize_image.py
Browse files- resize_image.py +22 -0
resize_image.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from PIL import Image
|
| 2 |
+
import os
|
| 3 |
+
from tqdm import tqdm
|
| 4 |
+
|
| 5 |
+
in_file = "E:\\data\\pokemon_classify\\images\\test\\"
|
| 6 |
+
out_file = "E:\\data\\pokemon_classify\\resize_image\\test\\"
|
| 7 |
+
|
| 8 |
+
dict_file = os.listdir(in_file)
|
| 9 |
+
|
| 10 |
+
def main(dict_file, in_file, out_file):
|
| 11 |
+
for file in tqdm(dict_file):
|
| 12 |
+
img = Image.open(in_file + file)
|
| 13 |
+
w,h = img.size
|
| 14 |
+
ratio = w/h
|
| 15 |
+
new_w = 640
|
| 16 |
+
new_h = int(new_w/ratio)
|
| 17 |
+
new_img = img.resize((new_w,new_h), Image.ANTIALIAS)
|
| 18 |
+
file = file[:-4] + '.jpg'
|
| 19 |
+
new_img.save(out_file + file, quality = 100)
|
| 20 |
+
|
| 21 |
+
if __name__ == '__main__':
|
| 22 |
+
main(dict_file, in_file, out_file)
|