albumentations.augmentations.other.annotation_artifacts


Transform for synthetic annotation and callout artifacts.

AnnotationArtifactsclass

AnnotationArtifacts(
    element_types: tuple[AnnotationElementType, ...] = ('text', 'rectangle', 'arrow', 'line', 'callout'),
    element_probabilities: tuple[float, ...] = (0.35, 0.2, 0.2, 0.15, 0.1),
    count_range: tuple[int, int] = (1, 3),
    text_length_range: tuple[int, int] = (1, 5),
    font_scale_range: tuple[float, float] = (0.3, 1.2),
    thickness_range: tuple[int, int] = (1, 3),
    size_ratio_range: tuple[float, float] = (0.1, 0.35),
    line_length_ratio_range: tuple[float, float] = (0.1, 0.8),
    tip_length_range: tuple[float, float] = (0.2, 0.4),
    corner_prob: float = 0.6,
    black_white_prob: float = 0.85,
    p: float = 0.5
)

Add synthetic text, arrows, boxes, guide lines, and callouts that mimic scientific markup. Use to harden models against annotation artifacts. This transform simulates sparse human annotation artifacts commonly found in scientific figures, medical images, microscopy screenshots, and competition data. It draws short text tokens, rectangles, arrows, horizontal or vertical guide lines, and zoom-callout boxes directly on the image. Args: element_types (tuple[Literal["text", "rectangle", "arrow", "line", "callout"], ...]): Artifact types to sample. Default: ("text", "rectangle", "arrow", "line", "callout"). element_probabilities (tuple[float, ...]): Sampling weights matching `element_types`. Values must be non-negative and at least one value must be positive. Default: (0.35, 0.2, 0.2, 0.15, 0.1). count_range (tuple[int, int]): Range for the number of artifacts drawn per image. Default: (1, 3). text_length_range (tuple[int, int]): Range for generated text token length. Text uses uppercase ASCII letters and digits. Default: (1, 5). font_scale_range (tuple[float, float]): Range for OpenCV Hershey font scale. Default: (0.3, 1.2). thickness_range (tuple[int, int]): Range for line, rectangle, arrow, and text thickness. Default: (1, 3). size_ratio_range (tuple[float, float]): Range for rectangle and callout size as a fraction of image width and height. Default: (0.1, 0.35). line_length_ratio_range (tuple[float, float]): Range for line and arrow length as a fraction of the smaller image dimension. Default: (0.1, 0.8). tip_length_range (tuple[float, float]): Range for arrowhead length as a fraction of arrow length. Default: (0.2, 0.4). corner_prob (float): Probability of placing artifacts near image corners or edges instead of uniformly inside the image. Default: 0.6. black_white_prob (float): Probability of choosing black or white instead of red for an artifact. Default: 0.85. p (float): Probability of applying the transform. Default: 0.5. Targets: image, volume Image types: uint8, float32 Number of channels: Any Note: - This is an image-only transform: masks, bounding boxes, and keypoints are not modified. - Colors are adapted to the number of channels; black and white affect all channels, while red maps to the first channel and pads remaining channels with zero. - Random values are sampled before drawing, so replay and deterministic pipelines preserve the exact generated artifacts. Examples: >>> import numpy as np >>> import albumentations as A >>> >>> image = np.random.randint(0, 256, (320, 320, 3), dtype=np.uint8) >>> transform = A.Compose([ ... A.AnnotationArtifacts( ... element_types=("text", "rectangle", "arrow", "line", "callout"), ... element_probabilities=(0.35, 0.2, 0.2, 0.15, 0.1), ... count_range=(1, 3), ... corner_prob=0.6, ... p=1.0, ... ) ... ]) >>> result = transform(image=image) >>> augmented_image = result["image"] References: - Uladzislau Leketush: https://www.linkedin.com/in/leketush/ - Original augmentation gist: https://gist.github.com/vlad3996/00724aafce45374214e16eb9eb07e893 - Kaggle 1st place solution: https://github.com/vlad3996/forgeryscope/ - Competition: https://www.kaggle.com/competitions/recodai-luc-scientific-image-forgery-detection See Also: - TextImage: Metadata-driven rendering of text inside known bounding boxes. - OverlayElements: Paste supplied overlay images or masks onto an image. - CoarseDropout: Remove rectangular regions instead of adding annotation markup.

Parameters

NameTypeDefaultDescription
element_typestuple[AnnotationElementType, ...]('text', 'rectangle', 'arrow', 'line', 'callout')-
element_probabilitiestuple[float, ...](0.35, 0.2, 0.2, 0.15, 0.1)-
count_rangetuple[int, int](1, 3)-
text_length_rangetuple[int, int](1, 5)-
font_scale_rangetuple[float, float](0.3, 1.2)-
thickness_rangetuple[int, int](1, 3)-
size_ratio_rangetuple[float, float](0.1, 0.35)-
line_length_ratio_rangetuple[float, float](0.1, 0.8)-
tip_length_rangetuple[float, float](0.2, 0.4)-
corner_probfloat0.6-
black_white_probfloat0.85-
pfloat0.5-