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

Function smooth_cntsyn_gap

inpaint/utils.py:913–940  ·  view source on GitHub ↗
(init_depth_map, mask_region, context_region, init_mask_region=None)

Source from the content-addressed store, hash-verified

911 return omaps
912
913def smooth_cntsyn_gap(init_depth_map, mask_region, context_region, init_mask_region=None):
914 if init_mask_region is not None:
915 curr_mask_region = init_mask_region * 1
916 else:
917 curr_mask_region = mask_region * 0
918 depth_map = init_depth_map.copy()
919 for _ in range(2):
920 cm_mask = context_region + curr_mask_region
921 depth_s1 = np.roll(depth_map, 1, 0)
922 depth_s2 = np.roll(depth_map, -1, 0)
923 depth_s3 = np.roll(depth_map, 1, 1)
924 depth_s4 = np.roll(depth_map, -1, 1)
925 mask_s1 = np.roll(cm_mask, 1, 0)
926 mask_s2 = np.roll(cm_mask, -1, 0)
927 mask_s3 = np.roll(cm_mask, 1, 1)
928 mask_s4 = np.roll(cm_mask, -1, 1)
929 fluxin_depths = (depth_s1 * mask_s1 + depth_s2 * mask_s2 + depth_s3 * mask_s3 + depth_s4 * mask_s4) / \
930 ((mask_s1 + mask_s2 + mask_s3 + mask_s4) + 1e-6)
931 fluxin_mask = (fluxin_depths != 0) * mask_region
932 init_mask = (fluxin_mask * (curr_mask_region >= 0).astype(np.float32) > 0).astype(np.uint8)
933 depth_map[init_mask > 0] = fluxin_depths[init_mask > 0]
934 if init_mask.shape[-1] > curr_mask_region.shape[-1]:
935 curr_mask_region[init_mask.sum(-1, keepdims=True) > 0] = 1
936 else:
937 curr_mask_region[init_mask > 0] = 1
938 depth_map[fluxin_mask > 0] = fluxin_depths[fluxin_mask > 0]
939
940 return depth_map
941
942def read_MiDaS_depth(disp_fi, disp_rescale=10., h=None, w=None):
943 if 'npy' in os.path.splitext(disp_fi)[-1]:

Callers 1

depth_inpaintingFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected