Skip to content

Instantly share code, notes, and snippets.

@danyashorokh
Created November 15, 2019 06:59
Show Gist options
  • Save danyashorokh/bc90d3fcf77242664291f0c15622f21e to your computer and use it in GitHub Desktop.
Save danyashorokh/bc90d3fcf77242664291f0c15622f21e to your computer and use it in GitHub Desktop.
[CV] Apply alpha mask
def mask_overlay(image, mask, color=(0, 255, 0)):
"""
Helper function to visualize mask on the top of the object
"""
mask = np.dstack((mask, mask, mask)) * np.array(color)
mask = mask.astype(np.uint8)
weighted_sum = cv2.addWeighted(mask, 0.5, image, 0.5, 0.)
img = image.copy()
ind = mask[:, :, 1] > 0
img[ind] = weighted_sum[ind]
return img
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment