Effect

class text_renderer.effect.Effect(p: float = 0.5)[source]

Base class for applying different augmentations to images.

This abstract base class defines the interface for all image effects used in text rendering. Effects can modify images and potentially update the text bounding box coordinates.

Examples of effects include: adding noise, dropout, padding, etc.

Parameters:

p (float) – Probability of applying this effect (default: 0.5)

abstract apply(img: Image, text_bbox: BBox) Tuple[Image, BBox][source]

Apply the effect to the image.

This method must be implemented by all subclasses to define the specific augmentation behavior.

Parameters:
  • img (PILImage) – Image to apply effect to

  • text_bbox (BBox) – Bounding box of text in the image

Returns:

Modified image and updated bounding box.

Some effects (such as Padding) may modify the relative position of the text in the image.

Return type:

Tuple[PILImage, BBox]

static fix_pick(pim, col: int, row: int, value_range: Tuple[int, int])[source]

Set pixel value to a random value within the specified range.

Parameters:
  • pim – Pixel access object from pil_img.load()

  • col (int) – Column coordinate

  • row (int) – Row coordinate

  • value_range (Tuple[int, int]) – Range for random value selection

static rand_pick(pim, col: int, row: int)[source]

Randomly reset pixel value at [col, row].

This utility method randomly reduces the pixel values at the specified position. The new pixel value is a random integer between 0 and the original pixel value.

Parameters:
  • pim – Pixel access object from pil_img.load()

  • col (int) – Column coordinate

  • row (int) – Row coordinate

class text_renderer.effect.Effects(effects: Effect | List[Effect] | Selector | List[Selector])[source]

Apply multiple effects in sequence.

This class manages the application of multiple effects to an image. It can handle individual effects, lists of effects, or effect selectors.

Parameters:

effects (Union[Effect, List[Effect], Selector, List[Selector]]) – Effect(s) to apply. Can be a single effect, list of effects, selector, or list of selectors.

Initialize the Effects container.

Parameters:

effects (Union[Effect, List[Effect], Selector, List[Selector]]) – Effect(s) to apply. Can be a single effect, list of effects, selector, or list of selectors.

apply_effects(img: Image, bbox: BBox) Tuple[Image, BBox][source]

Apply all configured effects to the image.

Parameters:
  • img (PILImage) – Input image to apply effects to

  • bbox (BBox) – Bounding box of text in the image

Returns:

Image with all effects applied and updated bounding box

Return type:

Tuple[PILImage, BBox]

class text_renderer.effect.NoEffects[source]

Placeholder class when no effects are desired for multi-corpus scenarios.

This class provides a no-op implementation that simply returns the input image and bounding box unchanged.

apply_effects(img: Image, bbox: BBox) Tuple[Image, BBox][source]

Return the input image and bounding box unchanged.

Parameters:
  • img (PILImage) – Input image

  • bbox (BBox) – Input bounding box

Returns:

Unchanged image and bounding box

Return type:

Tuple[PILImage, BBox]

class text_renderer.effect.OneOf(effects: List[Effect])[source]
Parameters:

effects (list of Effect) –