Files changed (2) hide show
  1. hoho/wed.py +20 -12
  2. setup.py +1 -1
hoho/wed.py CHANGED
@@ -28,13 +28,23 @@ 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 (the cost in centimeters of missing a vertex, default is -1, which means 1/4 of the diameter of the ground truth mesh)
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 +53,19 @@ 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/4 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
- 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)
@@ -72,11 +80,11 @@ def compute_WED(pd_vertices, pd_edges, gt_vertices, gt_edges, cv=-1, ce=1.0, nor
72
 
73
  # Additional: Vertex Deletion
74
  unmatched_pd_indices = set(range(len(pd_vertices))) - set(row_ind)
75
- deletion_costs = cv * len(unmatched_pd_indices)
76
 
77
  # Step 3: Vertex Insertion
78
  unmatched_gt_indices = set(range(len(gt_vertices))) - set(col_ind)
79
- insertion_costs = cv * len(unmatched_gt_indices)
80
 
81
  # Step 4: Edge Deletion and Insertion
82
  updated_pd_edges = [(col_ind[np.where(row_ind == edge[0])[0][0]], col_ind[np.where(row_ind == edge[1])[0][0]]) for edge in pd_edges if edge[0] in row_ind and edge[1] in row_ind]
 
28
  return transformed_verts
29
 
30
 
31
+ def update_cv(cv, gt_vertices):
32
+ if cv < 0:
33
+ diameter = cdist(gt_vertices, gt_vertices).max()
34
+ # Cost of adding or deleting a vertex is set to -cv times the diameter of the ground truth wireframe
35
+ cv = -cv * diameter
36
+ elif cv == 0:
37
+ # Cost of adding or deleting a vertex is set to the average distance of the ground truth vertices from their mean
38
+ cv = np.linalg.norm(np.mean(gt_vertices, axis=0) - gt_vertices, axis=1).mean()
39
+ return cv
40
+
41
+ def compute_WED(pd_vertices, pd_edges, gt_vertices, gt_edges, cv_ins=-1/2, cv_del=-1/4, ce=1.0, normalized=True, preregister=True, single_scale=True):
42
  '''The function computes the Wireframe Edge Distance (WED) between two graphs.
43
  pd_vertices: list of predicted vertices
44
  pd_edges: list of predicted edges
45
  gt_vertices: list of ground truth vertices
46
  gt_edges: list of ground truth edges
47
+ cv: vertex cost: if positive, the cost in centimeters of missing a vertex, if negative, multiplies diameter to compute cost (default is -1/2)
48
  ce: edge cost (multiplier of the edge length for edge deletion and insertion, default is 1.0)
49
  normalized: if True, the WED is normalized by the total length of the ground truth edges
50
  preregister: if True, the predicted vertices have their mean and scale matched to the ground truth vertices
 
53
  # Vertex coordinates are in centimeters. When cv and ce are set to 100.0 and 1.0 respectively,
54
  # missing a vertex is equivanlent predicting it 1 meter away from the ground truth vertex.
55
  # This is equivalent to setting cv=1 and ce=1 when the vertex coordinates are in meters.
56
+ # When a negative cv value is set (the default behavior), cv is reset to 1/2 of the diameter of the ground truth wireframe.
57
 
58
  pd_vertices = np.array(pd_vertices)
59
  gt_vertices = np.array(gt_vertices)
60
 
 
 
 
 
 
 
 
61
  if preregister:
62
  pd_vertices = preregister_mean_std(pd_vertices, gt_vertices, single_scale=single_scale)
63
 
64
+ cv_del = update_cv(cv_del, gt_vertices)
65
+ cv_ins = update_cv(cv_ins, gt_vertices)
66
+
67
+ # Step 0: Prenormalize / preregister
68
+
69
 
70
  pd_edges = np.array(pd_edges)
71
  gt_edges = np.array(gt_edges)
 
80
 
81
  # Additional: Vertex Deletion
82
  unmatched_pd_indices = set(range(len(pd_vertices))) - set(row_ind)
83
+ deletion_costs = cv_del * len(unmatched_pd_indices)
84
 
85
  # Step 3: Vertex Insertion
86
  unmatched_gt_indices = set(range(len(gt_vertices))) - set(col_ind)
87
+ insertion_costs = cv_ins * len(unmatched_gt_indices)
88
 
89
  # Step 4: Edge Deletion and Insertion
90
  updated_pd_edges = [(col_ind[np.where(row_ind == edge[0])[0][0]], col_ind[np.where(row_ind == edge[1])[0][0]]) for edge in pd_edges if edge[0] in row_ind and edge[1] in row_ind]
setup.py CHANGED
@@ -6,7 +6,7 @@ with open('requirements.txt') as f:
6
  required = f.read().splitlines()
7
 
8
  setup(name='hoho',
9
- version='0.0.3',
10
  description='Tools and utilites for the HoHo Dataset and S23DR Competition',
11
  url='usm3d.github.io',
12
  author='Jack Langerman, Dmytro Mishkin, S23DR Orgainizing Team',
 
6
  required = f.read().splitlines()
7
 
8
  setup(name='hoho',
9
+ version='0.0.4',
10
  description='Tools and utilites for the HoHo Dataset and S23DR Competition',
11
  url='usm3d.github.io',
12
  author='Jack Langerman, Dmytro Mishkin, S23DR Orgainizing Team',