(mesh, edge_mesh, edge_ccs, info_on_pix, config, redundant_number=1000, invalid=False, spdb=False)
| 634 | return mesh |
| 635 | |
| 636 | def remove_redundant_edge(mesh, edge_mesh, edge_ccs, info_on_pix, config, redundant_number=1000, invalid=False, spdb=False): |
| 637 | point_to_amount = {} |
| 638 | point_to_id = {} |
| 639 | end_maps = np.zeros((mesh.graph['H'], mesh.graph['W'])) - 1 |
| 640 | for valid_edge_id, valid_edge_cc in enumerate(edge_ccs): |
| 641 | for valid_edge_node in valid_edge_cc: |
| 642 | point_to_amount[valid_edge_node] = len(valid_edge_cc) |
| 643 | point_to_id[valid_edge_node] = valid_edge_id |
| 644 | if edge_mesh.has_node(valid_edge_node) is True: |
| 645 | if len([*edge_mesh.neighbors(valid_edge_node)]) == 1: |
| 646 | end_maps[valid_edge_node[0], valid_edge_node[1]] = valid_edge_id |
| 647 | nxs, nys = np.where(end_maps > -1) |
| 648 | point_to_adjoint = {} |
| 649 | for nx, ny in zip(nxs, nys): |
| 650 | adjoint_edges = set([end_maps[x, y] for x, y in [(nx + 1, ny), (nx - 1, ny), (nx, ny + 1), (nx, ny - 1)] if end_maps[x, y] != -1]) |
| 651 | point_to_adjoint[end_maps[nx, ny]] = (point_to_adjoint[end_maps[nx, ny]] | adjoint_edges) if point_to_adjoint.get(end_maps[nx, ny]) is not None else adjoint_edges |
| 652 | valid_edge_ccs = filter_edge(mesh, edge_ccs, config, invalid=invalid) |
| 653 | edge_canvas = np.zeros((mesh.graph['H'], mesh.graph['W'])) - 1 |
| 654 | for valid_edge_id, valid_edge_cc in enumerate(valid_edge_ccs): |
| 655 | for valid_edge_node in valid_edge_cc: |
| 656 | edge_canvas[valid_edge_node[0], valid_edge_node[1]] = valid_edge_id |
| 657 | if spdb is True: |
| 658 | plt.imshow(edge_canvas); plt.show() |
| 659 | import pdb; pdb.set_trace() |
| 660 | for valid_edge_id, valid_edge_cc in enumerate(valid_edge_ccs): |
| 661 | end_number = 0 |
| 662 | four_end_number = 0 |
| 663 | eight_end_number = 0 |
| 664 | db_eight_end_number = 0 |
| 665 | if len(valid_edge_cc) > redundant_number: |
| 666 | continue |
| 667 | for valid_edge_node in valid_edge_cc: |
| 668 | if len([*edge_mesh.neighbors(valid_edge_node)]) == 3: |
| 669 | break |
| 670 | elif len([*edge_mesh.neighbors(valid_edge_node)]) == 1: |
| 671 | hx, hy, hz = valid_edge_node |
| 672 | if invalid is False: |
| 673 | eight_nes = [(x, y) for x, y in [(hx + 1, hy), (hx - 1, hy), (hx, hy + 1), (hx, hy - 1), |
| 674 | (hx + 1, hy + 1), (hx - 1, hy - 1), (hx - 1, hy + 1), (hx + 1, hy - 1)] \ |
| 675 | if info_on_pix.get((x, y)) is not None and edge_canvas[x, y] != -1 and edge_canvas[x, y] != valid_edge_id] |
| 676 | if len(eight_nes) == 0: |
| 677 | end_number += 1 |
| 678 | if invalid is True: |
| 679 | four_nes = []; eight_nes = []; db_eight_nes = [] |
| 680 | four_nes = [(x, y) for x, y in [(hx + 1, hy), (hx - 1, hy), (hx, hy + 1), (hx, hy - 1)] \ |
| 681 | if info_on_pix.get((x, y)) is not None and edge_canvas[x, y] != -1 and edge_canvas[x, y] != valid_edge_id] |
| 682 | eight_nes = [(x, y) for x, y in [(hx + 1, hy), (hx - 1, hy), (hx, hy + 1), (hx, hy - 1), \ |
| 683 | (hx + 1, hy + 1), (hx - 1, hy - 1), (hx - 1, hy + 1), (hx + 1, hy - 1)] \ |
| 684 | if info_on_pix.get((x, y)) is not None and edge_canvas[x, y] != -1 and edge_canvas[x, y] != valid_edge_id] |
| 685 | db_eight_nes = [(x, y) for x in range(hx - 2, hx + 3) for y in range(hy - 2, hy + 3) \ |
| 686 | if info_on_pix.get((x, y)) is not None and edge_canvas[x, y] != -1 and edge_canvas[x, y] != valid_edge_id and (x, y) != (hx, hy)] |
| 687 | if len(four_nes) == 0 or len(eight_nes) == 0: |
| 688 | end_number += 1 |
| 689 | if len(four_nes) == 0: |
| 690 | four_end_number += 1 |
| 691 | if len(eight_nes) == 0: |
| 692 | eight_end_number += 1 |
| 693 | if len(db_eight_nes) == 0: |
no test coverage detected