资源简介
1. 根据给定的模糊图像生成视觉上完整并且统计上一致的去模糊图像,提升模糊图像的清晰度,使用生成性对抗网络(GAN)为基础的深度学习架构;
2. 含训练数据、训练代码以及测试样例,基于keras框架。
代码片段和文件信息
import glob as gb
import os
import h5py
import numpy as np
from PIL import Image
from tqdm import tqdm
# normalization x to [-11]
def normalization(x):
return x / 127.5 - 1
# according the image path to read the image and covert it
# to the given size then slice it finally return the full and blur images
def format_image(image_path size):
image = Image.open(image_path)
# slice image into full and blur images
image_full = image.crop((0 0 image.size[0] / 2 image.size[1]))
# Note the full image in left the blur image in right
image_blur = image.crop((image.size[0] / 2 0 image.size[0] image.size[1]))
# image_full.show()
# image_blur.show()
image_full = image_full.resize((size size) Image.ANTIALIAS)
image_blur = image_blur.resize((size size) Image.ANTIALIAS)
# return the numpy arrays
return np.array(image_full) np.array(image_blur)
# convert images to hdf5 data
def build_hdf5(jpeg_dir size=256):
# put data in HDF5
hdf5_file = os.path.join(‘data‘ ‘data.h5‘)
with h5py.File(hdf5_file ‘w‘) as f:
for data_type in tqdm([‘train‘ ‘test‘] desc=‘create HDF5 dataset from images‘):
data_path = jpeg_dir + ‘/%s/*.jpg‘ % data_type
images_path = gb.glob(data_path)
# print(images_path)
data_full = []
data_blur = []
for image_path in images_path:
image_full image_blur = format_image(image_path size)
data_full.append(image_full)
data_blur.append(image_blur)
# print(len(data_full))
# print(len(data_blur))
f.create_dataset(‘%s_data_full‘ % data_type data=data_full)
f.create_dataset(‘%s_data_blur‘ % data_type data=data_blur)
# load data by data type
def load_data(data_type):
with h5py.File(‘data/data.h5‘ ‘r‘) as f:
data_full = f[‘%s_data_full‘ % data_type][:].astype(np.float32)
data_full = normalization(data_full)
data_blur = f[‘%s_data_blur‘ % data_type][:].astype(np.float32)
data_blur = normalization(data_blur)
return data_full data_blur
def generate_image(full blur generated path epoch=None index=None):
full = full * 127.5 + 127.5
blur = blur * 127.5 + 127.5
generated = generated * 127.5 + 127.5
for i in range(generated.shape[0]):
image_full = full[i : : :]
image_blur = blur[i : : :]
image_generated = generated[i : : :]
image = np.concatenate((image_full image_blur image_generated) axis=1)
if (epoch is not None) and (index is not None):
Image.fromarray(image.astype(np.uint8)).save(path + str(epoch + 1) + ‘_‘ + str(index + 1) + ‘.png‘)
else:
Image.fromarray(image.astype(np.uint8)).save(path + str(i) + ‘.png‘)
if __name__ == ‘__main__‘:
# format_image(‘data/small/test/301.jpg‘ size=256)
build_hdf5(‘data/small‘)
img_full img_blur = loa
相关资源
-
Hollow fibre ba
sed Liquid-liquid-liquid mic - GAN对抗式生成网络的应用:从图片上
- 使用基于Neganov–Luke效应的光探测
- 台湾大学李宏毅——超详细GAN对抗神
- +GaN与SiC新型功率器件
-
A triphenylamine-ba
sed four-armed molecule - Electron mobility in strained wurtzite AlGaN/G
- Modeling of rapeseed at maturity stage using 3
- 基于深度学习的链路预测
- Computer Organization and Design 5th ppt
- Computer Organization and Architecture 第8版答
- ACOUSTICS_1_General_Program_Organization.pdf
- Computer Organization and Design RISC-V Editio
-
ComputerOrganizationandem
beddedSystems.6E.p - spring sagan 源码
- cyclegan风格迁移
- 万字综述之生成对抗网络
- Ext Gantt甘特图最新2.07破解+中文包+范
- 计算机结构习题答案 Computer+Organizat
- 标准GAN的公式推导
- 日志分析工具loganalyzer-4.1.7+中文语言
- computer organization and design solution
- Wasserstein Gan(论文翻译)
- AT-GAN:A Generative Attack Model译文
- 计算机组成设计第三版答案 Computer+
- Computer Organization and Design 4th Ed答案
- 计算机结构习题答案 Computer+Organizat
- Computer Organization and Design The Hardware/
- 传感器与检测技术课后习题解析
- GANs的崛起
评论
共有 条评论