-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
84 lines (70 loc) · 2.41 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
83
84
import tensorflow as tf
import tensorlayer as tl
from tensorlayer.prepro import crop, imresize
# from config import config, log_config
#
# img_path = config.TRAIN.img_path
from collections import defaultdict
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.
return x
def crop_sub_imgs_fn2(x, is_random=True):
x = crop(x, wrg=96, hrg=96, is_random=is_random)
x = x / (255. / 2.)
x = x - 1.
return x
def normalization_fn(x):
x = x / (255. / 2.)
x = x - 1.
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=[96, 96], interp='bicubic', mode=None)
x = x / (255. / 2.)
x = x - 1.
return x
def image_shuffle(train_img_list0,train_img_list1,train_img_list2,train_img_list3,train_img_list4,train_img_list5):
d=defaultdict(list)
for key in range(0,len(train_img_list0)):
d[key].append(train_img_list0[key])
k = list(d.keys())
np.random.shuffle(k)
img_shuffle_list0=[]
img_shuffle_list1=[]
img_shuffle_list2=[]
img_shuffle_list3=[]
img_shuffle_list4=[]
img_shuffle_list5=[]
for i in range(0,len(train_img_list0)):
k1=k[i]
list0=train_img_list0[k1]
img_shuffle_list0.append(list0)
for i in range(0,len(train_img_list1)):
k2=k[i]
list1=train_img_list1[k2]
img_shuffle_list1.append(list1)
for i in range(0,len(train_img_list2)):
k3=k[i]
list2=train_img_list2[k3]
img_shuffle_list2.append(list2)
for i in range(0,len(train_img_list3)):
k4=k[i]
list3=train_img_list3[k4]
img_shuffle_list3.append(list3)
for i in range(0,len(train_img_list4)):
k5=k[i]
list4=train_img_list4[k5]
img_shuffle_list4.append(list4)
for i in range(0,len(train_img_list5)):
k1=k[i]
list5=train_img_list5[k1]
img_shuffle_list5.append(list5)
return img_shuffle_list0,img_shuffle_list1,img_shuffle_list2,img_shuffle_list3,img_shuffle_list4,img_shuffle_list5