OverlayBuilder#

class augraphy.utilities.overlaybuilder.OverlayBuilder(overlay_types, foreground, background, ntimes=1, nscales=(1, 1), edge='center', edge_offset=0, alpha=0.3, ink_color=-1)[source]#

Bases: object

Takes an input image, a number of times to duplicate that image, an image on which to overlay the result of this, and a page position, then produces an overlayable image with the input image copied that many times across the edge of the page or at random location or at the center of image.

Parameters:
  • overlay_types (string) – Types of overlay method.

  • foreground (numpy array) – The image to overlay on the background document.

  • background (numpy array) – The document.

  • ntimes (int, optional) – Number copies of the foreground image to draw.

  • nscales (tuple, optional) – Scales of foreground image size.

  • edge (string, optional) – Which edge of the page the foreground copies should be placed on. Selections included left, right, top, bottom, enter, random.

  • edge_offset (int, optional) – How far from the edge of the page to draw the copies.

  • alpha (float, optional) – Alpha value for overlay methods that uses alpha in the blending.

  • ink_color (int, optional) – Ink color value for ink_to_paper overlay type.

apply_overlay(overlay_background, offset_width, offset_height, ystart, yend, xstart, xend)[source]#

Applies overlay from foreground to background.

Parameters:
  • overlay_background (numpy array) – Background image.

  • offset_width (int) – Offset width value to the overlay process.

  • offset_height (int) – Offset height value to the overlay process.

  • ystart (int) – y start point of the overlaying process.

  • yend (int) – y end point of the overlaying process.

  • xstart (int) – x start point of the overlaying process.

  • xend (int) – x end point of the overlaying process.

static apply_ratio(comp_value, base_norm, ratio_rs)[source]#

Function to apply alpha ratio to both foreground and background image

Parameters:
  • comp_value – The resulting image from blending process.

  • base_norm (numpy array) – The background.

  • ratio_rs (numpy array) – Alpha ratio for each pixel.

build_overlay()[source]#

Construct the overlay image containing foreground copies

check_size(img_foreground, img_background, center=None)[source]#

Check the fitting size of foreground to background

Parameters:
  • img_foreground (numpy array) – The image to overlay on the background document.

  • img_background (numpy array) – The background document.

  • center (tuple) – Center coordinate (x,y) of the overlaying process.

static compose_alpha(img_alpha_background, img_alpha_foreground, alpha)[source]#

Calculate alpha composition ratio between two images.

Parameters:
  • img_alpha_background (numpy array) – The background image alpha layer.

  • img_alpha_foreground (numpy array) – The foreground image alpha layer.

  • alpha (float) – Alpha value for the blending process.

compute_offsets(foreground)[source]#

Determine where to place the foreground image copies

Parameters:

foreground (numpy array) – The image to overlay on the background document.

fft_blend(overlay_background, image1, image2, xstart, xend, ystart, yend)[source]#

Blend images using saturation and value channel of images in hsv channel.

Parameters:
  • overlay_background (numpy array) – Background image.

  • image1 (numpy array) – A patch of background image.

  • image2 (numpy array) – Foreground_image.

  • xstart (int) – x start point of the image patch.

  • xend (int) – x end point of the image patch.

  • ystart (int) – y start point of the image patch.

  • yend (int) – y end point of the image patch.

fft_blend_single_channel(image1, image2, random_mask)[source]#

Blend images using random mask and fft transform.

Parameters:
  • image1 (numpy array) – The background image.

  • image2 (numpy array) – The foreground image.

  • random_mask (numpy array) – Mask with random value for FFT blending method.

ink_to_paper_blend(overlay_background, base, new_foreground, xstart, xend, ystart, yend)[source]#

Apply blending using default ink to paper printing method.

Parameters:
  • overlay_background (numpy array) – Background image.

  • base (numpy array) – A patch of background image.

  • new_foreground (numpy array) – Foreground_image.

  • xstart (int) – x start point of the image patch.

  • xend (int) – x end point of the image patch.

  • ystart (int) – y start point of the image patch.

  • yend (int) – y end point of the image patch.

min_max_blend(base, base_gray, new_foreground, new_foreground_gray, fg_height, fg_width)[source]#

Apply blending using min or max gray value.

Parameters:
  • base (numpy array) – Background image.

  • base_gray (numpy array) – Background image in grayscale.

  • new_foreground (numpy array) – Foreground_image.

  • new_foreground_gray (numpy array) – Foreground image in grayscale.

  • fg_height (int) – Height of foreground image.

  • fg_width (int) – Width of foreground image.

mix_blend(overlay_background, new_foreground, center, fg_height, fg_width)[source]#

Apply blending using cv2.seamlessClone.

Parameters:
  • overlay_background (numpy array) – The background image.

  • new_foreground (numpy array) – The foreground iamge of overlaying process.

  • center (tuple) – Center coordinate (x,y) of the overlaying process.

  • fg_height (int) – Height of foreground image.

  • fg_width (int) – Width of foreground image.

normal_blend(overlay_background, base, new_foreground, xstart, xend, ystart, yend, alpha)[source]#

Apply blending using input alpha value (normal method).

Parameters:
  • overlay_background (numpy array) – Background image.

  • base (numpy array) – A patch of background image.

  • new_foreground (numpy array) – Foreground_image.

  • xstart (int) – x start point of the image patch.

  • xend (int) – x end point of the image patch.

  • ystart (int) – y start point of the image patch.

  • yend (int) – y end point of the image patch.

  • alpha (float) – Alpha value of the foreground.

various_blend(overlay_background, base, new_foreground, xstart, xend, ystart, yend)[source]#

Apply blending using input alpha value (multiple methods).

Parameters:
  • overlay_background (numpy array) – Background image.

  • base (numpy array) – A patch of background image.

  • new_foreground (numpy array) – Foreground_image.

  • xstart (int) – x start point of the image patch.

  • xend (int) – x end point of the image patch.

  • ystart (int) – y start point of the image patch.

  • yend (int) – y end point of the image patch.

Overview#

OverlayBuilder is the base class to overlay 2 images. It supports more than 10 types of overlaying methods. There are some additional features including the feature to scale the foreground, duplicate the foreground, or offset the foreground.