MCPcopy Create free account
hub / github.com/drinkingcoder/NeuralMarker / flow_to_image

Function flow_to_image

core/utils/flow_viz.py:109–132  ·  view source on GitHub ↗

Expects a two dimensional flow image of shape. Args: flow_uv (np.ndarray): Flow UV image of shape [H,W,2] clip_flow (float, optional): Clip maximum of flow values. Defaults to None. convert_to_bgr (bool, optional): Convert output image to BGR. Defaults to False.

(flow_uv, clip_flow=None, convert_to_bgr=False)

Source from the content-addressed store, hash-verified

107
108
109def flow_to_image(flow_uv, clip_flow=None, convert_to_bgr=False):
110 """
111 Expects a two dimensional flow image of shape.
112
113 Args:
114 flow_uv (np.ndarray): Flow UV image of shape [H,W,2]
115 clip_flow (float, optional): Clip maximum of flow values. Defaults to None.
116 convert_to_bgr (bool, optional): Convert output image to BGR. Defaults to False.
117
118 Returns:
119 np.ndarray: Flow visualization image of shape [H,W,3]
120 """
121 assert flow_uv.ndim == 3, 'input flow must have three dimensions'
122 assert flow_uv.shape[2] == 2, 'input flow must have shape [H,W,2]'
123 if clip_flow is not None:
124 flow_uv = np.clip(flow_uv, 0, clip_flow)
125 u = flow_uv[:,:,0]
126 v = flow_uv[:,:,1]
127 rad = np.sqrt(np.square(u) + np.square(v))
128 rad_max = np.max(rad)
129 epsilon = 1e-5
130 u = u / (rad_max + epsilon)
131 v = v / (rad_max + epsilon)
132 return flow_uv_to_colors(u, v, convert_to_bgr)

Callers

nothing calls this directly

Calls 1

flow_uv_to_colorsFunction · 0.85

Tested by

no test coverage detected