Skip to content

semseginstancelabeling

semseginstancelabeling

Module for SemSegInstanceLabel

Classes

SemSegInstanceLabel

Bases: InstanceLabel

InstanceLabel for one SemSeg error mask instance (prediction or ground truth).

Functions
calc_iou
calc_iou(other)

Calculates the IOU of the masks of two SemSegInstanceLabels

Parameters:

Returns:

  • float

    Calculated IOU

Source code in niceml/utilities/semseg/semseginstancelabeling.py
def calc_iou(self, other: "SemSegInstanceLabel") -> float:
    """
    Calculates the IOU of the masks of two `SemSegInstanceLabel`s

    Args:
        other: Second SemSegInstanceLabel to calculate the IOU with

    Returns:
        Calculated IOU
    """

    intersection = np.logical_and(self.mask, other.mask)
    union = np.logical_or(self.mask, other.mask)

    return np.sum(intersection) / np.sum(union)
scale_label
scale_label(scale_factor)

Scales an SemSegInstanceLabel by a given scale_factor

Parameters:

  • scale_factor (float) –

    Factor to scale the SemSegInstanceLabel by

Returns:

Source code in niceml/utilities/semseg/semseginstancelabeling.py
def scale_label(self, scale_factor: float) -> "SemSegInstanceLabel":
    """
    Scales an SemSegInstanceLabel by a given `scale_factor`

    Args:
        scale_factor: Factor to scale the SemSegInstanceLabel by

    Returns:
        Scaled instance of this SemSegInstanceLabel
    """
    scaled_mask = cv2.resize(  # pylint: disable = no-member
        self.mask,
        dsize=None,
        fx=scale_factor,
        fy=scale_factor,
        interpolation=cv2.INTER_NEAREST,  # pylint: disable = no-member,
    )
    return SemSegInstanceLabel(
        class_name=self.class_name,
        class_index=self.class_index,
        color=self.color,
        active=self.active,
        mask=scaled_mask,
    )