import argparse
import glob
import h5py
import numpy as np
import PIL.Image as pil_image
from utils import calc_patch_size, convert_rgb_to_y
from PIL import Image
import random
import os
def random_crop(image, crop_shape):
###image 是pil读取的,crop_shape是裁剪的大小
nw = random.randint(0, image.size[0] - crop_shape[0]) ##裁剪图像在原图像中的坐标
nh = random.randint(0, image.size[1] - crop_shape[1])
image_crop = image.crop((nh, nw, nh + crop_shape[0], nw + crop_shape[1]))
return image_crop
def convert_rgb_to_y(img, dim_order='hwc'):
if dim_order == 'hwc':
return 16. + (64.738 * img[..., 0] + 129.057 * img[..., 1] + 25.064 * img[..., 2]) / 256.
else:
return 16. + (64.738 * img[0] + 129.057 * img[1] + 25.064 * img[2]) / 256.
def train(args):
h5_file = h5py.File(args.output_path, 'w')
lr_patches = []
hr_patches = []
深度学习超分辨率数据处理代码(包含数据增强,随机裁剪,最终保存为h5文件)
于 2022-09-07 21:23:02 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)