2023年7月3日发(作者:)
超分辨率测试集处理(基于插值下采样)测试集⽣成代码样例基于Set5 测试集 其他测试集类似。在超分辨率训练集的训练过程中,为了节省训练时间,通常将训练集按照倍率提前⽣成。⽅案1.原图剪切:为了使得缩放后的图像与原图像保持像素上的⼀⼀对应关系,因此需要将原图的w,h 都能被缩放因⼦整除。⼀般超分辨率的缩放因⼦设置为【2,3,4,8】.所以提取最⼩公倍数 24.原图需要被剪切为w,h都能被24整除。图像剪切:在这⾥使⽤的orms 包。代码from os import listdirfrom import joinfrom orms import Compose, CenterCrop, Resizefrom PIL import Imageimport osdef is_imagefile(image): return any(th(extension) for extension in ['.png', '.jpg', '.jpeg', '.PNG', '.JPG', '.JPEG','bmp','BMP'])def calculate_valid_crop_size(crop_size,upscale_factor): return crop_size - (crop_size % upscale_factor)def hr_transform(crop_size): return Compose([ CenterCrop(crop_size), ])def lr_transform(crop_size): return Compose([ Resize(crop_size, interpolation=C), ])def produce_image(data_dir,scale): filename = [join(data_dir, x) for x in listdir(data_dir) if is_imagefile(x)] for x in filename: images_name = ('/')[-1] images_name = images_('.')[0] x_image = (x) (w,h) = x_ print(w,h) nw = calculate_valid_crop_size(w,24) nh = calculate_valid_crop_size(h,24) hr_size = hr_transform((nh,nw)) x_image = hr_size(x_image) print(x_image) save_image(x_image,scale,images_name)def save_image(x_image,scale,images_name): output_lr_dir = 'TestDataSR/Set5/LR' output_hr_dir = 'TestDataSR/Set5/HR' x_((output_hr_dir,images_name + '.bmp')) for s in scale: rs( (output_lr_dir,'X{}'.format(s)), exist_ok= True ) path = (output_lr_dir,'X{}'.format(s) + '/' + images_name + '_X{}'.format(s) + '.bmp') (nw,nh) = x_ lr_size = lr_transform((nh // s, nw // s)) xr_image = lr_size(x_image) xr_(path)data_dir = 'TestDataSR/Set5'scale = [2,3,4,8]produce_image(data_dir,scale)
发布者:admin,转转请注明出处:http://www.yc00.com/news/1688383170a129775.html
评论列表(0条)