Created
November 15, 2019 06:59
-
-
Save danyashorokh/bc90d3fcf77242664291f0c15622f21e to your computer and use it in GitHub Desktop.
[CV] Apply alpha mask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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