Draw semantic segmentation predictions/labels. Args: sem_seg (Tensor or ndarray): the segmentation of shape (H, W). Each value is the integer label of the pixel. area_threshold (int): segments with less than `area_threshold` are not drawn.
(self, sem_seg, area_threshold=None, alpha=0.8)
| 408 | return self.output |
| 409 | |
| 410 | def draw_sem_seg(self, sem_seg, area_threshold=None, alpha=0.8): |
| 411 | """ |
| 412 | Draw semantic segmentation predictions/labels. |
| 413 | |
| 414 | Args: |
| 415 | sem_seg (Tensor or ndarray): the segmentation of shape (H, W). |
| 416 | Each value is the integer label of the pixel. |
| 417 | area_threshold (int): segments with less than `area_threshold` are not drawn. |
| 418 | alpha (float): the larger it is, the more opaque the segmentations are. |
| 419 | |
| 420 | Returns: |
| 421 | output (VisImage): image object with visualizations. |
| 422 | """ |
| 423 | if isinstance(sem_seg, torch.Tensor): |
| 424 | sem_seg = sem_seg.numpy() |
| 425 | labels, areas = np.unique(sem_seg, return_counts=True) |
| 426 | sorted_idxs = np.argsort(-areas).tolist() |
| 427 | labels = labels[sorted_idxs] |
| 428 | for label in filter(lambda l: l < len(self.metadata.stuff_classes), labels): |
| 429 | try: |
| 430 | mask_color = [x / 255 for x in self.metadata.stuff_colors[label]] |
| 431 | except (AttributeError, IndexError): |
| 432 | mask_color = None |
| 433 | |
| 434 | binary_mask = (sem_seg == label).astype(np.uint8) |
| 435 | text = self.metadata.stuff_classes[label] |
| 436 | self.draw_binary_mask( |
| 437 | binary_mask, |
| 438 | color=mask_color, |
| 439 | edge_color=_OFF_WHITE, |
| 440 | text=text, |
| 441 | alpha=alpha, |
| 442 | area_threshold=area_threshold, |
| 443 | ) |
| 444 | return self.output |
| 445 | |
| 446 | def draw_panoptic_seg_predictions( |
| 447 | self, panoptic_seg, segments_info, area_threshold=None, alpha=0.7 |
no test coverage detected