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.
line_geometryGeometry used for line
artifacts. "axis_aligned" preserves horizontal and vertical lines. "random_endpoints" samples
both endpoints independently. "random_angle" samples a start point, angle, and length.
Default: "axis_aligned".
line_stylesLine styles sampled for lines, arrows, and callouts. Default: ("solid", "dashed", "dotted").
line_style_probabilitiesSampling weights matching line_styles. Values must be
non-negative and at least one value must be positive. Default: (0.55, 0.35, 0.1).
random_color_probProbability of sampling every image channel independently and uniformly from
[0, 255]. The remaining probability uses color_palette when provided, otherwise the legacy
black/white/red policy. Default: 0.0.
color_paletteOptional artifact colors in [0, 255]. Colors are
truncated or extended using their last value to match the image channels. Default: None.
color_palette_probabilitiesOptional sampling weights matching
color_palette. When omitted, palette colors are sampled uniformly. Default: None.
line_length_rangeOptional length range in pixels for "random_angle" lines.
When omitted, line_length_ratio_range controls their length. Default: None.
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"][0, 1].