def test_get_most_populous_class2():
    """
	"""
    segment_mask = np.array([[1, 0, 0], [1, 1, 0], [0, 1, 0]])
    label_map = np.array([[9, 8, 8], [7, 7, 8], [8, 7, 8]])
    assert get_most_populous_class(segment_mask, label_map) == 7
    def overlay_instances(
        self,
        label_map,
        id_to_class_name_map,
        alpha=0.5
    ):
        """
        Args:
            boxes (Boxes, RotatedBoxes or ndarray): either a :class:`Boxes`,
                or an Nx4 numpy array of XYXY_ABS format for the N objects in a single image,
                or a :class:`RotatedBoxes`,
                or an Nx5 numpy array of (x_center, y_center, width, height, angle_degrees) format
                for the N objects in a single image,
            labels (list[str]): the text to be displayed for each instance.
            masks (masks-like object): Supported types are:

                * `structures.masks.PolygonMasks`, `structures.masks.BitMasks`.
                * list[list[ndarray]]: contains the segmentation masks for all objects in one image.
                    The first level of the list corresponds to individual instances. The second
                    level to all the polygon that compose the instance, and the third level
                    to the polygon coordinates. The third level should have the format of
                    [x0, y0, x1, y1, ..., xn, yn] (n >= 3).
                * list[ndarray]: each ndarray is a binary mask of shape (H, W).
                * list[dict]: each dict is a COCO-style RLE.
            keypoints (Keypoint or array like): an array-like object of shape (N, K, 3),
                where the N is the number of instances and K is the number of keypoints.
                The last dimension corresponds to (x, y, visibility or score).
            assigned_colors (list[matplotlib.colors]): a list of colors, where each color
                corresponds to each mask or box in the image. Refer to 'matplotlib.colors'
                for full list of formats that the colors are accepted in.

        Returns:
            output (VisImage): image object with visualizations.
        """
        for label_idx in np.unique(label_map):
            color = fixed_color(rgb=True, maximum=1, idx=label_idx)
            text = id_to_class_name_map[label_idx]

            segment = label_map == label_idx

            #import pdb; pdb.set_trace()
            mask_obj = GenericMask(segment, self.output.height, self.output.width)
            polygons, _ = mask_obj.mask_to_polygons(segment)



            for polygon_verts in polygons:
                #print('Polygon verts: ', polygon_verts)
                
                # rasterize this specific polygon
                segment_mask = get_mask_from_polygon(polygon_verts, self.output.height, self.output.width)
                class_mode_idx = get_most_populous_class(segment_mask, label_map)
                if class_mode_idx != label_idx:
                    continue
                self.draw_polygon(polygon_verts, color, alpha=alpha)

                # import matplotlib.pyplot as plt
                # plt.imshow(segment_mask)
                # plt.show()

                # draw text in the center (defined by median) when box is not drawn
                # median is less sensitive to outliers.
                text_pos = np.median(segment_mask.nonzero(), axis=1)[::-1]
                horiz_align = "center"

                x0 = np.amin(polygon_verts[:,0])
                x1 = np.amax(polygon_verts[:,0])

                y0 = np.amin(polygon_verts[:,1])
                y1 = np.amax(polygon_verts[:,1])

                # else:
                #     continue  # drawing the box confidence for keypoints isn't very useful.
                # # for small objects, draw text at the side to avoid occlusion
                # instance_area = (y1 - y0) * (x1 - x0)
                # if (
                #     instance_area < _SMALL_OBJECT_AREA_THRESH * self.output.scale
                #     or y1 - y0 < 40 * self.output.scale
                # ):
                #     if y1 >= self.output.height - 5:
                #         text_pos = (x1, y0)
                #     else:
                #         text_pos = (x0, y1)

                height_ratio = (y1 - y0) / np.sqrt(self.output.height * self.output.width)
                lighter_color = self._change_color_brightness(color, brightness_factor=0.7)
                font_size = (
                    np.clip((height_ratio - 0.02) / 0.08 + 1, 1.2, 2)
                    * 0.5
                    * self._default_font_size
                )
                self.draw_text(
                    text,
                    text_pos,
                    color=lighter_color,
                    horizontal_alignment=horiz_align,
                    font_size=font_size,
                )
                # import matplotlib.pyplot as plt
                # plt.imshow(self.output.get_image())
                # plt.show()

        return self.output.get_image()