code: def quantize_flow(flow, max_val=0.02, norm=True):
      """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.
      """
      h, w, _ = flow.shape
      dx = flow[..., 0]
      dy = flow[..., 1]
      if norm:
          dx = dx / w  # avoid inplace operations
          dy = dy / h
      # use 255 levels instead of 256 to make sure 0 is 0 after dequantization.
      flow_comps = [
          quantize(d, -max_val, max_val, 255, np.uint8)
          for d in [dx, dy]
      ]
      return tuple(flow_comps)
  
file_path: lavis/lavis/common/annotator/uniformer/mmcv/video/optflow.py
imports: import warnings
  import cv2
  import numpy
  from annotator.uniformer.mmcv.arraymisc import dequantize, quantize
  from annotator.uniformer.mmcv.image import imread, imwrite
  from annotator.uniformer.mmcv.utils import is_str
label_desc: Use image node_id 3 for calling a global function with example usage: quantize_flow(flow, max_val, norm) and returns: tuple