albumentations.augmentations.text.transforms


Transforms for text rendering and augmentation on images. This module provides transforms for adding and manipulating text on images, including text augmentation techniques like word insertion, deletion, and swapping.

Members

TextImageclass

TextImage(
    font_path: str | Path,
    stopwords: tuple[str, ...] = ('the', 'is', 'in', 'at', 'of'),
    augmentations: tuple[Literal['insertion', 'swap', 'deletion'] | None, ...] = (None,),
    fraction_range: tuple[float, float] = (1.0, 1.0),
    font_size_fraction_range: tuple[float, float] = (0.8, 0.9),
    font_color: tuple[float, ...] = (0, 0, 0),
    clear_bg: bool = False,
    metadata_key: str = textimage_metadata,
    p: float = 0.5
)

Apply text rendering transformations on images. This class supports rendering text directly onto images using a variety of configurations, such as custom fonts, font sizes, colors, and augmentation methods. The text can be placed inside specified bounding boxes.

Parameters

NameTypeDefaultDescription
font_path
One of:
  • str
  • Path
-Path to the font file to use for rendering text.
stopwordstuple[str, ...]('the', 'is', 'in', 'at', 'of')List of stopwords for text augmentation.
augmentations
One of:
  • tuple[Literal['insertion', 'swap', 'deletion'] | None, ...]
(None,)List of text augmentations to apply. None: text is printed as is "insertion": insert random stop words into the text. "swap": swap random words in the text. "deletion": delete random words from the text.
fraction_rangetuple[float, float](1.0, 1.0)Range for selecting a fraction of bounding boxes to modify.
font_size_fraction_rangetuple[float, float](0.8, 0.9)Range for selecting the font size as a fraction of bounding box height.
font_colortuple[float, ...](0, 0, 0)Font color as RGB values (e.g., (0, 0, 0) for black).
clear_bgboolFalseWhether to clear the background before rendering text.
metadata_keystrtextimage_metadataKey to access metadata in the parameters.
pfloat0.5Probability of applying the transform.