-
Notifications
You must be signed in to change notification settings - Fork 0
/
downsample_psfrgan.py
38 lines (27 loc) · 1.13 KB
/
downsample_psfrgan.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
import os
from tqdm import tqdm
from PIL import Image
from util.downsample_config import DownsampleConfig
from util.create import create_dataset
from util.common import batch_tensor_to_image, make_directories
if __name__ == '__main__':
config = DownsampleConfig(
filename='./config/downsample.json'
)
dataset = create_dataset(config)
lr_dir = os.path.join(config.dataset_base_path, 'lr')
hr_dir = os.path.join(config.dataset_base_path, 'hr')
make_directories([
lr_dir,
hr_dir
])
for i, data in tqdm(enumerate(dataset)):
print(f'[{i}/{len(dataset)}] Generate lr-hr images.')
high_res_images = batch_tensor_to_image(data['hr'])
low_res_images = batch_tensor_to_image(data['lr'])
image_paths = data['hr_path']
for j in range(len(high_res_images)):
saved_hr_image = Image.fromarray(high_res_images[j])
saved_hr_image.save(os.path.join(hr_dir, os.path.basename(image_paths[j])))
saved_lr_image = Image.fromarray(low_res_images[j])
saved_lr_image.save(os.path.join(lr_dir, os.path.basename(image_paths[j])))