-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
82 lines (74 loc) · 2.44 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# import tensorflow as tf
# import tensorlayer as tl
# from tensorlayer.prepro import *
# # from config import config, log_config
# #
# # img_path = config.TRAIN.img_path
#
# import scipy
# import numpy as np
#
# def get_imgs_fn(file_name, path):
# """ Input an image path and name, return an image array """
# # return scipy.misc.imread(path + file_name).astype(np.float)
# return scipy.misc.imread(path + file_name, mode='RGB')
#
# def crop_sub_imgs_fn(x, is_random=True):
# # x = crop(x, wrg=384, hrg=384, is_random=is_random)
# x = x / (255. / 2.)
# x = x - 1.
# # x = (x - 0.5)*2
# return x
#
# def downsample_fn(x):
# # We obtained the LR images by downsampling the HR images using bicubic kernel with downsampling factor r = 4.
# x = imresize(x, size=[128, 128], interp='bicubic', mode=None)
# x = x / (255. / 2.)
# x = x - 1.
# # x = (x - 0.5)*2
# return x
import tensorflow as tf
import tensorlayer as tl
from tensorlayer.prepro import *
from skimage import color
# from config import config, log_config
#
# img_path = config.TRAIN.img_path
import scipy
import numpy as np
def get_imgs_fn(file_name, path):
""" Input an image path and name, return an image array """
# return scipy.misc.imread(path + file_name).astype(np.float)
return scipy.misc.imread(path + file_name, mode='RGB')
def crop_sub_imgs_fn(x, is_random=True):
# x = crop(x, wrg=384, hrg=384, is_random=is_random)
if x.shape[2] == 4:
x = color.rgba2rgb(x)
if x.max() > 10:
x = x / (255. / 2.)
x = x - 1.
else:
x = x * 2 - 1
# x = (x - 0.5)*2
return x
def downsample_fn(x):
# We obtained the LR images by downsampling the HR images using bicubic kernel with downsampling factor r = 4.
x = imresize(x, size=[128, 128], interp='bicubic', mode=None)
x = x / (255. / 2.)
x = x - 1.
# x = (x - 0.5)*2
return x
def downsample_fn_3(x):
# We obtained the LR images by downsampling the HR images using bicubic kernel with downsampling factor r = 4.
x = imresize(x, size=[256, 256], interp='bicubic', mode=None)
x = x / (255. / 2.)
x = x - 1.
# x = (x - 0.5)*2
return x
def downsample_fn_2(x, size=128):
# We obtained the LR images by downsampling the HR images using bicubic kernel with downsampling factor r = 4.
x = imresize(x, size=[size, size], interp='bicubic', mode=None)
x = x / (255. / 2.)
x = x - 1.
# x = (x - 0.5)*2
return x