def quantize_flow(flow, max_val=<NUM_LIT>, norm=True):
h, w, _ = flow.shape<EOL>dx = flow[..., <NUM_LIT:0>]<EOL>dy = flow[..., <NUM_LIT:1>]<EOL>if norm:<EOL><INDENT>dx = dx / w  <EOL>dy = dy / h<EOL><DEDENT>flow_comps = [<EOL>quantize(d, -max_val, max_val, <NUM_LIT:255>, np.uint8) for d in [dx, dy]<EOL>]<EOL>return tuple(flow_comps)<EOL>
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] will be truncated.
        norm (bool): Whether to divide flow values by image width/height.

    Returns:
        tuple[ndarray]: Quantized dx and dy.