code: def visualize(image, result, color_map, save_dir=None, weight=0.6):
      """
      Convert predict result to color image, and save added image.
  
      Args:
          image (str): The path of origin image.
          result (np.ndarray): The predict result of image.
          color_map (list): The color used to save the prediction results.
          save_dir (str): The directory for saving visual image. Default: None.
          weight (float): The image weight of visual image, and the result weight is (1 - weight). Default: 0.6
  
      Returns:
          vis_result (np.ndarray): If `save_dir` is None, return the visualized result.
      """
  
      color_map = [
          color_map[i : i + 3] for i in range(0, len(color_map), 3)
      ]
      color_map = np.array(color_map).astype("uint8")
      # Use OpenCV LUT for color mapping
      c1 = cv2.LUT(result, color_map[:, 0])
      c2 = cv2.LUT(result, color_map[:, 1])
      c3 = cv2.LUT(result, color_map[:, 2])
      pseudo_img = np.dstack((c1, c2, c3))
  
      im = cv2.imread(image)
      vis_result = cv2.addWeighted(
          im, weight, pseudo_img, 1 - weight, 0
      )
  
      if save_dir is not None:
          if not os.path.exists(save_dir):
              os.makedirs(save_dir)
          image_name = os.path.split(image)[-1]
          out_path = os.path.join(save_dir, image_name)
          cv2.imwrite(out_path, vis_result)
      else:
          return vis_result
  
file_path: PaddleSeg/contrib/MedicalSeg/medicalseg/utils/visualize.py
imports: import os
  import cv2
  import numpy
  from PIL import Image
label_desc: Use image node_id 2 for calling a global function with example usage: visualize(image, result, color_map, save_dir, weight) and returns: vis_result