MCPcopy Create free account
hub / github.com/LoSealL/VideoSuperResolution / upsample

Function upsample

VSR/Util/Utility.py:154–205  ·  view source on GitHub ↗
(img, scale)

Source from the content-addressed store, hash-verified

152
153
154def upsample(img, scale):
155 scale = to_list(scale, 2)
156 with tf.name_scope('UpsampleX{}'.format(scale[0])):
157 shape = img.shape
158 imgx = tf.pad(img, [[0, 0], [1, 1], [0, 0], [0, 0]], "CONSTANT")
159 imgx = tf.pad(imgx, [[0, 0], [0, 1], [0, 0], [0, 0]], "CONSTANT")
160 dh = [(i + 0.5) / scale[1] for i in range(scale[1])]
161 dw = [(i + 0.5) / scale[0] for i in range(scale[0])]
162 ph, pw = [], []
163 for d in dh:
164 _v = np.array([-1, 0, 1, 2], np.float32) - d + 0.5
165 if d < 0.5:
166 _v[-1] = 2
167 else:
168 _v[0] = 2
169 _k = np.asarray([_bicubic_filter(v) for v in _v], np.float32)
170 _k /= np.sum(_k) + 1e-12
171 _k = _k.reshape([4, 1, 1])
172 if shape[-1] == 3:
173 zero = tf.zeros_like(_k)
174 _r = tf.concat([_k, zero, zero], -1)
175 _g = tf.concat([zero, _k, zero], -1)
176 _b = tf.concat([zero, zero, _k], -1)
177 _k = tf.stack([_r, _g, _b], -1)
178 else:
179 _k = tf.expand_dims(_k, -1)
180 ph += [tf.nn.conv2d(imgx, _k, (1, 1, 1, 1), 'VALID', name='Hori')]
181 img = pixel_shift(tf.concat(ph, -1), [1, scale[1]], shape[-1])
182 img = tf.round(img)
183 imgx = tf.pad(img, [[0, 0], [0, 0], [1, 1], [0, 0]], "CONSTANT")
184 imgx = tf.pad(imgx, [[0, 0], [0, 0], [0, 1], [0, 0]], "CONSTANT")
185 for d in dw:
186 _v = np.array([-1, 0, 1, 2], np.float32) - d + 0.5
187 if d < 0.5:
188 _v[-1] = 2
189 else:
190 _v[0] = 2
191 _k = np.asarray([_bicubic_filter(v) for v in _v], np.float32)
192 _k /= np.sum(_k) + 1e-12
193 _k = _k.reshape([4, 1, 1])
194 if shape[-1] == 3:
195 zero = tf.zeros_like(_k)
196 _r = tf.concat([_k, zero, zero], -1)
197 _g = tf.concat([zero, _k, zero], -1)
198 _b = tf.concat([zero, zero, _k], -1)
199 _k = tf.stack([_r, _g, _b], -1)
200 else:
201 _k = tf.expand_dims(_k, -1)
202 _k = tf.transpose(_k, [1, 0, 2, 3])
203 pw += [tf.nn.conv2d(imgx, _k, (1, 1, 1, 1), 'VALID', name='Vert')]
204 img = pixel_shift(tf.concat(pw, -1), [scale[0], 1], shape[-1])
205 return tf.round(img)
206
207
208def prelu(x, initialize=0, name=None, scope='PReLU'):

Callers

nothing calls this directly

Calls 4

to_listFunction · 0.85
_bicubic_filterFunction · 0.85
pixel_shiftFunction · 0.85
conv2dMethod · 0.45

Tested by

no test coverage detected