INNER CODE UNIT · Python
mask
Anything-of-anything/Anything-3D · AnyObject3D/src/main.py:40
mask = masks[np.argmax(scores)][:, :, None].astype(np.uint8) * 255
res = np.where(mask > 0)
y1, y2 = np.min(res[0]), np.max(res[0])
x1, x2 = np.min(res[1]), np.max(res[1])
cx, cy = (x1 + x2) / 2., (y1 + y2) / 2.
w, h = x2 - x1, y2 - y1
crop_sz = 1.8 * math.sqrt(w * h) # context_ratio
x1, x2 = cx - crop_sz / 2., cx + crop_sz / 2.
y1, y2 = cy - crop_sz / 2., cy + crop_sz / 2.
x1, y1, x2, y2 = list(map(lambda x: int(x), [x1, y1, x2, y2]))
# affine transform to get the object-centric image
bbox = [x1, y1, x2, y2]
output_sz = 512
a = (output_sz-1) / (bbox[2]-bbox[0])
b = (output_sz-1) / (bbox[3]-bbox[1])
c = -a * bbox[0]
d = -b * bbox[1]