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

Function create_mesh

inpaint/mesh.py:34–68  ·  view source on GitHub ↗
(depth, image, int_mtx, config)

Source from the content-addressed store, hash-verified

32import sys
33
34def create_mesh(depth, image, int_mtx, config):
35 H, W, C = image.shape
36 ext_H, ext_W = H + 2 * config['extrapolation_thickness'], W + 2 * config['extrapolation_thickness']
37 LDI = netx.Graph(H=ext_H, W=ext_W, noext_H=H, noext_W=W, cam_param=int_mtx)
38 xy2depth = {}
39 int_mtx_pix = int_mtx * np.array([[W], [H], [1.]])
40 LDI.graph['cam_param_pix'], LDI.graph['cam_param_pix_inv'] = int_mtx_pix, np.linalg.inv(int_mtx_pix)
41 disp = 1. / (-depth)
42 LDI.graph['hoffset'], LDI.graph['woffset'] = config['extrapolation_thickness'], config['extrapolation_thickness']
43 LDI.graph['bord_up'], LDI.graph['bord_down'] = LDI.graph['hoffset'] + 0, LDI.graph['hoffset'] + H
44 LDI.graph['bord_left'], LDI.graph['bord_right'] = LDI.graph['woffset'] + 0, LDI.graph['woffset'] + W
45 for idx in range(H):
46 for idy in range(W):
47 x, y = idx + LDI.graph['hoffset'], idy + LDI.graph['woffset']
48 LDI.add_node((x, y, -depth[idx, idy]),
49 color=image[idx, idy],
50 disp=disp[idx, idy],
51 synthesis=False,
52 cc_id=set())
53 xy2depth[(x, y)] = [-depth[idx, idy]]
54 for x, y, d in LDI.nodes:
55 two_nes = [ne for ne in [(x+1, y), (x, y+1)] if ne[0] < LDI.graph['bord_down'] and ne[1] < LDI.graph['bord_right']]
56 [LDI.add_edge((ne[0], ne[1], xy2depth[ne][0]), (x, y, d)) for ne in two_nes]
57 LDI = calculate_fov(LDI)
58 image = np.pad(image,
59 pad_width=((config['extrapolation_thickness'], config['extrapolation_thickness']),
60 (config['extrapolation_thickness'], config['extrapolation_thickness']),
61 (0, 0)),
62 mode='constant')
63 depth = np.pad(depth,
64 pad_width=((config['extrapolation_thickness'], config['extrapolation_thickness']),
65 (config['extrapolation_thickness'], config['extrapolation_thickness'])),
66 mode='constant')
67
68 return LDI, xy2depth, image, depth
69
70
71def tear_edges(mesh, threshold = 0.00025, xy2depth=None):

Callers 1

write_meshFunction · 0.70

Calls 1

calculate_fovFunction · 0.85

Tested by

no test coverage detected