mask与原图叠加

  • Post author:
  • Post category:其他


分割中将mask与原图叠加,生成漂亮的掩膜。

import os
from PIL import Image

    
root_path_background = "/home/cc/codes/python/YOLOP-main/datas/images/train/"
root_path_paste = "/home/cc/codes/python/YOLOP-main/datas/da_seg_annotations/train/"
output_path = "/home/cc/codes/python/YOLOP-main/datas/masks/"
img_list = os.listdir(root_path_background)
label_list = os.listdir(root_path_paste)
img_list = sorted(img_list)
label_list = sorted(label_list)
for num,img_label in enumerate(zip(img_list,label_list)): 
    img = Image.open(os.path.join(root_path_background,img_label[0]))
    label = Image.open(os.path.join(root_path_paste,img_label[1]))
    label = label.convert("RGB")
    fin = Image.blend(img,label,0.3)
    # fin.show()
    fin.save(os.path.join(output_path,img_label[0]))



版权声明:本文为qq_15409121原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。