【发布时间】: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
【问题讨论】: