code: def convert_MT(args):
      """
      Convert Magnetic-Tile dataset to paddleseg style data.
      """
      prefix = "MT_"
      dataset_path, output_path = args.dataset_path, args.output_path
      (
          train_img_path,
          val_img_path,
          train_anno_path,
          val_anno_path,
      ) = _create_output_path(output_path)
      f_train = open(osp.join(output_path, "train.txt"), "w")
      f_val = open(osp.join(output_path, "val.txt"), "w")
  
      for name, label_id in DEFECTS_LABELS.items():
          folder_path = osp.join(dataset_path, prefix + name, "Imgs")
          for img_name in os.listdir(folder_path):
              basename, ext = osp.splitext(img_name)
              if ext == ".png":
                  continue
  
              anno_name = basename + ".png"
              anno_img = cv2.imread(
                  osp.join(folder_path, anno_name), -1
              )
              anno_img[anno_img <= 240] = 0
              anno_img[anno_img > 240] = label_id
              exp_prefix = img_name.split("_")[0]
  
              if exp_prefix in TRAIN_PREFIX:
                  shutil.copyfile(
                      osp.join(folder_path, img_name),
                      osp.join(train_img_path, img_name),
                  )
                  cv2.imwrite(
                      osp.join(train_anno_path, anno_name), anno_img
                  )
                  line = (
                      osp.join(train_img_path, img_name)
                      + " "
                      + osp.join(train_anno_path, anno_name)
                      + "\n"
                  )
                  f_train.write(line)
              elif exp_prefix in VAL_PREFIX:
                  shutil.copyfile(
                      osp.join(folder_path, img_name),
                      osp.join(val_img_path, img_name),
                  )
                  cv2.imwrite(
                      osp.join(val_anno_path, anno_name), anno_img
                  )
                  line = (
                      osp.join(val_img_path, img_name)
                      + " "
                      + osp.join(val_anno_path, anno_name)
                      + "\n"
                  )
                  f_val.write(line)
              else:
                  raise ValueError(
                      "img name can not match any train or val prefix."
                  )
      f_train.close()
      f_val.close()
  
file_path: PaddleSeg/contrib/QualityInspector/tools/dataset/MT_dataset.py
imports: import argparse
  import os
  import os.path
  import shutil
  import cv2
label_desc: Use image node_id 4 for calling a global function with example usage: convert_MT(args) without return types