-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpreDefogData.py
78 lines (62 loc) · 2.61 KB
/
preDefogData.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import argparse
import re
import os
import shutil
def get_arguments():
"""Parse the arguments from the command line.
Returns:
Parsed arguments
"""
parser = argparse.ArgumentParser(
description='Script for the preparation of dehaze dataset')
parser.add_argument('--clear_folder', default='ITS_v2/clear',
help='Folder with dehaze clear datasets')
parser.add_argument('--hazy_folder', default='ITS_v2/hazy',
help='Folder with dehaze hazy datasets')
return parser.parse_args()
def checkDir(dirPath):
if not os.path.exists(dirPath):
os.makedirs(dirPath)
def main():
args = get_arguments()
if not os.path.exists(args.clear_folder):
raise FileNotFoundError('Folder %s not found!' % args.dataset_folder)
if not os.path.exists(args.hazy_folder):
raise FileNotFoundError('Folder %s not found!' % args.dataset_folder)
norainDir_train = 'defog_dataset/train_datasets/norain'
rainDir_train = 'defog_dataset/train_datasets/rain/X2'
norainDir_test = 'defog_dataset/test_datasets/norain'
rainDir_test = 'defog_dataset/test_datasets/rain/X2'
checkDir('defog_dataset')
checkDir('defog_dataset/train_datasets')
checkDir('defog_dataset/test_datasets')
checkDir('defog_dataset/train_datasets/rain')
checkDir('defog_dataset/test_datasets/rain')
checkDir(norainDir_train)
checkDir(norainDir_test)
checkDir(rainDir_train)
checkDir(rainDir_test)
# prepare clear files for train and test
for clear_files in os.listdir(args.clear_folder):
oldname = os.path.join(args.clear_folder, clear_files)
for i in range(10):
j = i + 1
newfile=clear_files[0:len(clear_files)-4]+'_'+str(j)+'.png'
if (int)(clear_files.split('.')[0]) <= 1360:
newfile_path=os.path.join(norainDir_train,newfile)
else:
newfile_path=os.path.join(norainDir_test,newfile)
shutil.copyfile(oldname,newfile_path)
# prepare hazy files for train and test
for hazy_files in os.listdir(args.hazy_folder):
oldname = os.path.join(args.hazy_folder, hazy_files)
newfile = hazy_files[0: len(hazy_files) - len(hazy_files.split('_')[2]) - 1] + 'x2.png'
if (int)(hazy_files.split('_')[0]) <= 1360:
newname = os.path.join(rainDir_train, newfile)
else:
newname = os.path.join(rainDir_test, newfile)
shutil.copyfile(oldname,newname)
shutil.rmtree(args.clear_folder)
shutil.rmtree(args.hazy_folder)
if __name__ == '__main__':
main()