Overlay a mask on top of the image. Args: im: a 3-channel uint8 image in BGR mask: a binary 1-channel image of the same size color: if None, will choose automatically
(im, mask, alpha=0.5, color=None)
| 122 | |
| 123 | |
| 124 | def draw_mask(im, mask, alpha=0.5, color=None): |
| 125 | """ |
| 126 | Overlay a mask on top of the image. |
| 127 | |
| 128 | Args: |
| 129 | im: a 3-channel uint8 image in BGR |
| 130 | mask: a binary 1-channel image of the same size |
| 131 | color: if None, will choose automatically |
| 132 | """ |
| 133 | if color is None: |
| 134 | color = PALETTE_RGB[np.random.choice(len(PALETTE_RGB))][::-1] |
| 135 | color = np.asarray(color, dtype=np.float32) |
| 136 | im = np.where(np.repeat((mask > 0)[:, :, None], 3, axis=2), |
| 137 | im * (1 - alpha) + color * alpha, im) |
| 138 | im = im.astype('uint8') |
| 139 | return im |
no outgoing calls
no test coverage detected
searching dependent graphs…