import argparse
import os
import glob
import torch
import PIL.Image as image
from tqdm import tqdm
parser = argparse.ArgumentParser()
parser.add_argument('--hr-path',type=str,default='/home/dushuai/word/superpixel_fcn-master/demo/inputs')
parser.add_argument('--lr-path',type=str,default='/home/dushuai/word/superpixel_fcn-master/demo/output')
parser.add_argument('--num',type = int,default=3)
parser.add_argument('--scale',type = int,default=2)
args = parser.parse_args()
if torch.cuda.is_available():
device = torch.device('cuda')
else:
device = torch.device('cpu')
if not os.path.exists(args.lr_path):
os.makedirs(args.lr_path)
def convert2lr(args):
with tqdm(total=args.num) as t:
for image_relative_name in os.listdir(args.hr_path):
image_path = os.path.join(args.hr_path,image_relative_name)
hr = image.open(image_path).convert('RGB')
hr_width = (hr.width//args.scale)*args.scale
hr_height = (hr.height//args.scale)*args.scale
hr = hr.resize((hr_width,hr_height),resample=image.BICUBIC)
lr = hr.resize((hr_width//args.scale,hr_height//args.scale),resample=image.BICUBIC)
lr = lr.resize((lr.width*args.scale,lr.height*args.scale),resample=image.BICUBIC)
lr.save('/home/dushuai/word/superpixel_fcn-master/demo/output/{}'.format(image_relative_name))
t.update()
if __name__ == '__main__':
convert2lr(args)