I have a set of curves defined as 2D arrays (number of points, number of coordinates). I am calculating a distance matrix for them using Hausdorff distance. My current code is as follows. Unfortunately it is too slow with 500-600 curves each having 50-100 3D points. Is there any faster way for that?
def distanceBetweenCurves(C1, C2):
D = scipy.spatial.distance.cdist(C1, C2, 'euclidean')
#none symmetric Hausdorff distances
H1 = np.max(np.min(D, axis=1))
H2 = np.max(np.min(D, axis=0))
return (H1 + H2) / 2.
def distanceMatrixOfCurves(Curves):
numC = len(Curves)
D = np.zeros((numC, numC))
for i in range(0, numC-1):
for j in range(i+1, numC):
D[i, j] = D[j, i] = distanceBetweenCurves(Curves[i], Curves[j])
return D
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…