Skip to content

Instantly share code, notes, and snippets.

@carlosejimenez
Created February 16, 2021 22:55
Show Gist options
  • Select an option

  • Save carlosejimenez/85d979ec1bcaeae100606c3e838cbe8f to your computer and use it in GitHub Desktop.

Select an option

Save carlosejimenez/85d979ec1bcaeae100606c3e838cbe8f to your computer and use it in GitHub Desktop.
def get_bbox(obj, max_x, max_y, padding=6):
x0, y0 = obj['x'], obj['y']
x1, y1 = x0 + obj['w'], y0 + obj['h']
return max(x0-padding, 0), min(x1+padding, max_x), max(y0-padding, 0), min(y1+padding, max_y)
def blur_context(img, sigma, bboxes):
ksize = 0
img_blurred = cv2.GaussianBlur(img, (ksize, ksize), sigma)
objs_mask = np.zeros_like(img)
for bbox in bboxes:
x0, x1, y0, y1 = bbox
objs_mask[y0:y1, x0:x1:, :] = 255
objs_mask_blurred = cv2.GaussianBlur(objs_mask, (ksize, ksize), sigma) / 255
return (img_blurred * (1 - objs_mask_blurred) + objs_mask_blurred * img).round().clip(0, 255).astype('uint8')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment