根据语义分割二分类结果用不同颜色标注

import cv2 as cv
import numpy as np

def mark_type(infer,gt,ori_path,save_path):
    print(ori_path)
    ori=cv.imread(ori_path)
    #print(ori.shape)
    mark_r = ori[:,:,2]
    mark_g = ori[:,:,1]
    mark_b = ori[:,:,0]
    #print(mark_r.shape)

    tp_matrix=np.multiply(infer,gt)#真正例,标记为白色
    fp_matrix=np.multiply(infer,1-gt)#假正例,标记为绿色
    tn_matrix = np.multiply(1-infer, 1 - gt)#真反例,标记为黑色
    fn_matrix = np.multiply(1-infer,  gt)#假反例,标记为红色

    mark_r[np.where(tp_matrix==1)]=255
    mark_g[np.where(tp_matrix==1) ]=255
    mark_b[np.where(tp_matrix == 1)]=255
    mark_r[np.where(fn_matrix == 1)] = 255
    mark_g[np.where(fp_matrix == 1)]=255

    mark=np.stack((mark_b,mark_g,mark_r),axis=2)

    cv.imwrite(save_path,mark)
    print(save_path)


ori_dir="C:/test_ori_img/"
gt_path="C:/gt_label/"
inferred_path="C:/inferred_jointed/"
mark_dst_path="C:/marked/"
pic_list_path="C:/TransUNet-main/infer_test_list.txt"
inferred_list=[]
gt_list=[]
with open(pic_list_path,'r') as f:
    lines = f.readlines()
    for line in lines:
        inferred=inferred_path+line.strip("\n")+".png"
        gt=gt_path+line.strip("\n")+".tif"
        infer_arr=cv.imread(inferred,cv.IMREAD_GRAYSCALE)
        gt_arr=cv.imread(gt,cv.IMREAD_GRAYSCALE)
        infer_arr[infer_arr==255]=1
        gt_arr[gt_arr==255]=1
        save_path=mark_dst_path+line.strip("\n")+".png"
        ori_path=ori_dir+line.strip("\n")+".tiff"
        mark_type(infer_arr,gt_arr,ori_path,save_path)

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值