Interop#

class augraphy.utilities.interop.Interop(augmentation, p=1)[source]#

Bases: Augmentation

A wrapper for augmentations from other projects.

Parameters:
  • augmentation (object) – The fully-applied constructor for the interop transform.

  • p (float, optional) – The probability that augmentation will be applied.

handle_augmentation_result()[source]#

The argument to this depends on the augmentation applied. If an Albumentation augmentation is used, the result is a dict with the output image at key “image”. If an imgaug augmenter is used, the result is a numpy.ndarray.

Overview#

Interop allows the usage of imgaug or Albumentations function in Augraphy pipeline.

Example#

In this example, Interop allows the usage of Rain augmenter from imgaug in ink phase of Augraphy pipeline. Paper phase is using ColorPaper from Augraphy while Interop in post phase to allow the usage of ElasticTransform from Albumentations.

# import libraries
from augraphy import *
import cv2
import numpy as np
from augraphy.utilities.interop import Interop

# import imgaug and albumentations
import imgaug.augmenters as iaa
from albumentations.augmentations.geometric.transforms import ElasticTransform


# initialize phases and pipeline
# ink phase with imgaug
ink_phase   = [Interop(augmentation=iaa.Rain(drop_size=(0.10, 0.20)),p=1)]
# paper phase with augraphy
paper_phase = [ColorPaper(hue_range=(0,10), saturation_range=(128, 255), p=1)]
# post phase with albumentations
post_phase  = [Interop(augmentation=ElasticTransform(alpha_affine=100, p=1),p=1)]

# initialize pipeline
pipeline    = AugraphyPipeline(ink_phase, paper_phase, post_phase)

# create input image
image = np.full((1200, 1200,3), 128, dtype="uint8")
cv2.putText(
    image,
    "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
    (80, 250),
    cv2.FONT_HERSHEY_SIMPLEX,
    1.2,
    0,
    3,
)

# augment image
augmented_image = pipeline.augment(image)["output"]

Input image:

../../../_images/input2.png

Augmented image:

../../../_images/output4.png