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.
element_typesArtifact types to sample. Default: ("text", "rectangle", "arrow", "line", "callout").
element_probabilitiesSampling 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_rangeRange for the number of artifacts drawn per image. Default: (1, 3).
text_length_rangeRange for generated text token length. Text uses uppercase ASCII letters and digits. Default: (1, 5).
font_scale_rangeRange for OpenCV Hershey font scale. Default: (0.3, 1.2).
thickness_rangeRange for line, rectangle, arrow, and text thickness. Default: (1, 3).
size_ratio_rangeRange for rectangle and callout size as a fraction of image width and height. Default: (0.1, 0.35).
line_length_ratio_rangeRange for line and arrow length as a fraction of the smaller image dimension. Default: (0.1, 0.8).
tip_length_rangeRange for arrowhead length as a fraction of arrow length. Default: (0.2, 0.4).
corner_probProbability of placing artifacts near image corners or edges instead of uniformly inside the image. Default: 0.6.
black_white_probProbability of choosing black or white instead of red for an artifact. Default: 0.85.
pProbability of applying the transform. Default: 0.5.
>>> 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"]