python - 评估图像分割方法
问题描述
我已经使用算法将图像分割成以下标签如果它被重塑,这将是一个 4 x 4 的标签矩阵。以下面的列表为例:
imagesegment = [1,1,1,1,1,2,2,1,1,1,2,3,3,3,3,3]
groundtruth = [2,2,2,2,3,3,3,2,2,3,3,1,1,1,1,3]
鉴于基本事实和分割首先包含具有不同标记方案的标签,我该如何评估该方法?
def jaccard_similarity(list1, list2):
s1 = set(list1)
s2 = set(list2)
return len(s1.intersection(s2)) / len(s1.union(s2))
jaccard(imagesegment, groundtruth)
鉴于标签方案与上面所示的不同,如何将分割后的图像与真实情况进行比较?
注意通过比较列表:图像片段中的 1 可以看作是真值中的 2,2 是 3,3 是 1。所以这不是错误分类,而是使用了不同的标签。
解决方案
您可能想要比较共现矩阵。
分区共现矩阵是n
x n
(其中n
是点数,在您的情况下为 16)二进制矩阵,其中
C_ij = 1 iff label(i) == label(j)
您可以计算 和 的共现矩阵imagesegment
并groundtruth
计算相同条目的数量。
imagesegment = np.array([1,1,1,1,1,2,2,1,1,1,2,3,3,3,3,3])
groundtruth = np.array([2,2,2,2,3,3,3,2,2,3,3,1,1,1,1,3])
Ci = imagesegment[None, :] == imagesegment[:, None]
Cg = groundtruth[None, :] == groundtruth[:, None]
# compare only half the matrix and ignore diagonal
fci = np.concatenate([np.diag(Ci,k=k) for k in range(1, 16)])
fcg = np.concatenate([np.diag(Cg, k=k) for k in range(1, 16)])
# the actual score:
(fci==fcg).mean() # 0.775 in your case. score of 1 is perfect
推荐阅读
- python - 如何在列表变量中重复一个值以在 matplotlib 中为条形图着色?
- android - 在android中更改View Pager2所选图像的图像视图背景
- google-apps-script - SpreadsheetApp.getActiveSpreadsheet() 返回:指定对象必须是工作表的一部分
- swiftui - 带有变量的 navigationBarTitle 给出了各种随机错误
- php - 实现用户日志的最佳方式
- php - PHP数组中的最后一项在foreach中为空
- apache-spark - spark-submit 与 hive shell 中的查询性能
- java - 卡夫卡管道的 Spring Boot 应用程序出现错误“无法建立与节点 -1 的连接。代理可能不可用。”
- android - 如何更改 HERE Android SDK PositioningManager 的更新频率?
- attributes - 我如何在属性部分“测试”中读取一些结构参数?