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

Function find_largest_rect

inpaint/utils.py:1403–1416  ·  view source on GitHub ↗
(dst_img, bg_color=(128, 128, 128))

Source from the content-addressed store, hash-verified

1401 return i, i + mh, j, j + mw
1402
1403def find_largest_rect(dst_img, bg_color=(128, 128, 128)):
1404 valid = np.any(dst_img[..., :3] != bg_color, axis=-1)
1405 dst_h, dst_w = dst_img.shape[:2]
1406 ret, labels = cv2.connectedComponents(np.uint8(valid == False))
1407 red_mat = np.zeros_like(labels)
1408 # denoise
1409 for i in range(1, np.max(labels)+1, 1):
1410 x, y, w, h = cv2.boundingRect(np.uint8(labels==i))
1411 if x == 0 or (x+w) == dst_h or y == 0 or (y+h) == dst_w:
1412 red_mat[labels==i] = 1
1413 # crop
1414 t, b, l, r = find_anchors(red_mat)
1415
1416 return t, b, l, r

Callers

nothing calls this directly

Calls 1

find_anchorsFunction · 0.85

Tested by

no test coverage detected