Visualize a mask on top of an image. Args: mask (np.ndarray): A 2D array of shape (H, W). image (np.ndarray): A 3D array of shape (H, W, 3). random_color (bool): Whether to use a random color for the mask. Outputs: np.ndarray: A 3D arra
(self, mask: np.ndarray,image: np.ndarray,
random_color: bool = False, transparency=1)
| 821 | |
| 822 | |
| 823 | def show_mask(self, mask: np.ndarray,image: np.ndarray, |
| 824 | random_color: bool = False, transparency=1) -> np.ndarray: |
| 825 | |
| 826 | """Visualize a mask on top of an image. |
| 827 | Args: |
| 828 | mask (np.ndarray): A 2D array of shape (H, W). |
| 829 | image (np.ndarray): A 3D array of shape (H, W, 3). |
| 830 | random_color (bool): Whether to use a random color for the mask. |
| 831 | Outputs: |
| 832 | np.ndarray: A 3D array of shape (H, W, 3) with the mask |
| 833 | visualized on top of the image. |
| 834 | transparenccy: the transparency of the segmentation mask |
| 835 | """ |
| 836 | |
| 837 | if random_color: |
| 838 | color = np.concatenate([np.random.random(3)], axis=0) |
| 839 | else: |
| 840 | color = np.array([30 / 255, 144 / 255, 255 / 255]) |
| 841 | h, w = mask.shape[-2:] |
| 842 | mask_image = mask.reshape(h, w, 1) * color.reshape(1, 1, -1) * 255 |
| 843 | |
| 844 | image = cv2.addWeighted(image, 0.7, mask_image.astype('uint8'), transparency, 0) |
| 845 | |
| 846 | |
| 847 | return image |
| 848 | |
| 849 | def show_box(self, box, ax, label): |
| 850 | x0, y0 = box[0], box[1] |
no outgoing calls
no test coverage detected