MCPcopy Create free account
hub / github.com/tensorpack/tensorpack / draw_mask

Function draw_mask

examples/FasterRCNN/viz.py:124–139  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

122
123
124def 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

Callers 2

draw_annotationFunction · 0.85
draw_final_outputsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…