MCPcopy Create free account
hub / github.com/PaddlePaddle/Research / flow_compute_color

Function flow_compute_color

CV/PWCNet/src/flow_vis.py:68–110  ·  view source on GitHub ↗

Applies the flow color wheel to (possibly clipped) flow components u and v. According to the C++ source code of Daniel Scharstein According to the Matlab source code of Deqing Sun :param u: np.ndarray, input horizontal flow :param v: np.ndarray, input vertical flow :param

(u, v, convert_to_bgr=False)

Source from the content-addressed store, hash-verified

66
67
68def flow_compute_color(u, v, convert_to_bgr=False):
69 '''
70 Applies the flow color wheel to (possibly clipped) flow components u and v.
71
72 According to the C++ source code of Daniel Scharstein
73 According to the Matlab source code of Deqing Sun
74
75 :param u: np.ndarray, input horizontal flow
76 :param v: np.ndarray, input vertical flow
77 :param convert_to_bgr: bool, whether to change ordering and output BGR instead of RGB
78 :return:
79 '''
80
81 flow_image = np.zeros((u.shape[0], u.shape[1], 3), np.uint8)
82
83 colorwheel = make_colorwheel() # shape [55x3]
84 ncols = colorwheel.shape[0]
85
86 rad = np.sqrt(np.square(u) + np.square(v))
87 a = np.arctan2(-v, -u)/np.pi
88
89 fk = (a+1) / 2*(ncols-1)
90 k0 = np.floor(fk).astype(np.int32)
91 k1 = k0 + 1
92 k1[k1 == ncols] = 0
93 f = fk - k0
94
95 for i in range(colorwheel.shape[1]):
96
97 tmp = colorwheel[:,i]
98 col0 = tmp[k0] / 255.0
99 col1 = tmp[k1] / 255.0
100 col = (1-f)*col0 + f*col1
101
102 idx = (rad <= 1)
103 col[idx] = 1 - rad[idx] * (1-col[idx])
104 col[~idx] = col[~idx] * 0.75 # out of range?
105
106 # Note the 2-i => BGR instead of RGB
107 ch_idx = 2-i if convert_to_bgr else i
108 flow_image[:,:,ch_idx] = np.floor(255 * col)
109
110 return flow_image
111
112
113def flow_to_color(flow_uv, clip_flow=None, convert_to_bgr=False):

Callers 1

flow_to_colorFunction · 0.85

Calls 1

make_colorwheelFunction · 0.85

Tested by

no test coverage detected