超分辨率中根据原图生成测试集(低分辨图或高分辨图)

超分辨率生成训练图片代码

 1 from PIL import Image
 2 import os
 3 import cv2
 4 def produceImage(file_in, width, height, file_out):
 5     image = Image.open(file_in)
 6     resized_image = image.resize((width, height), Image.ANTIALIAS)
 7 
 8     resized_image.save(file_out)
 9 
10 if __name__ == '__main__':
11 
12     #该路径为原图路径
13     path=r"H:\jianfeng\project\super_resolution\dataset\urban100_img\X3"
14     #该路径为保存路径
15     save=r"H:\jianfeng\project\super_resolution\dataset\urban100_img\X3_HR"
16     fileList = os.listdir(path)
17 
18     for i in fileList:
19         a=os.path.join(path,i)
20 
21         pic = cv2.imread(a)
22 
23         width = pic.shape[1]
24         height = pic.shape[0]
25         #修改你要转换的分辨率 这里需要将分辨率乘以三倍,如果需要降低4倍则width//4,height//4
26         #遇到除不尽情况,会自动规整,需要再做一次还原操作,
27         # 比如降低3倍后1024-->341 需要在将341图片乘以三倍重新生成1023作为HR图
28         produceImage(a, width*3, height*3, os.path.join(save,i))

猜你喜欢

转载自www.cnblogs.com/bob-jianfeng/p/11872270.html
今日推荐