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

Function clean_far_edge_new

inpaint/utils.py:114–339  ·  view source on GitHub ↗
(input_edge, end_depth_maps, mask, context, global_mesh, info_on_pix, self_edge, inpaint_id, config)

Source from the content-addressed store, hash-verified

112 return other_edges, end_depth_maps, other_edges_info
113
114def clean_far_edge_new(input_edge, end_depth_maps, mask, context, global_mesh, info_on_pix, self_edge, inpaint_id, config):
115 mesh = netx.Graph()
116 hxs, hys = np.where(input_edge * mask > 0)
117 valid_near_edge = (input_edge != 0).astype(np.uint8) * context
118 valid_map = mask + context
119 invalid_edge_ids = []
120 for hx, hy in zip(hxs, hys):
121 node = (hx ,hy)
122 mesh.add_node((hx, hy))
123 eight_nes = [ne for ne in [(hx + 1, hy), (hx - 1, hy), (hx, hy + 1), (hx, hy - 1), \
124 (hx + 1, hy + 1), (hx - 1, hy - 1), (hx - 1, hy + 1), (hx + 1, hy - 1)]\
125 if 0 <= ne[0] < input_edge.shape[0] and 0 <= ne[1] < input_edge.shape[1] and 0 < input_edge[ne[0], ne[1]]] # or end_depth_maps[ne[0], ne[1]] != 0]
126 for ne in eight_nes:
127 mesh.add_edge(node, ne, length=np.hypot(ne[0] - hx, ne[1] - hy))
128 if end_depth_maps[ne[0], ne[1]] != 0:
129 mesh.nodes[ne[0], ne[1]]['cnt'] = True
130 if end_depth_maps[ne[0], ne[1]] == 0:
131 import pdb; pdb.set_trace()
132 mesh.nodes[ne[0], ne[1]]['depth'] = end_depth_maps[ne[0], ne[1]]
133 elif mask[ne[0], ne[1]] != 1:
134 four_nes = [nne for nne in [(ne[0] + 1, ne[1]), (ne[0] - 1, ne[1]), (ne[0], ne[1] + 1), (ne[0], ne[1] - 1)]\
135 if nne[0] < end_depth_maps.shape[0] and nne[0] >= 0 and nne[1] < end_depth_maps.shape[1] and nne[1] >= 0]
136 for nne in four_nes:
137 if end_depth_maps[nne[0], nne[1]] != 0:
138 mesh.add_edge(nne, ne, length=np.hypot(nne[0] - ne[0], nne[1] - ne[1]))
139 mesh.nodes[nne[0], nne[1]]['cnt'] = True
140 mesh.nodes[nne[0], nne[1]]['depth'] = end_depth_maps[nne[0], nne[1]]
141 ccs = [*netx.connected_components(mesh)]
142 end_pts = []
143 for cc in ccs:
144 end_pts.append(set())
145 for node in cc:
146 if mesh.nodes[node].get('cnt') is not None:
147 end_pts[-1].add((node[0], node[1], mesh.nodes[node]['depth']))
148 predef_npaths = [None for _ in range(len(ccs))]
149 fpath_map = np.zeros_like(input_edge) - 1
150 npath_map = np.zeros_like(input_edge) - 1
151 npaths, fpaths = dict(), dict()
152 break_flag = False
153 end_idx = 0
154 while end_idx < len(end_pts):
155 end_pt, cc = [*zip(end_pts, ccs)][end_idx]
156 end_idx += 1
157 sorted_end_pt = []
158 fpath = []
159 iter_fpath = []
160 if len(end_pt) > 2 or len(end_pt) == 0:
161 if len(end_pt) > 2:
162 continue
163 continue
164 if len(end_pt) == 2:
165 ravel_end = [*end_pt]
166 tmp_sub_mesh = mesh.subgraph(list(cc)).copy()
167 tmp_npath = [*netx.shortest_path(tmp_sub_mesh, (ravel_end[0][0], ravel_end[0][1]), (ravel_end[1][0], ravel_end[1][1]), weight='length')]
168 fpath_map1, npath_map1, disp_diff1 = plan_path(mesh, info_on_pix, cc, ravel_end[0:1], global_mesh, input_edge, mask, valid_map, inpaint_id, npath_map=None, fpath_map=None, npath=tmp_npath)
169 fpath_map2, npath_map2, disp_diff2 = plan_path(mesh, info_on_pix, cc, ravel_end[1:2], global_mesh, input_edge, mask, valid_map, inpaint_id, npath_map=None, fpath_map=None, npath=tmp_npath)
170 tmp_disp_diff = [disp_diff1, disp_diff2]
171 self_end = []

Callers 1

DL_inpaint_edgeFunction · 0.90

Calls 4

plan_pathFunction · 0.85
plan_path_e2eFunction · 0.85
appendMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected