Function#

class augraphy.utilities.function.Function(fs, nkwargs={}, p=1)[source]#

Bases: Augmentation

Accepts an arbitrary function or list of functions to apply in the pipeline.

Parameters:
  • fs (function or list of functions) – The function(s) to apply.

  • nkwargs (Dictionary list of dictionaries) – Arguments to the function(s).

apply_functions(fs, image)[source]#

Applies any functions to image sequentially.

Overview#

Function allows a custom defined function to be added into the augmentation pipeline.

Example#

In this example, Function is use to add a manually defined function into the augmentation pipeline.

# import libraries
from augraphy import *
import cv2
import numpy as np
from augraphy.utilities.function import Function

# custom function
def invert_colour(image):
    return np.invert(image.astype("uint8"))

# initialize phases and pipeline
ink_phase   = [Function(fs=invert_colour,p=1)]
paper_phase = []
post_phase  = []

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

# create input image
image = np.full((1200, 1200,3), 250, 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/output3.png