【问题标题】:Compare ground truth list of colours to another list of colours将基本颜色列表与另一个颜色列表进行比较
【发布时间】:2019-06-23 00:20:49
【问题描述】:

我有 2 个颜色数组/列表。一个表示图像中的实际主色,另一个表示算法认为是图像中主色的列表颜色。

我想比较这 2 个列表,以了解算法与 实际 真实颜色列表的接近程度。 *如果它们之间的欧几里得距离

问题在于 2 个列表的长度不一定相同。每个列表中的颜色不会按任何顺序排列。颜色将始终位于颜色空间CieLAB (cv2.COLOR_BGR2LAB) 中。

我需要比较相似性的 2 个列表示例。请注意,它们的顺序和列表长度不同。但是这 2 个被认为是相同的,因为它发现了地面实况中的所有颜色(加上一些额外的颜色)并且所有这些颜色都在

ground_truth = [[76, 177, 34], [36, 28, 237], [204, 72, 63], [0, 242, 255]]
结果 = [[35, 29, 234], [200, 72, 63], [70, 177, 34], [0, 242, 250], [45,29,67], [3,90,52] ]

我在下面构建了一个验证器,但我不确定它是否正确?关于如何实现上述目标的任何建议?

def validator(algoTuner, result, ground_truth):
    # Score = How close the colours in result are to the colours in ground_truth

    # p = pairwise distance between result and ground_truth
    # hits = get all distances from p that are <= max_dist
    # score = float(len(hits)) / len(ground_truth)
    dists = cdist(result, ground_truth, 'euclidean')
    score = float(len(dists[ dists < 25 ])) / len(ground_truth)
    return score

在@Nakor 的回答之后

编辑,这会更正确吗?请记住,该算法可以找到比基本事实更多的颜色。重要的是算法会在基本实况中找到所有正确的颜色,任何额外的颜色都不会影响分数。

def validator(algoTuner, result, ground_truth, debug=False):
    dists = cdist(result, ground_truth, 'euclidean')
    correct_guesses = np.sum(dists<25, axis=1)
    correct_guesses = correct_guesses[ correct_guesses > 0 ]
    # score = correct_guesses.mean()
    score = float(correct_guesses.size) / len(ground_truth)

    if debug:
        print(len(correct_guesses))
        print(correct_guesses)
        print(score)
    return score

【问题讨论】:

    标签: python numpy opencv scipy


    【解决方案1】:

    我认为您计算分数的部分不正确。您在全球范围内计算 25 以下的元素数量。但如果我理解正确,您正在寻找ground_truth 中的每种颜色,result 中是否至少有一种颜色距离小于 25 点。

    如果是这种情况,那么我会修改您的验证器:

    def validator(algoTuner, result, ground_truth):
        # Score = How close the colours in result are to the colours in ground_truth
    
        # p = pairwise distance between result and ground_truth
        # hits = get all distances from p that are <= max_dist
        # score = float(len(hits)) / len(ground_truth)
        dists = cdist(result, ground_truth, 'euclidean')
        correct_guesses = np.sum(dists<25,axis=0)
        score = (correct_guesses>0).mean()
        return score
    

    它返回 ground_truth 中颜色的比例,这些颜色也出现在结果中。 在您的示例中,得分为 1。

    【讨论】:

    • 感谢您的回答。我已经编辑了我的帖子,该解决方案是否正确?
    • 实际上我纠正了两件事:1)我不知道你不关心结果中的额外颜色。在这种情况下,您只需查看axis = 0(即,如果对于地面实况中的每种颜色,您都有一个匹配项)2)我没有考虑到我可以在正确的猜测中找到几个匹配项。所以,在计算分数的时候,你需要做score = (correct_guesses&gt;0).mean()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-17
    • 1970-01-01
    • 2013-07-31
    相关资源
    最近更新 更多