Siromanec commited on
Commit
32ea5b8
1 Parent(s): 198fdf0

remove self loops and bi-directional non unique edges. edge_th=60

Browse files
Files changed (1) hide show
  1. handcrafted_solution.py +14 -6
handcrafted_solution.py CHANGED
@@ -138,7 +138,7 @@ def get_vertices_and_edges_from_segmentation(gest_seg_np, edge_th=50.0):
138
  theta = np.pi / 180 # angular resolution in radians of the Hough grid
139
  threshold = 15 # minimum number of votes (intersections in Hough grid cell)
140
  min_line_length = 40 # minimum number of pixels making up a line
141
- max_line_gap = 30 # maximum gap in pixels between connectable line segments
142
 
143
  # Run Hough on edge detected image
144
  # Output "lines" is an array containing endpoints of detected line segments
@@ -165,19 +165,27 @@ def get_vertices_and_edges_from_segmentation(gest_seg_np, edge_th=50.0):
165
  begin_closest_point_distances = begin_distances[begin_closest_points, np.arange(len(begin_closest_points))]
166
  end_closest_point_distances = end_distances[end_closest_points, np.arange(len(end_closest_points))]
167
 
168
- begin_in_range_mask = begin_closest_point_distances < edge_th
169
- end_in_range_mask = end_closest_point_distances < edge_th
170
 
171
  # where both ends are in range
172
  in_range_connected_mask = np.logical_and(begin_in_range_mask, end_in_range_mask)
173
 
174
  edge_idxs = np.where(in_range_connected_mask)[0]
175
 
176
- unique_edges = np.unique(np.array([begin_closest_points[edge_idxs], end_closest_points[edge_idxs]]).T,
177
- axis=0)
 
 
 
 
 
178
 
 
 
179
  connections.extend(unique_edges)
180
 
 
181
  vertices = [{"xy": v, "type": "apex"} for v in apex_centroids]
182
  vertices += [{"xy": v, "type": "eave_end_point"} for v in eave_end_point_centroids]
183
  return vertices, connections
@@ -288,7 +296,7 @@ def predict(entry, visualize=False) -> Tuple[np.ndarray, List[int]]:
288
  gest_seg_np = np.array(gest_seg).astype(np.uint8)
289
  # Metric3D
290
  depth_np = np.array(depth) / 2.5 # 2.5 is the scale estimation coefficient
291
- vertices, connections = get_vertices_and_edges_from_segmentation(gest_seg_np, edge_th=70.)
292
  if (len(vertices) < 2) or (len(connections) < 1):
293
  print(f'Not enough vertices or connections in image {i}')
294
  vert_edge_per_image[i] = np.empty((0, 2)), [], np.empty((0, 3))
 
138
  theta = np.pi / 180 # angular resolution in radians of the Hough grid
139
  threshold = 15 # minimum number of votes (intersections in Hough grid cell)
140
  min_line_length = 40 # minimum number of pixels making up a line
141
+ max_line_gap = 40 # maximum gap in pixels between connectable line segments
142
 
143
  # Run Hough on edge detected image
144
  # Output "lines" is an array containing endpoints of detected line segments
 
165
  begin_closest_point_distances = begin_distances[begin_closest_points, np.arange(len(begin_closest_points))]
166
  end_closest_point_distances = end_distances[end_closest_points, np.arange(len(end_closest_points))]
167
 
168
+ begin_in_range_mask = begin_closest_point_distances <= edge_th
169
+ end_in_range_mask = end_closest_point_distances <= edge_th
170
 
171
  # where both ends are in range
172
  in_range_connected_mask = np.logical_and(begin_in_range_mask, end_in_range_mask)
173
 
174
  edge_idxs = np.where(in_range_connected_mask)[0]
175
 
176
+ edges = np.array([begin_closest_points[edge_idxs], end_closest_points[edge_idxs]]).T
177
+ if len(edges) < 1:
178
+ continue
179
+ edges = np.sort(edges, axis=1)
180
+ unique_edges = np.unique(edges, axis=0)
181
+
182
+ unique_edges = unique_edges[unique_edges[:, 0] != unique_edges[:, 1]] # remove self loops
183
 
184
+ if len(unique_edges) < 1:
185
+ continue
186
  connections.extend(unique_edges)
187
 
188
+
189
  vertices = [{"xy": v, "type": "apex"} for v in apex_centroids]
190
  vertices += [{"xy": v, "type": "eave_end_point"} for v in eave_end_point_centroids]
191
  return vertices, connections
 
296
  gest_seg_np = np.array(gest_seg).astype(np.uint8)
297
  # Metric3D
298
  depth_np = np.array(depth) / 2.5 # 2.5 is the scale estimation coefficient
299
+ vertices, connections = get_vertices_and_edges_from_segmentation(gest_seg_np, edge_th=60.)
300
  if (len(vertices) < 2) or (len(connections) < 1):
301
  print(f'Not enough vertices or connections in image {i}')
302
  vert_edge_per_image[i] = np.empty((0, 2)), [], np.empty((0, 3))