code: def generate_seg_label_image(label):
      # this code copy from https://github.com/ZJULearning/resa/blob/main/tools/generate_seg_tusimple.py
      lanes = []
      _lanes = []
      slope = (
          []
      )  # identify 0th, 1st, 2nd, 3rd, 4th, 5th lane through slope
      for i in range(len(label["lanes"])):
          l = [
              (x, y)
              for x, y in zip(label["lanes"][i], label["h_samples"])
              if x >= 0
          ]
          if len(l) > 1:
              _lanes.append(l)
              slope.append(
                  np.arctan2(l[-1][1] - l[0][1], l[0][0] - l[-1][0])
                  / np.pi
                  * 180
              )
      _lanes = [_lanes[i] for i in np.argsort(slope)]
      slope = [slope[i] for i in np.argsort(slope)]
  
      idx = [None for i in range(CLASS_NUMS - 1)]
      for i in range(len(slope)):
          if slope[i] <= 90:
              idx[2] = i
              idx[1] = i - 1 if i > 0 else None
              idx[0] = i - 2 if i > 1 else None
          else:
              idx[3] = i
              idx[4] = i + 1 if i + 1 < len(slope) else None
              idx[5] = i + 2 if i + 2 < len(slope) else None
              break
      for i in range(CLASS_NUMS - 1):
          lanes.append([] if idx[i] is None else _lanes[idx[i]])
  
      seg_img = np.zeros([Image_Height, Image_Width], np.uint8)
  
      for i in range(len(lanes)):
          coords = lanes[i]
          if len(coords) < 4:
              continue
          for j in range(len(coords) - 1):
              cv2.line(
                  seg_img,
                  coords[j],
                  coords[j + 1],
                  i + 1,
                  LANE_SEG_WIDTH // 2,
              )
  
      return seg_img
  
file_path: PaddleSeg/contrib/LaneSeg/third_party/generate_tusimple_dataset.py
imports: import os
  import cv2
  import json
  import argparse
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: generate_seg_label_image(label) and returns: seg_img