forked from JasonGUTU/TorchTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BatchResize.py
executable file
·65 lines (48 loc) · 1.66 KB
/
BatchResize.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
import os
import argparse
from PIL import Image
from DataTools.FileTools import _video_image_file, _image_file
from Functions.functional import resize
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--input', type=str, default='/home/sensetime/Documents/NTIRE2019/SRdata/Train_GT_down')
parser.add_argument('-o', '--output', type=str, default='/home/sensetime/Documents/NTIRE2019/SRdata/Train_GT_bicubic')
parser.add_argument('-s', '--scala', type=int, default=4)
parser.add_argument('-v', type=bool, default=False)
parser.add_argument('--up', type=bool, default=True)
args = parser.parse_args()
input_path = os.path.abspath(args.input)
output_path = os.path.abspath(args.output)
if args.up:
scala = 1 / args.scala
else:
scala = args.scala
V = args.v
def make_dir(input, output):
dirs = os.listdir(input)
os.mkdir(output)
for i in dirs:
os.mkdir(os.path.join(output, i))
def resize_and_save(file_org, output, scala):
im = Image.open(file_org)
w, h = im.size
im = resize(im, (int(h // scala), int(w // scala)))
name = os.path.split(file_org)
vdir = os.path.split(name[0])
if V:
save_name = os.path.join(output, vdir[1])
save_name = os.path.join(save_name, name[1])
else:
save_name = os.path.join(output, name[1])
im.save(save_name)
print(save_name)
if V:
file_list = _video_image_file(input_path)
make_dir(input_path, output_path)
for j in file_list:
for i in j:
resize_and_save(i, output_path, scala)
else:
file_list = _image_file(input_path)
os.mkdir(output_path)
for i in file_list:
resize_and_save(i, output_path, scala)