MCPcopy Create free account
hub / github.com/DragonisCV/RAM / quantize_flow

Function quantize_flow

ram/utils/flow_util.py:76–99  ·  view source on GitHub ↗

Quantize flow to [0, 255]. After this step, the size of flow will be much smaller, and can be dumped as jpeg images. Args: flow (ndarray): (h, w, 2) array of optical flow. max_val (float): Maximum value of flow, values beyond [-max_val, max_val]

(flow, max_val=0.02, norm=True)

Source from the content-addressed store, hash-verified

74
75
76def quantize_flow(flow, max_val=0.02, norm=True):
77 """Quantize flow to [0, 255].
78
79 After this step, the size of flow will be much smaller, and can be
80 dumped as jpeg images.
81
82 Args:
83 flow (ndarray): (h, w, 2) array of optical flow.
84 max_val (float): Maximum value of flow, values beyond
85 [-max_val, max_val] will be truncated.
86 norm (bool): Whether to divide flow values by image width/height.
87
88 Returns:
89 tuple[ndarray]: Quantized dx and dy.
90 """
91 h, w, _ = flow.shape
92 dx = flow[..., 0]
93 dy = flow[..., 1]
94 if norm:
95 dx = dx / w # avoid inplace operations
96 dy = dy / h
97 # use 255 levels instead of 256 to make sure 0 is 0 after dequantization.
98 flow_comps = [quantize(d, -max_val, max_val, 255, np.uint8) for d in [dx, dy]]
99 return tuple(flow_comps)
100
101
102def dequantize_flow(dx, dy, max_val=0.02, denorm=True):

Callers 1

flowwriteFunction · 0.85

Calls 1

quantizeFunction · 0.85

Tested by

no test coverage detected