(ax: Axes, mask: torch.Tensor | np.ndarray | None)
| 93 | @as_chain_func |
| 94 | @IgnoreException |
| 95 | def plot_mask(ax: Axes, mask: torch.Tensor | np.ndarray | None) -> Axes: |
| 96 | if mask is None: return ax |
| 97 | if isinstance(mask, torch.Tensor): |
| 98 | mask = mask.float().detach().cpu().numpy() |
| 99 | |
| 100 | H, W = mask.shape |
| 101 | rgba_mask = np.zeros((H, W, 4)) |
| 102 | rgba_mask[..., 0:3] = 1 |
| 103 | rgba_mask[..., 3] = 1 - mask # Alpha channel (0 = transparent, 1 = opaque) |
| 104 | ax.imshow(rgba_mask) |
| 105 | return ax |
| 106 | |
| 107 | @as_chain_func |
| 108 | @IgnoreException |