Squish#

class augraphy.augmentations.squish.Squish(squish_direction='random', squish_location='random', squish_number_range=(5, 10), squish_distance_range=(5, 7), squish_line='random', squish_line_thickness_range=(1, 1), p=1)[source]#

Bases: Augmentation

Creates a squish effect by removing a fixed horizontal or vertical section of the image.

Parameters:
  • squish_direction (int or string, optional) – Direction of the squish effect. Use 0 for horizontal squish, 1 for vertical squish, 2 for both directions. Use “random” to generate random direction.

  • squish_location (list, optional) – List of ints determining the location of squish effect. If direction of squish effect is horizontal, the value determines the row coordinate of the lines. If direction of squish effect is vertical, the value determines the column coordinate of the lines. If both directions are selected, the value determines both row and column coordinate of the lines.

  • squish_number_range (tuple, optional) – Tuple of ints determining the number of squish effect.

  • squish_distance_range (tuple, optional) – Tuple of ints determining the distance of squish effect.

  • squish_line (int, optional) – Flag to enable drawing of line in each squish effect.

  • squish_line_thickness_range (tuple, optional) – Tuple of ints determing the thickness of squish line.

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

apply_squish(image, mask, keypoints, bounding_boxes, squish_direction)[source]#

Core function to apply the squish effect.

Parameters:
  • image (numpy array) – The input image.

  • mask (numpy array (uint8)) – The mask of labels for each pixel. Mask value should be in range of 1 to 255. Value of 0 will be assigned to the filled area after the transformation.

  • keypoints (dictionary) – A dictionary of single or multiple labels where each label is a nested list of points coordinate.

  • bounding_boxes (list) – A nested list where each nested list contains box location (x1, y1, x2, y2).

  • squish_direction (int) – Direction of squish effect, where 0 = horizontal, 1 = vertical.

Overview#

The Squish augmentation creates a squish effect by removing a fixed horizontal or vertical section of the image. For additional input such as mask and keypoints, they are fully supported. For bounding boxes, they will be affected only if the starting point or ending point of the box is in the squishing area.

Initially, a clean image with single line of text is created.

Code example:

# import libraries
import cv2
import numpy as np
from augraphy import *


# create a clean image with single line of text
image = np.full((500, 1500,3), 250, dtype="uint8")
cv2.putText(
    image,
    "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
    (80, 250),
    cv2.FONT_HERSHEY_SIMPLEX,
    1.5,
    0,
    3,
)

cv2.imshow("Input image", image)

Clean image:

../../../_images/input.png

Example 1#

In this example, a Squish augmentation instance is initialized and the squish direction is set to vertical (1). The location of squish effect is set to random location (“random”). The number of squish effect is set to random value in between 5 and 10 (5,10). The squished distance in each squish effect is set to random value in between 5 and 7 (5, 7). Squish line will be drawn randomly in each squish effect (“random”). The thickness of each squish line is set to 1 (1,1).

Code example:

squish = Squish(squish_direction = 1,
                squish_location = "random",
                squish_number_range = (5,10),
                squish_distance_range = (5,7),
                squish_line = "random",
                squish_line_thickness_range = (1,1)
                )

img_squish = squish(image)

cv2.imshow("squish", img_squish)

Augmented image:

../../../_images/squish.png

Example 2#

In this example, a Squish augmentation will be applied to additional inputs such as mask, keypoints and bounding boxes. The Squish augmentation will be using the default parameters value and hence no additional parameters value will be specified.

Code example:

squish = Squish()

img_squish, mask, keypoints, bounding_boxes = squish(image=image, mask=mask, keypoints=keypoints, bounding_boxes=bounding_boxes)

cv2.imshow("squish", img_squish)

Input mask:

../../../_images/input_mask.png

Input keypoints:

../../../_images/input_keypoints.png

Input bounding boxes:

../../../_images/input_bounding_boxes.png

Augmented image:

../../../_images/squish2.png

Augmented mask:

../../../_images/squish2_mask.png

Augmented keypoints:

../../../_images/squish2_keypoints.png

Augmented bounding boxes:

../../../_images/squish2_bounding_boxes.png