多颜色绘制语义分割/变化检测结果图

server/2024/9/24 22:19:31/

在论文绘图时,传统的二元语义分割结果图颜色单一(下图左),所以论文中常根据混淆矩阵类别使用多颜色进行绘制(下图右),可以看到,结果的可视化效果更好。

     

以下是绘制代码:

python">import os
import cv2
import argparse
import numpy as np
from tqdm import tqdmdef intersection_color(binary_result, ground_truth):if len(binary_result.shape) != 2 or len(ground_truth.shape) != 2:raise ValueError(f"The dim numbers of binary_result and ground_truth must be 2!")# 将255的值转换为1binary_result = np.where(binary_result > 128, 1, 0)ground_truth = np.where(ground_truth > 128, 1, 0)# 创建RGB图像,根据TP、FP和FN的位置使用不同的颜色rgb_image = np.zeros((binary_result.shape[0], binary_result.shape[1], 3), dtype=np.uint8)# True Positives (TP) - 白色rgb_image[(binary_result == 1) & (ground_truth == 1)] = [255, 255, 255]# False Positives (FP) - 红色rgb_image[(binary_result == 1) & (ground_truth == 0), 2] = 255# False Negatives (FN) - 绿色rgb_image[(binary_result == 0) & (ground_truth == 1), 1] = 255# rgb_image = cv2.cvtColor(rgb_image, cv2.COLOR_RGB2BGR)return rgb_imagedef visual_label(args):pred_list = os.listdir(args.pred_root)gt_list = os.listdir(args.gt_root)if len(pred_list)!= len(gt_list):raise ValueError(f"The number of predicted result is not equal to that of ground truth!")if not os.path.exists(args.out_root):os.makedirs(args.out_root)for file_name in tqdm(pred_list):pred_file = os.path.join(args.pred_root, file_name)gt_file = os.path.join(args.gt_root, file_name)pred = cv2.imread(pred_file, cv2.IMREAD_GRAYSCALE)gt = cv2.imread(gt_file, cv2.IMREAD_GRAYSCALE)rgb_label = intersection_color(pred, gt)out_path = os.path.join(args.out_root, file_name)cv2.imwrite(out_path, rgb_label)def parse_args():parser = argparse.ArgumentParser(description='Open-CD test (and eval) a model')parser.add_argument('--pred_root', help='predict results path')parser.add_argument('--gt_root', help='gt path')parser.add_argument('--out_root',help=('if specified, the evaluation metric results will be dumped''into the directory as json'))args = parser.parse_args()return argsdef main():args = parse_args()visual_label(args)if __name__ == "__main__":main()

欢迎关注大地主的Github仓库(ABCnutter (PengChen) (github.com)),谢谢。


http://www.ppmy.cn/server/121531.html

相关文章

结构设计模式 -装饰器设计模式 - JAVA

装饰器设计模式 一. 介绍二. 代码示例2.1 抽象构件(Component)角色2.2 具体构件(Concrete Component)角色2.3 装饰(Decorator)角色2.4 具体装饰(Concrete Decorator)角色2.5 测试 结…

数理统计(第一章)

数理统计核心问题:有子样推断母体 1.1 母体和子样 母体:研究对象的全体(关心个体的一项或者几项)数量指标及总体的分布情况。 比如:一批灯泡的使用寿命,班级学生的身高,体重等。 1.2 母体分布…

Spring MVC 基本配置步骤 总结

1.简介 本文记录Spring MVC基本项目拉起配置步骤。 2.步骤 在pom.xml中导入依赖&#xff1a; <dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>6.0.6</version><scope>…

类型转换与RTTI

类型转换 一、类型转换1、C语言2、C3、注意 二、static_cast1、介绍2、示例 三、reinterpret_cast1、介绍2、示例代码3、运行结果 四、const_cast1、介绍2、示例 五、dynamic_cast1、介绍2、示例代码3、运行结果 六、RTTI1、介绍2、typeid&#xff08;1&#xff09;介绍&#x…

LabVIEW提高开发效率技巧----合理使用数据流与内存管理

理使用数据流和内存管理是LabVIEW开发中提高性能和稳定性的关键&#xff0c;特别是在处理大数据或高频率信号时&#xff0c;优化可以避免内存消耗过大、程序卡顿甚至崩溃。 1. 使用 Shift Register 进行内存管理 Shift Register&#xff08;移位寄存器&#xff09; 是 LabVIE…

《DevOps实践指南》笔记-Part 3

一篇文章显得略长&#xff0c;本文对应第5-6章、附录、认证考试、参考资源等。 前言、第1-2章请参考Part 1&#xff0c;第3-4章内容&#xff0c;请参考Part 2。 持续学习与实验的技术实践 通过以下方式制定有关提高安全性、持续改进和边做边学的制度&#xff1a; 建立公正的…

分布式消息服务Kafka版的详细解析和配置方式

分布式消息服务Kafka版是一款基于开源社区版Kafka提供的消息队列服务&#xff0c;它向用户提供计算、存储和带宽资源独占式的Kafka专享实例。以下是对分布式消息服务Kafka版的详细解析和配置方式的介绍。 一、分布式消息服务Kafka版解析 1. Kafka概述 Kafka是一个开源的分布…

CSS调整背景

一、设置背景颜色 通过 background-color 属性指定&#xff0c;值可以是十六进制 #ffffff&#xff0c;也可以是rgb(0, 255, 255)&#xff0c;或是颜色名称 "red" div {background-color: red; /* 通过颜色名称设置 */background-color: #ff0000; /* 通过十六进制设…