code: def gray2pseudo_color(args):
      """将灰度标注图片转换为伪彩色图片"""
      input = args.dir_or_file
      output_dir = args.output_dir
      if not osp.exists(output_dir):
          os.makedirs(output_dir)
          print("Creating colorful label directory:", output_dir)
  
      color_map = get_color_map_list(256)
      if os.path.isdir(input):
          for fpath, dirs, fs in os.walk(input):
              for f in fs:
                  try:
                      grt_path = osp.join(fpath, f)
                      _output_dir = fpath.replace(input, "")
                      _output_dir = _output_dir.lstrip(os.path.sep)
  
                      im = Image.open(grt_path)
                      lbl = np.asarray(im)
  
                      lbl_pil = Image.fromarray(
                          lbl.astype(np.uint8), mode="P"
                      )
                      lbl_pil.putpalette(color_map)
  
                      real_dir = osp.join(output_dir, _output_dir)
                      if not osp.exists(real_dir):
                          os.makedirs(real_dir)
                      new_grt_path = osp.join(real_dir, f)
  
                      lbl_pil.save(new_grt_path)
                      print("New label path:", new_grt_path)
                  except:
                      continue
      elif os.path.isfile(input):
          if args.dataset_dir is None or args.file_separator is None:
              print("No dataset_dir or file_separator input!")
              sys.exit()
          with open(input) as f:
              for line in f:
                  parts = line.strip().split(args.file_separator)
                  grt_name = parts[1]
                  grt_path = os.path.join(args.dataset_dir, grt_name)
  
                  im = Image.open(grt_path)
                  lbl = np.asarray(im)
  
                  lbl_pil = Image.fromarray(
                      lbl.astype(np.uint8), mode="P"
                  )
                  lbl_pil.putpalette(color_map)
  
                  grt_dir, _ = osp.split(grt_name)
                  new_dir = osp.join(output_dir, grt_dir)
                  if not osp.exists(new_dir):
                      os.makedirs(new_dir)
                  new_grt_path = osp.join(output_dir, grt_name)
  
                  lbl_pil.save(new_grt_path)
                  print("New label path:", new_grt_path)
      else:
          print("It's neither a dir nor a file")
  
file_path: PaddleSeg/tools/data/gray2pseudo_color.py
imports: from __future__ import print_function
  import argparse
  import os
  import os.path
  import sys
  import numpy
  from PIL import Image
label_desc: Use image node_id 3 for calling a global function with example usage: gray2pseudo_color(args) without return types