【发布时间】:2019-04-04 02:41:14
【问题描述】:
我有 2 张二值图像,一张是地面实况,一张是我制作的图像分割。
我正在尝试计算均方距离...
Let G = {g1, g2, . . . , gN} be the points in the ground truth boundary.
Let B = {b1, b2, . . . , bM} be the points in the segmented boundary.
Define d(p, p0) be a measure of distance between points p and p0 (e.g. Euclidean, city block, etc.)
使用以下算法在两个图像之间。
def MSD(A,G):
'''
Takes a thresholded binary image, and a ground truth img(binary), and computes the mean squared absolute difference
:param A: The thresholded binary image
:param G: The ground truth img
:return:
'''
sim = np.bitwise_xor(A,G)
sum = 0
for i in range(0,sim.shape[0]):
for j in range(0,sim.shape[1]):
if (sim[i,j] == True):
min = 9999999
for k in range(0,sim.shape[0]):
for l in range(0,sim.shape[1]):
if (sim[k, l] == True):
e = abs(i-k) + abs(j-l)
if e < min:
min = e
mink = k
minl = l
sum += min
return sum/(sim.shape[0]*sim.shape[1])
这个算法太慢了,而且永远不会完成。
example 和 this example(答案 3)可能会展示如何使用矩阵算术获得均方误差的方法,但我不明白这些示例有何意义或它们为何起作用。
【问题讨论】:
-
您的代码与方程式不匹配。通过计算对称差 (xor),您的代码是对称的。如果我交换
A和G我会得到相同的结果。这不适用于方程,这不是对称距离测量。B(A) 中不在G中的像素会增加平均距离。G中的像素不在B中。
标签: python arrays numpy image-processing image-segmentation