Commit
·
91b350c
1
Parent(s):
a842b44
refactor cv + fix calc
Browse files- hoho/wed.py +12 -10
hoho/wed.py
CHANGED
|
@@ -28,13 +28,13 @@ def preregister_mean_std(verts_to_transform, target_verts, single_scale=True):
|
|
| 28 |
return transformed_verts
|
| 29 |
|
| 30 |
|
| 31 |
-
def compute_WED(pd_vertices, pd_edges, gt_vertices, gt_edges, cv=-1, ce=1.0, normalized=True, preregister=True, single_scale=True):
|
| 32 |
'''The function computes the Wireframe Edge Distance (WED) between two graphs.
|
| 33 |
pd_vertices: list of predicted vertices
|
| 34 |
pd_edges: list of predicted edges
|
| 35 |
gt_vertices: list of ground truth vertices
|
| 36 |
gt_edges: list of ground truth edges
|
| 37 |
-
cv: vertex cost
|
| 38 |
ce: edge cost (multiplier of the edge length for edge deletion and insertion, default is 1.0)
|
| 39 |
normalized: if True, the WED is normalized by the total length of the ground truth edges
|
| 40 |
preregister: if True, the predicted vertices have their mean and scale matched to the ground truth vertices
|
|
@@ -43,21 +43,23 @@ def compute_WED(pd_vertices, pd_edges, gt_vertices, gt_edges, cv=-1, ce=1.0, nor
|
|
| 43 |
# Vertex coordinates are in centimeters. When cv and ce are set to 100.0 and 1.0 respectively,
|
| 44 |
# missing a vertex is equivanlent predicting it 1 meter away from the ground truth vertex.
|
| 45 |
# This is equivalent to setting cv=1 and ce=1 when the vertex coordinates are in meters.
|
| 46 |
-
# When a negative cv value is set (the default behavior), cv is reset to 1/
|
| 47 |
|
| 48 |
pd_vertices = np.array(pd_vertices)
|
| 49 |
gt_vertices = np.array(gt_vertices)
|
| 50 |
|
| 51 |
-
diameter = cdist(gt_vertices, gt_vertices).max()
|
| 52 |
-
|
| 53 |
-
if cv < 0:
|
| 54 |
-
cv = diameter / 4.0
|
| 55 |
-
# Cost of addining or deleting a vertex is set to 1/4 of the diameter of the ground truth mesh
|
| 56 |
-
|
| 57 |
-
# Step 0: Prenormalize / preregister
|
| 58 |
if preregister:
|
| 59 |
pd_vertices = preregister_mean_std(pd_vertices, gt_vertices, single_scale=single_scale)
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
pd_edges = np.array(pd_edges)
|
| 63 |
gt_edges = np.array(gt_edges)
|
|
|
|
| 28 |
return transformed_verts
|
| 29 |
|
| 30 |
|
| 31 |
+
def compute_WED(pd_vertices, pd_edges, gt_vertices, gt_edges, cv=-1/4, ce=1.0, normalized=True, preregister=True, single_scale=True):
|
| 32 |
'''The function computes the Wireframe Edge Distance (WED) between two graphs.
|
| 33 |
pd_vertices: list of predicted vertices
|
| 34 |
pd_edges: list of predicted edges
|
| 35 |
gt_vertices: list of ground truth vertices
|
| 36 |
gt_edges: list of ground truth edges
|
| 37 |
+
cv: vertex cost: if positive, the cost in centimeters of missing a vertex, if negative, multiplies diameter to compute cost (default is -1/2)
|
| 38 |
ce: edge cost (multiplier of the edge length for edge deletion and insertion, default is 1.0)
|
| 39 |
normalized: if True, the WED is normalized by the total length of the ground truth edges
|
| 40 |
preregister: if True, the predicted vertices have their mean and scale matched to the ground truth vertices
|
|
|
|
| 43 |
# Vertex coordinates are in centimeters. When cv and ce are set to 100.0 and 1.0 respectively,
|
| 44 |
# missing a vertex is equivanlent predicting it 1 meter away from the ground truth vertex.
|
| 45 |
# This is equivalent to setting cv=1 and ce=1 when the vertex coordinates are in meters.
|
| 46 |
+
# When a negative cv value is set (the default behavior), cv is reset to 1/2 of the diameter of the ground truth wireframe.
|
| 47 |
|
| 48 |
pd_vertices = np.array(pd_vertices)
|
| 49 |
gt_vertices = np.array(gt_vertices)
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
if preregister:
|
| 52 |
pd_vertices = preregister_mean_std(pd_vertices, gt_vertices, single_scale=single_scale)
|
| 53 |
|
| 54 |
+
if cv < 0:
|
| 55 |
+
diameter = cdist(gt_vertices, gt_vertices).max()
|
| 56 |
+
# Cost of adding or deleting a vertex is set to -cv times the diameter of the ground truth wireframe
|
| 57 |
+
cv = -cv * diameter
|
| 58 |
+
elif cv == 0:
|
| 59 |
+
# Cost of adding or deleting a vertex is set to the average distance of the ground truth vertices from their mean
|
| 60 |
+
cv = np.linalg.norm(np.mean(gt_vertices, axis=0) - gt_vertices, axis=1).mean()
|
| 61 |
+
# Step 0: Prenormalize / preregister
|
| 62 |
+
|
| 63 |
|
| 64 |
pd_edges = np.array(pd_edges)
|
| 65 |
gt_edges = np.array(gt_edges)
|