Skip to content

semsegdrawing

semsegdrawing

Module for error mask (SemSegInstanceLabel) draw functions

Classes

Functions

draw_error_mask_on_image

draw_error_mask_on_image(label, image)

Draws an error mask of a SemSegInstanceLabel on an image

Parameters:

  • label (SemSegInstanceLabel) –

    label (error mask) to draw on the image

  • image (Image) –

    image to draw the error masks on

Returns:

  • Image

    image with the error mask

Source code in niceml/utilities/semseg/semsegdrawing.py
def draw_error_mask_on_image(
    label: SemSegInstanceLabel,
    image: ImageType,
) -> ImageType:
    """
    Draws an error mask of a SemSegInstanceLabel on an image

    Args:
        label: label (error mask) to draw on the image
        image: image to draw the error masks on

    Returns:
        image with the error mask
    """

    color_image = Image.new("RGB", image.size, label.color)
    mask_input = label.mask
    mask_input[mask_input == 255] = 100
    mask = Image.fromarray(mask_input)
    mask = mask.convert("L")
    image = Image.composite(color_image, image, mask)
    return image

draw_labels_on_image

draw_labels_on_image(
    image,
    pred_error_mask_label_list,
    gt_error_mask_label_list,
    hide_gt=False,
)

Draws multiple prediction and ground truth error mask labels (SemSegInstanceLabel) on an image

Parameters:

  • image (Image) –

    image to draw the error masks on

  • pred_error_mask_label_list (List[SemSegInstanceLabel]) –

    list of prediction error mask labels

  • gt_error_mask_label_list (List[SemSegInstanceLabel]) –

    list of ground truth error mask labels

  • hide_gt (bool, default: False ) –

    flag to hide the gt labels

Returns:

  • Image

    Image with predicted and ground truth error masks

Source code in niceml/utilities/semseg/semsegdrawing.py
def draw_labels_on_image(  # pylint: disable=too-many-arguments
    image: ImageType,
    pred_error_mask_label_list: List[SemSegInstanceLabel],
    gt_error_mask_label_list: List[SemSegInstanceLabel],
    hide_gt: bool = False,
) -> ImageType:
    """

    Draws multiple prediction and ground truth error mask labels
    (SemSegInstanceLabel) on an image

    Args:
        image: image to draw the error masks on
        pred_error_mask_label_list: list of prediction error mask labels
        gt_error_mask_label_list: list of ground truth error mask labels
        hide_gt: flag to hide the gt labels

    Returns:
        Image with predicted and ground truth error masks
    """

    for pred_label in pred_error_mask_label_list:
        if pred_label.active:
            image = draw_error_mask_on_image(image=image, label=pred_label)

    if not hide_gt:
        for gt_label in gt_error_mask_label_list:
            if gt_label.active:
                image = draw_error_mask_on_image(image=image, label=gt_label)
    return image