MCPcopy Create free account
hub / github.com/OpenTalker/StyleHEAT / computeColor

Function computeColor

utils/flow_util.py:142–175  ·  view source on GitHub ↗
(u, v)

Source from the content-addressed store, hash-verified

140
141
142def computeColor(u, v):
143 colorwheel = makeColorwheel()
144 nan_u = np.isnan(u)
145 nan_v = np.isnan(v)
146 nan_u = np.where(nan_u)
147 nan_v = np.where(nan_v)
148
149 u[nan_u] = 0
150 u[nan_v] = 0
151 v[nan_u] = 0
152 v[nan_v] = 0
153
154 ncols = colorwheel.shape[0]
155 radius = np.sqrt(u ** 2 + v ** 2)
156 a = np.arctan2(-v, -u) / np.pi
157 fk = (a + 1) / 2 * (ncols - 1) # -1~1 maped to 1~ncols
158 k0 = fk.astype(np.uint8) # 1, 2, ..., ncols
159 k1 = k0 + 1
160 k1[k1 == ncols] = 0
161 f = fk - k0
162
163 img = np.empty([k1.shape[0], k1.shape[1], 3])
164 ncolors = colorwheel.shape[1]
165 for i in range(ncolors):
166 tmp = colorwheel[:, i]
167 col0 = tmp[k0] / 255
168 col1 = tmp[k1] / 255
169 col = (1 - f) * col0 + f * col1
170 idx = radius <= 1
171 col[idx] = 1 - radius[idx] * (1 - col[idx]) # increase saturation with radius
172 col[~idx] *= 0.75 # out of range
173 img[:, :, 2 - i] = np.floor(255 * col).astype(np.uint8)
174
175 return img.astype(np.uint8)
176
177
178def vis_flow(flow):

Callers 1

vis_flowFunction · 0.85

Calls 1

makeColorwheelFunction · 0.85

Tested by

no test coverage detected