add generate_multiscale_DF2K
This commit is contained in:
@@ -3,4 +3,5 @@ facexlib>=0.2.0.3
|
|||||||
gfpgan>=0.2.1
|
gfpgan>=0.2.1
|
||||||
numpy
|
numpy
|
||||||
opencv-python
|
opencv-python
|
||||||
|
Pillow
|
||||||
torch>=1.7
|
torch>=1.7
|
||||||
|
|||||||
46
scripts/generate_multiscale_DF2K.py
Normal file
46
scripts/generate_multiscale_DF2K.py
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import argparse
|
||||||
|
import glob
|
||||||
|
import os
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
|
def main(args):
|
||||||
|
|
||||||
|
# For DF2K, we consider the following three scales,
|
||||||
|
# and the smallest image whose shortest edge is 400
|
||||||
|
scale_list = [0.75, 0.5, 1 / 3]
|
||||||
|
shortest_edge = 400
|
||||||
|
|
||||||
|
path_list = sorted(glob.glob(os.path.join(args.input, '*')))
|
||||||
|
for path in path_list:
|
||||||
|
print(path)
|
||||||
|
basename = os.path.splitext(os.path.basename(path))[0]
|
||||||
|
|
||||||
|
img = Image.open(path)
|
||||||
|
width, height = img.size
|
||||||
|
for idx, scale in enumerate(scale_list):
|
||||||
|
print(f'\t{scale:.2f}')
|
||||||
|
rlt = img.resize((int(width * scale), int(height * scale)), resample=Image.LANCZOS)
|
||||||
|
rlt.save(os.path.join(args.output, f'{basename}T{idx}.png'))
|
||||||
|
|
||||||
|
# save the smallest image which the shortest edge is 400
|
||||||
|
if width < height:
|
||||||
|
ratio = height / width
|
||||||
|
width = shortest_edge
|
||||||
|
height = int(width * ratio)
|
||||||
|
else:
|
||||||
|
ratio = width / height
|
||||||
|
height = shortest_edge
|
||||||
|
width = int(height * ratio)
|
||||||
|
rlt = img.resize((int(width), int(height)), resample=Image.LANCZOS)
|
||||||
|
rlt.save(os.path.join(args.output, f'{basename}T{idx+1}.png'))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('--input', type=str, default='datasets/DF2K/DF2K_HR', help='Input folder')
|
||||||
|
parser.add_argument('--output', type=str, default='datasets/DF2K/DF2K_multiscale', help='Output folder')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
os.makedirs(args.output, exist_ok=True)
|
||||||
|
main(args)
|
||||||
@@ -17,6 +17,6 @@ line_length = 120
|
|||||||
multi_line_output = 0
|
multi_line_output = 0
|
||||||
known_standard_library = pkg_resources,setuptools
|
known_standard_library = pkg_resources,setuptools
|
||||||
known_first_party = realesrgan
|
known_first_party = realesrgan
|
||||||
known_third_party = basicsr,cv2,numpy,torch
|
known_third_party = PIL,basicsr,cv2,numpy,torch
|
||||||
no_lines_before = STDLIB,LOCALFOLDER
|
no_lines_before = STDLIB,LOCALFOLDER
|
||||||
default_section = THIRDPARTY
|
default_section = THIRDPARTY
|
||||||
|
|||||||
Reference in New Issue
Block a user