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

Function warp

VSR/Framework/Motion.py:156–189  ·  view source on GitHub ↗

warp the image with flow(u, v) If flow=[u, v], representing motion from img1 to img2 then `warp(img2, u, v)->img1~` Args: image: a 4-D tensor [B, H, W, C], images to warp u: horizontal motion vectors of optical flow v: vertical motion vectors of optical flow addit

(image, u, v, additive_warp=True, normalized=False)

Source from the content-addressed store, hash-verified

154
155
156def warp(image, u, v, additive_warp=True, normalized=False):
157 """warp the image with flow(u, v)
158
159 If flow=[u, v], representing motion from img1 to img2
160 then `warp(img2, u, v)->img1~`
161
162 Args:
163 image: a 4-D tensor [B, H, W, C], images to warp
164 u: horizontal motion vectors of optical flow
165 v: vertical motion vectors of optical flow
166 additive_warp: a boolean, if False, regard [u, v]
167 as destination coordinate rather than motion
168 vectors.
169 normalized: a boolean, if True, regard [u, v] as
170 [-1, 1] and scaled to [-W, W], [-H, H] respectively.
171
172 Note: usually nobody uses a normalized optical flow...
173 """
174 shape = tf.shape(image)
175 b, h, w = shape[0], shape[1], shape[2]
176
177 if normalized:
178 if not additive_warp:
179 u = (u + 1) * 0.5
180 v = (v + 1) * 0.5
181 u *= tf.to_float(w)
182 v *= tf.to_float(h)
183
184 if additive_warp:
185 grids = _grid(w, h, dtype=tf.float32)
186 u += grids[..., 1]
187 v += grids[..., 0]
188
189 return _sample(image, u, v)
190
191
192def epe(label, predict):

Callers 1

_meMethod · 0.90

Calls 3

_gridFunction · 0.85
_sampleFunction · 0.85
shapeMethod · 0.45

Tested by

no test coverage detected