Example #1
0
def make_patches(hr_image, lr_image, scale, resize):
    hr_image = tf.stack(flip([hr_image]))
    lr_image = tf.stack(flip([lr_image]))
    hr_image = util.crop_by_pixel(hr_image, 12)
    lr_image = util.crop_by_pixel(lr_image, 12 / scale)
    hr_patches = util.image_to_patches(hr_image)
    if resize:
        lr_image = util.resize_func(lr_image, tf.shape(hr_image)[1:3])
        lr_patches = util.image_to_patches(lr_image)
    else:
        lr_patches = util.image_to_patches(lr_image, scale)
    return hr_patches, lr_patches
Example #2
0
 with open(FLAGS.hr_flist) as f:
     hr_filename_list = f.read().splitlines()
 with open(FLAGS.lr_flist) as f:
     lr_filename_list = f.read().splitlines()
 filename_queue = tf.train.string_input_producer(lr_filename_list,
                                                 num_epochs=2,
                                                 shuffle=False)
 reader = tf.WholeFileReader()
 _, image_file = reader.read(filename_queue)
 lr_image = tf.image.decode_image(image_file, channels=3)
 lr_image = tf.image.convert_image_dtype(lr_image, tf.float32)
 lr_image = tf.expand_dims(lr_image, 0)
 lr_image_shape = tf.shape(lr_image)[1:3]
 hr_image_shape = lr_image_shape * FLAGS.scale
 if (data.resize):
     lr_image = util.resize_func(lr_image, hr_image_shape)
     lr_image = tf.reshape(lr_image,
                           [1, hr_image_shape[0], hr_image_shape[1], 3])
 else:
     lr_image = tf.reshape(lr_image,
                           [1, lr_image_shape[0], lr_image_shape[1], 3])
 lr_image_padded = util.pad_boundary(lr_image)
 hr_image = model.build_model(lr_image_padded - 0.5,
                              FLAGS.scale,
                              training=False,
                              reuse=False)
 hr_image = util.crop_center(hr_image, hr_image_shape)
 if (data.residual):
     if (data.resize):
         hr_image += lr_image
     else:
Example #3
0
def make_residual(hr_image, lr_image):
    hr_image = tf.expand_dims(hr_image, 0)
    lr_image = tf.expand_dims(lr_image, 0)
    hr_image_shape = tf.shape(hr_image)[1:3]
    res_image = hr_image - util.resize_func(lr_image, hr_image_shape)
    return tf.reshape(res_image, [hr_image_shape[0], hr_image_shape[1], 3])