从文件夹读取数据
import argparse
import PIL.Image as pil_image
from PIL import Image
import random
import os
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 random_crop(image, 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 dataset(args):
flip = [0]
count = 0
pathlist = os.listdir(args.input_path)
if not os.path.exists(args.output_path):
os.mkdir(args.output_path)
for image_name in pathlist:
hr = Image.open(os.path.join(args.inp