def visualize_instance(instance,
                       ignore_ins_id=0,
                       image=None,
                       weight=0.5,
                       use_random_color=False):
    """
    Visualize instance segmentation results.

    Args:
        instance (np.ndarray): The instance segmentation results, whose shape is (h, w).
        ignore_ins_id (int, optional): ID for background area that you do not want to plot.
        image (np.ndarray, optional): The original input image. Merge the segmentation result 
            with `image` if it is provided. Default: None.
        weight (float, optional): The weight of original image when performing image merge. 
            Default: 0.5.
        use_random_color (bool, optional): Whether or not to use randomly selected color to
            visualize instances. Default: False.
    """
    # Add color map for instance segmentation result
    ids = np.unique(instance)
    num_colors = len(ids)
    colormap = np.zeros((num_colors, 3), dtype=np.uint8)
    # Make a copy to avoid in-place modification on the input
    instance = instance.copy()
    # Maps label to continuous value
    for i in range(num_colors):
        instance[instance == ids[i]] = i
        if use_random_color:
            colormap[i, :] = random_color(maximum=255)
        else:
            colormap[i, :] = _COLORS[i] * 255
        if ids[i] == ignore_ins_id:
            colormap[i, :] = np.array([0, 0, 0])
    colored_instance = colormap[instance]

    if image is not None:
        colored_instance = cv2.addWeighted(image, weight, colored_instance,
                                           1 - weight, 0)
    return colored_instance

    Visualize instance segmentation results.

    Args:
        instance (np.ndarray): The instance segmentation results, whose shape is (h, w).
        ignore_ins_id (int, optional): ID for background area that you do not want to plot.
        image (np.ndarray, optional): The original input image. Merge the segmentation result 
            with `image` if it is provided. Default: None.
        weight (float, optional): The weight of original image when performing image merge. 
            Default: 0.5.
        use_random_color (bool, optional): Whether or not to use randomly selected color to
            visualize instances. Default: False.
    
contrib/PanopticSeg/paddlepanseg/utils/visualize.py