首页 > 解决方案 > 评估图像分割方法

问题描述

我已经使用算法将图像分割成以下标签如果它被重塑,这将是一个 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。所以这不是错误分类,而是使用了不同的标签。

标签: pythonpython-3.ximage-processingcomputer-visionimage-segmentation

解决方案


您可能想要比较共现矩阵。

分区共现矩阵是nx n(其中n是点数,在您的情况下为 16)二进制矩阵,其中

C_ij = 1 iff label(i) == label(j)

您可以计算 和 的共现矩阵imagesegmentgroundtruth计算相同条目的数量。

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

推荐阅读