(2) clear_node_feat(G, *fts) : Clear all the node feature on graph G. (6) get_cross_nes(x, y) : Get the four cross neighbors of pixel(x, y).
(mesh, info_on_pix, depth=None)
| 334 | return mesh |
| 335 | |
| 336 | def update_status(mesh, info_on_pix, depth=None): |
| 337 | ''' |
| 338 | (2) clear_node_feat(G, *fts) : Clear all the node feature on graph G. |
| 339 | (6) get_cross_nes(x, y) : Get the four cross neighbors of pixel(x, y). |
| 340 | ''' |
| 341 | key_exist = lambda d, k: d.get(k) is not None |
| 342 | is_inside = lambda x, y, xmin, xmax, ymin, ymax: xmin <= x < xmax and ymin <= y < ymax |
| 343 | get_cross_nes = lambda x, y: [(x + 1, y), (x - 1, y), (x, y - 1), (x, y + 1)] |
| 344 | append_element = lambda d, k, x: d[k] + [x] if key_exist(d, k) else [x] |
| 345 | |
| 346 | def clear_node_feat(G, fts): |
| 347 | le_nodes = G.nodes |
| 348 | for k in le_nodes: |
| 349 | v = le_nodes[k] |
| 350 | for ft in fts: |
| 351 | if ft in v: |
| 352 | v[ft] = None |
| 353 | |
| 354 | clear_node_feat(mesh, ['edge_id', 'far', 'near']) |
| 355 | bord_up, bord_down = mesh.graph['bord_up'], mesh.graph['bord_down'] |
| 356 | bord_left, bord_right = mesh.graph['bord_left'], mesh.graph['bord_right'] |
| 357 | |
| 358 | le_nodes = mesh.nodes |
| 359 | |
| 360 | for node_key in le_nodes: |
| 361 | if mesh.neighbors(node_key).__length_hint__() == 4: |
| 362 | continue |
| 363 | four_nes = [xx for xx in get_cross_nes(node_key[0], node_key[1]) if |
| 364 | is_inside(xx[0], xx[1], bord_up, bord_down, bord_left, bord_right) and |
| 365 | xx in info_on_pix] |
| 366 | [four_nes.remove((ne_node[0], ne_node[1])) for ne_node in mesh.neighbors(node_key)] |
| 367 | for ne in four_nes: |
| 368 | for info in info_on_pix[ne]: |
| 369 | assert mesh.has_node((ne[0], ne[1], info['depth'])), "No node_key" |
| 370 | ind_node = le_nodes[node_key] |
| 371 | if abs(node_key[2]) > abs(info['depth']): |
| 372 | ind_node['near'] = append_element(ind_node, 'near', (ne[0], ne[1], info['depth'])) |
| 373 | else: |
| 374 | ind_node['far'] = append_element(ind_node, 'far', (ne[0], ne[1], info['depth'])) |
| 375 | if depth is not None: |
| 376 | for key, value in info_on_pix.items(): |
| 377 | if depth[key[0], key[1]] != abs(value[0]['depth']): |
| 378 | value[0]['disp'] = 1. / value[0]['depth'] |
| 379 | depth[key[0], key[1]] = abs(value[0]['depth']) |
| 380 | |
| 381 | return mesh, depth, info_on_pix |
| 382 | else: |
| 383 | return mesh |
| 384 | |
| 385 | def group_edges(LDI, config, image, remove_conflict_ordinal, spdb=False): |
| 386 |
no test coverage detected