Args: soft_mask (ndarray): float array of shape (H, W), each value in [0, 1]. color: color of the mask. Refer to `matplotlib.colors` for a full list of formats that are accepted. If None, will pick a random color. text (str): if None, will
(self, soft_mask, color=None, *, text=None, alpha=0.5)
| 1096 | return self.output |
| 1097 | |
| 1098 | def draw_soft_mask(self, soft_mask, color=None, *, text=None, alpha=0.5): |
| 1099 | """ |
| 1100 | Args: |
| 1101 | soft_mask (ndarray): float array of shape (H, W), each value in [0, 1]. |
| 1102 | color: color of the mask. Refer to `matplotlib.colors` for a full list of |
| 1103 | formats that are accepted. If None, will pick a random color. |
| 1104 | text (str): if None, will be drawn on the object |
| 1105 | alpha (float): blending efficient. Smaller values lead to more transparent masks. |
| 1106 | |
| 1107 | Returns: |
| 1108 | output (VisImage): image object with mask drawn. |
| 1109 | """ |
| 1110 | if color is None: |
| 1111 | color = random_color(rgb=True, maximum=1) |
| 1112 | color = mplc.to_rgb(color) |
| 1113 | |
| 1114 | shape2d = (soft_mask.shape[0], soft_mask.shape[1]) |
| 1115 | rgba = np.zeros(shape2d + (4,), dtype="float32") |
| 1116 | rgba[:, :, :3] = color |
| 1117 | rgba[:, :, 3] = soft_mask * alpha |
| 1118 | self.output.ax.imshow(rgba, extent=(0, self.output.width, self.output.height, 0)) |
| 1119 | |
| 1120 | if text is not None: |
| 1121 | lighter_color = self._change_color_brightness(color, brightness_factor=0.7) |
| 1122 | binary_mask = (soft_mask > 0.5).astype("uint8") |
| 1123 | self._draw_text_in_mask(binary_mask, text, lighter_color) |
| 1124 | return self.output |
| 1125 | |
| 1126 | def draw_polygon(self, segment, color, edge_color=None, alpha=0.5): |
| 1127 | """ |
nothing calls this directly
no test coverage detected