MCPcopy Create free account
hub / github.com/thygate/stable-diffusion-webui-depthmap-script / create_placeholder

Function create_placeholder

inpaint/utils.py:586–663  ·  view source on GitHub ↗
(context, mask, depth, fpath_map, npath_map, mesh, inpaint_id, edge_ccs, extend_edge_cc, all_edge_maps, self_edge_id)

Source from the content-addressed store, hash-verified

584
585
586def create_placeholder(context, mask, depth, fpath_map, npath_map, mesh, inpaint_id, edge_ccs, extend_edge_cc, all_edge_maps, self_edge_id):
587 add_node_time = 0
588 add_edge_time = 0
589 add_far_near_time = 0
590 valid_area = context + mask
591 H, W = mesh.graph['H'], mesh.graph['W']
592 edge_cc = edge_ccs[self_edge_id]
593 num_com = len(edge_cc) + len(extend_edge_cc)
594 hxs, hys = np.where(mask > 0)
595 for hx, hy in zip(hxs, hys):
596 mesh.add_node((hx, hy), inpaint_id=inpaint_id + 1, num_context=num_com)
597 for hx, hy in zip(hxs, hys):
598 four_nes = [(x, y) for x, y in [(hx + 1, hy), (hx - 1, hy), (hx, hy + 1), (hx, hy - 1)] if\
599 0 <= x < mesh.graph['H'] and 0 <= y < mesh.graph['W'] and valid_area[x, y] != 0]
600 for ne in four_nes:
601 if mask[ne[0], ne[1]] != 0:
602 if not mesh.has_edge((hx, hy), ne):
603 mesh.add_edge((hx, hy), ne)
604 elif depth[ne[0], ne[1]] != 0:
605 if mesh.has_node((ne[0], ne[1], depth[ne[0], ne[1]])) and\
606 not mesh.has_edge((hx, hy), (ne[0], ne[1], depth[ne[0], ne[1]])):
607 mesh.add_edge((hx, hy), (ne[0], ne[1], depth[ne[0], ne[1]]))
608 else:
609 print("Undefined context node.")
610 import pdb; pdb.set_trace()
611 near_ids = np.unique(npath_map)
612 if near_ids[0] == -1: near_ids = near_ids[1:]
613 for near_id in near_ids:
614 hxs, hys = np.where((fpath_map == near_id) & (mask > 0))
615 if hxs.shape[0] > 0:
616 mesh.graph['max_edge_id'] = mesh.graph['max_edge_id'] + 1
617 else:
618 break
619 for hx, hy in zip(hxs, hys):
620 mesh.nodes[(hx, hy)]['edge_id'] = int(round(mesh.graph['max_edge_id']))
621 four_nes = [(x, y) for x, y in [(hx + 1, hy), (hx - 1, hy), (hx, hy + 1), (hx, hy - 1)] if\
622 x < mesh.graph['H'] and x >= 0 and y < mesh.graph['W'] and y >= 0 and npath_map[x, y] == near_id]
623 for xx in four_nes:
624 xx_n = copy.deepcopy(xx)
625 if not mesh.has_node(xx_n):
626 if mesh.has_node((xx_n[0], xx_n[1], depth[xx_n[0], xx_n[1]])):
627 xx_n = (xx_n[0], xx_n[1], depth[xx_n[0], xx_n[1]])
628 if mesh.has_edge((hx, hy), xx_n):
629 # pass
630 mesh.remove_edge((hx, hy), xx_n)
631 if mesh.nodes[(hx, hy)].get('near') is None:
632 mesh.nodes[(hx, hy)]['near'] = []
633 mesh.nodes[(hx, hy)]['near'].append(xx_n)
634 connect_point_exception = set()
635 hxs, hys = np.where((npath_map == near_id) & (all_edge_maps > -1))
636 for hx, hy in zip(hxs, hys):
637 unknown_id = int(round(all_edge_maps[hx, hy]))
638 if unknown_id != near_id and unknown_id != self_edge_id:
639 unknown_node = set([xx for xx in edge_ccs[unknown_id] if xx[0] == hx and xx[1] == hy])
640 connect_point_exception |= unknown_node
641 hxs, hys = np.where((npath_map == near_id) & (mask > 0))
642 if hxs.shape[0] > 0:
643 mesh.graph['max_edge_id'] = mesh.graph['max_edge_id'] + 1

Callers 1

DL_inpaint_edgeFunction · 0.90

Calls 2

getMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected