TextImage
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.
font_pathPath to the font file to use for rendering text.
stopwordsList of stopwords for text augmentation.
augmentationsList 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_rangeRange for selecting a fraction of bounding boxes to modify.
font_size_fraction_rangeRange for selecting the font size as a fraction of bounding box height.
font_colorFont color as RGB values (e.g., (0, 0, 0) for black).
clear_bgWhether to clear the background before rendering text.
metadata_keyKey to access metadata in the parameters.
pProbability of applying the transform.
>>> import albumentations as A
>>> transform = A.Compose([
A.TextImage(
font_path=Path("/path/to/font.ttf"),
stopwords=("the", "is", "in"),
augmentations=("insertion", "deletion"),
fraction_range=(0.5, 1.0),
font_size_fraction_range=(0.5, 0.9),
font_color=(255, 0, 0), # red in RGB
metadata_key="text_metadata",
p=0.5
)
])
>>> transformed = transform(image=my_image, text_metadata=my_metadata)
>>> image = transformed['image']
# This will render text on `my_image` based on the metadata provided in `my_metadata`.- doc-augmentationhttps://github.com/danaaubakirova/doc-augmentation