-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompress_images.py
More file actions
31 lines (28 loc) · 1.03 KB
/
compress_images.py
File metadata and controls
31 lines (28 loc) · 1.03 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
30
31
from PIL import Image, ImageFilter
from tqdm import tqdm
import glob, os
paths=['RAIN_DATASET/ALIGNED_PAIRS/CG_DROPLETS/',
'RAIN_DATASET/ALIGNED_PAIRS/CLEAN/',
'RAIN_DATASET/ALIGNED_PAIRS/REAL_DROPLETS/',
'RAIN_DATASET/LABELLED/LABELLED_CG_RAIN_INPUTS/',
'RAIN_DATASET/LABELLED/LABELLED_CLEAR_INPUTS/',
'RAIN_DATASET/LABELLED/LABELLED_MASKS/',
'RAIN_DATASET/LABELLED/LABELLED_REAL_RAIN_INPUTS/']
size=540,480
for path in paths:
print(path)
new_path='RAIN_DATASET_COMPRESSED'+path[12:]
if not os.path.exists(new_path):
os.makedirs(new_path)
for file in tqdm(glob.glob(path+'*.png')):
im=Image.open(file)
# if im.size != (776,690):
# print(im.size)
im.thumbnail(size)
new_file='RAIN_DATASET_COMPRESSED'+file[12:]
split=new_file.split('/')
split[-1]=split[-1].split('_')[-1]
new_file='/'.join(split)
new_file=new_file[:-3]+'jpg'
# we remove the 'left_' or 'right' in the file
im.save(new_file,'JPEG')