MCPcopy Create free account
hub / github.com/UVA-Computer-Vision-Lab/FrameINO / flow_to_image

Function flow_to_image

utils/optical_flow_utils.py:93–118  ·  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

91
92
93def flow_to_image(flow_uv, clip_flow=None, convert_to_bgr=False):
94 """
95 Expects a two dimensional flow image of shape.
96
97 Args:
98 flow_uv (np.ndarray): Flow UV image of shape [H,W,2]
99 clip_flow (float, optional): Clip maximum of flow values. Defaults to None.
100 convert_to_bgr (bool, optional): Convert output image to BGR. Defaults to False.
101
102 Returns:
103 np.ndarray: Flow visualization image of shape [H,W,3]
104 """
105 assert flow_uv.ndim == 3, 'input flow must have three dimensions'
106 assert flow_uv.shape[2] == 2, 'input flow must have shape [H,W,2]'
107
108 if clip_flow is not None:
109 flow_uv = np.clip(flow_uv, 0, clip_flow)
110
111 u = flow_uv[:,:,0]
112 v = flow_uv[:,:,1]
113 rad = np.sqrt(np.square(u) + np.square(v))
114 rad_max = np.max(rad)
115 epsilon = 1e-5
116 u = u / (rad_max + epsilon)
117 v = v / (rad_max + epsilon)
118 return flow_uv_to_colors(u, v, convert_to_bgr)
119
120
121

Callers

nothing calls this directly

Calls 1

flow_uv_to_colorsFunction · 0.85

Tested by

no test coverage detected