from iaa_od.models import AnnotationProtocol
from dataclasses import dataclass, field
[docs]
@dataclass(slots=True, kw_only=True)
class KAlphaUnit:
"""
Data class representing a "unit" for Krippendorff's Alpha analysis.
The definition of unit comes from Krippendorff's 2011 paper "Computing Krippendorff's Alpha-Reliability".
Attributes:
id (int): Unique identifier for the unit.
img_filename (str): Filename of the image associated with the unit.
annotations (list[Annotation]): List of annotations linked to this unit.
"""
id: int
img_filename: str
annotations: list[AnnotationProtocol] = field(default_factory=list)
@property
def average_area(self) -> float:
"""
Compute the average area of the bounding boxes in the annotations for this unit.
Returns:
float: The average area of the bounding boxes, or 0 if there are no annotations.
"""
if not self.annotations:
return 0.0
total_area = sum(ann.bbox_coords.area for ann in self.annotations)
return total_area / len(self.annotations)