augly.image package

Submodules

augly.image.composition module

class augly.image.composition.BaseComposition(transforms, p=1.0)

Bases: object

__init__(transforms, p=1.0)
Parameters
  • transforms (List[BaseTransform]) – a list of transforms

  • p (float) – the probability of the transform being applied; default value is 1.0

class augly.image.composition.Compose(transforms, p=1.0)

Bases: augly.image.composition.BaseComposition

__call__(image, metadata=None, bboxes=None, bbox_format=None)

Applies the list of transforms in order to the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies the type of bounding box that was passed in in bboxes. Must specify bbox_type if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.composition.OneOf(transforms, p=1.0)

Bases: augly.image.composition.BaseComposition

__call__(image, metadata=None, bboxes=None, bbox_format=None)

Applies one of the transforms to the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies the type of bounding box that was passed in in bboxes. Must specify bbox_type if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

__init__(transforms, p=1.0)
Parameters
  • transforms (List[BaseTransform]) – a list of transforms to select from; one of which will be chosen to be applied to the media

  • p (float) – the probability of the transform being applied; default value is 1.0

augly.image.functional module

augly.image.functional.apply_lambda(image, output_path=None, aug_function=<function <lambda>>, metadata=None, bboxes=None, bbox_format=None, **kwargs)

Apply a user-defined lambda on an image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • aug_function (Callable[..., Image]) – the augmentation function to be applied onto the image (should expect a PIL image as input and return one)

  • **kwargs

    the input attributes to be passed into the augmentation function to be applied

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.apply_pil_filter(image, output_path=None, filter_type=<class 'PIL.ImageFilter.EDGE_ENHANCE_MORE'>, metadata=None, bboxes=None, bbox_format=None)

Applies a given PIL filter to the input image using Image.filter()

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • filter_type (Union[Callable, Filter]) – the PIL ImageFilter to apply to the image

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.blur(image, output_path=None, radius=2.0, metadata=None, bboxes=None, bbox_format=None)

Blurs the image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • radius (float) – the larger the radius, the blurrier the image

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.brightness(image, output_path=None, factor=1.0, metadata=None, bboxes=None, bbox_format=None)

Changes the brightness of the image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • factor (float) – values less than 1.0 darken the image and values greater than 1.0 brighten the image. Setting factor to 1.0 will not alter the image’s brightness

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.change_aspect_ratio(image, output_path=None, ratio=1.0, metadata=None, bboxes=None, bbox_format=None)

Changes the aspect ratio of the image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • ratio (float) – aspect ratio, i.e. width/height, of the new image

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.clip_image_size(image, output_path=None, min_resolution=None, max_resolution=None, metadata=None, bboxes=None, bbox_format=None)

Scales the image up or down if necessary to fit in the given min and max resolution

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • min_resolution (Optional[int]) – the minimum resolution, i.e. width * height, that the augmented image should have; if the input image has a lower resolution than this, the image will be scaled up as necessary

  • max_resolution (Optional[int]) – the maximum resolution, i.e. width * height, that the augmented image should have; if the input image has a higher resolution than this, the image will be scaled down as necessary

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.color_jitter(image, output_path=None, brightness_factor=1.0, contrast_factor=1.0, saturation_factor=1.0, metadata=None, bboxes=None, bbox_format=None)

Color jitters the image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • brightness_factor (float) – a brightness factor below 1.0 darkens the image, a factor of 1.0 does not alter the image, and a factor greater than 1.0 brightens the image

  • contrast_factor (float) – a contrast factor below 1.0 removes contrast, a factor of 1.0 gives the original image, and a factor greater than 1.0 adds contrast

  • saturation_factor (float) – a saturation factor of below 1.0 lowers the saturation, a factor of 1.0 gives the original image, and a factor greater than 1.0 adds saturation

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.contrast(image, output_path=None, factor=1.0, metadata=None, bboxes=None, bbox_format=None)

Alters the contrast of the image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • factor (float) – zero gives a grayscale image, values below 1.0 decreases contrast, a factor of 1.0 gives the original image, and a factor greater than 1.0 increases contrast

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Image.Image - Augmented PIL Image

augly.image.functional.convert_color(image, output_path=None, mode=None, matrix=None, dither=None, palette=0, colors=256, metadata=None, bboxes=None, bbox_format=None)

Converts the image in terms of color modes

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • mode (Optional[str]) – defines the type and depth of a pixel in the image. If mode is omitted, a mode is chosen so that all information in the image and the palette can be represented without a palette. For list of available modes, check: https://pillow.readthedocs.io/en/stable/handbook/concepts.html#concept-modes

  • matrix (Union[None, Tuple[float, float, float, float], Tuple[float, float, float, float, float, float, float, float, float, float, float, float]]) – an optional conversion matrix. If given, this should be 4- or 12-tuple containing floating point values

  • dither (Optional[int]) – dithering method, used when converting from mode “RGB” to “P” or from “RGB” or “L” to “1”. Available methods are NONE or FLOYDSTEINBERG (default).

  • palette (int) – palette to use when converting from mode “RGB” to “P”. Available palettes are WEB or ADAPTIVE

  • colors (int) – number of colors to use for the ADAPTIVE palette. Defaults to 256.

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Image.Image - Augmented PIL Image

augly.image.functional.crop(image, output_path=None, x1=0.25, y1=0.25, x2=0.75, y2=0.75, metadata=None, bboxes=None, bbox_format=None)

Crops the image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • x1 (float) – position of the left edge of cropped image relative to the width of the original image; must be a float value between 0 and 1

  • y1 (float) – position of the top edge of cropped image relative to the height of the original image; must be a float value between 0 and 1

  • x2 (float) – position of the right edge of cropped image relative to the width of the original image; must be a float value between 0 and 1

  • y2 (float) – position of the bottom edge of cropped image relative to the height of the original image; must be a float value between 0 and 1

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.encoding_quality(image, output_path=None, quality=50, metadata=None, bboxes=None, bbox_format=None)

Changes the JPEG encoding quality level

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • quality (int) – JPEG encoding quality. 0 is lowest quality, 100 is highest

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.grayscale(image, output_path=None, mode='luminosity', metadata=None, bboxes=None, bbox_format=None)

Changes an image to be grayscale

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • mode (str) – the type of greyscale conversion to perform; two options are supported (“luminosity” and “average”)

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.hflip(image, output_path=None, metadata=None, bboxes=None, bbox_format=None)

Horizontally flips an image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.masked_composite(image, output_path=None, mask=None, transform_function=None, metadata=None, bboxes=None, bbox_format=None)

Applies given augmentation function to the masked area of the image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • mask (Union[str, Image, None]) – the path to an image or a variable of type PIL.Image.Image for masking. This image can have mode “1”, “L”, or “RGBA”, and must have the same size as the other two images. If the mask is not provided the function returns the augmented image

  • transform_function (Optional[Callable]) – the augmentation function to be applied. If transform_function is not provided, the function returns the input image

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.meme_format(image, output_path=None, text='LOL', font_file='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/fonts/Raleway-ExtraBold.ttf', opacity=1.0, text_color=(0, 0, 0), caption_height=250, meme_bg_color=(255, 255, 255), metadata=None, bboxes=None, bbox_format=None)

Creates a new image that looks like a meme, given text and an image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • text (str) – the text to be overlaid/used in the meme. note: if using a very long string, please add in newline characters such that the text remains in a readable font size.

  • font_file (str) – iopath uri to a .ttf font file

  • opacity (float) – the lower the opacity, the more transparent the text

  • text_color (Tuple[int, int, int]) – color of the text in RGB values

  • caption_height (int) – the height of the meme caption

  • meme_bg_color (Tuple[int, int, int]) – background color of the meme caption in RGB values

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.opacity(image, output_path=None, level=1.0, metadata=None, bboxes=None, bbox_format=None)

Alter the opacity of an image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • level (float) – the level the opacity should be set to, where 0 means completely transparent and 1 means no transparency at all

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.overlay_emoji(image, output_path=None, emoji_path='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/twemojis/smileys/smiling_face_with_heart_eyes.png', opacity=1.0, emoji_size=0.15, x_pos=0.4, y_pos=0.8, metadata=None, bboxes=None, bbox_format=None)

Overlay an emoji onto the original image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • emoji_path (str) – iopath uri to the emoji image

  • opacity (float) – the lower the opacity, the more transparent the overlaid emoji

  • emoji_size (float) – size of the emoji is emoji_size * height of the original image

  • x_pos (float) – position of emoji relative to the image width

  • y_pos (float) – position of emoji relative to the image height

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.overlay_image(image, overlay, output_path=None, opacity=1.0, overlay_size=1.0, x_pos=0.4, y_pos=0.4, max_visible_opacity=0.75, metadata=None, bboxes=None, bbox_format=None)

Overlays an image onto another image at position (width * x_pos, height * y_pos)

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • overlay (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image that will be overlaid

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • opacity (float) – the lower the opacity, the more transparent the overlaid image

  • overlay_size (float) – size of the overlaid image is overlay_size * height of the original image

  • x_pos (float) – position of overlaid image relative to the image width

  • max_visible_opacity (float) – if bboxes are passed in, this param will be used as the maximum opacity value through which the src image will still be considered visible; see the function overlay_image_bboxes_helper in utils/bboxes.py for more details about how this is used. If bboxes are not passed in this is not used

  • y_pos (float) – position of overlaid image relative to the image height

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.overlay_onto_background_image(image, background_image, output_path=None, opacity=1.0, overlay_size=1.0, x_pos=0.4, y_pos=0.4, scale_bg=False, metadata=None, bboxes=None, bbox_format=None)

Overlays the image onto a given background image at position (width * x_pos, height * y_pos)

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • background_image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image onto which the source image will be overlaid

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • opacity (float) – the lower the opacity, the more transparent the overlaid image

  • overlay_size (float) – size of the overlaid image is overlay_size * height of the background image

  • x_pos (float) – position of overlaid image relative to the background image width with respect to the x-axis

  • y_pos (float) – position of overlaid image relative to the background image height with respect to the y-axis

  • scale_bg (bool) – if True, the background image will be scaled up or down so that overlay_size is respected; if False, the source image will be scaled instead

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.overlay_onto_screenshot(image, output_path=None, template_filepath='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/screenshot_templates/web.png', template_bboxes_filepath='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/screenshot_templates/bboxes.json', max_image_size_pixels=None, crop_src_to_fit=False, resize_src_to_match_template=True, metadata=None, bboxes=None, bbox_format=None)

Overlay the image onto a screenshot template so it looks like it was screenshotted on Instagram

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • template_filepath (str) – iopath uri to the screenshot template

  • template_bboxes_filepath (str) – iopath uri to the file containing the bounding box for each template

  • max_image_size_pixels (Optional[int]) – if provided, the template image and/or src image will be scaled down to avoid an output image with an area greater than this size (in pixels)

  • crop_src_to_fit (bool) – if True, the src image will be cropped if necessary to fit into the template image if the aspect ratios are different. If False, the src image will instead be resized if needed

  • resize_src_to_match_template (bool) – if True, the src image will be resized if it is too big or small in both dimensions to better match the template image. If False, the template image will be resized to match the src image instead. It can be useful to set this to True if the src image is very large so that the augmented image isn’t huge, but instead is the same size as the template image

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.overlay_stripes(image, output_path=None, line_width=0.5, line_color=(255, 255, 255), line_angle=0, line_density=0.5, line_type='solid', line_opacity=1.0, metadata=None, bboxes=None, bbox_format=None)

Overlay stripe pattern onto the image (by default, white horizontal stripes are overlaid)

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • line_width (float) – the width of individual stripes as a float value ranging from 0 to 1. Defaults to 0.5

  • line_color (Tuple[int, int, int]) – color of the overlaid stripes in RGB values

  • line_angle (float) – the angle of the stripes in degrees, ranging from -360° to 360°. Defaults to 0° or horizontal stripes

  • line_density (float) – controls the distance between stripes represented as a float value ranging from 0 to 1, with 1 indicating more densely spaced stripes. Defaults to 0.5

  • line_type (Optional[str]) – the type of stripes. Current options include: dotted, dashed, and solid. Defaults to solid

  • line_opacity (float) – the opacity of the stripes, ranging from 0 to 1 with 1 being opaque. Defaults to 1.0

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.overlay_text(image, output_path=None, text=[79, 66, 332, 903, 46], font_file='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/fonts/NotoNaskhArabic-Regular.ttf', font_size=0.15, opacity=1.0, color=(255, 0, 0), x_pos=0.0, y_pos=0.5, metadata=None, bboxes=None, bbox_format=None)

Overlay text onto the image (by default, text is randomly overlaid)

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • text (List[Union[int, List[int]]]) – indices (into the file) of the characters to be overlaid. Each line of text is represented as a list of int indices; if a list of lists is supplied, multiple lines of text will be overlaid

  • font_file (str) – iopath uri to the .ttf font file

  • font_size (float) – size of the overlaid characters, calculated as font_size * min(height, width) of the original image

  • opacity (float) – the lower the opacity, the more transparent the overlaid text

  • color (Tuple[int, int, int]) – color of the overlaid text in RGB values

  • x_pos (float) – position of the overlaid text relative to the image width

  • y_pos (float) – position of the overlaid text relative to the image height

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.pad(image, output_path=None, w_factor=0.25, h_factor=0.25, color=(0, 0, 0), metadata=None, bboxes=None, bbox_format=None)

Pads the image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • w_factor (float) – width * w_factor pixels are padded to both left and right of the image

  • h_factor (float) – height * h_factor pixels are padded to the top and the bottom of the image

  • color (Tuple[int, int, int]) – color of the padded border in RGB values

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.pad_square(image, output_path=None, color=(0, 0, 0), metadata=None, bboxes=None, bbox_format=None)

Pads the shorter edge of the image such that it is now square-shaped

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • color (Tuple[int, int, int]) – color of the padded border in RGB values

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.perspective_transform(image, output_path=None, sigma=50.0, dx=0.0, dy=0.0, seed=42, crop_out_black_border=False, metadata=None, bboxes=None, bbox_format=None)

Apply a perspective transform to the image so it looks like it was taken as a photo from another device (e.g. taking a picture from your phone of a picture on a computer).

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • sigma (float) – the standard deviation of the distribution of destination coordinates. the larger the sigma value, the more intense the transform

  • dx (float) – change in x for the perspective transform; instead of providing sigma you can provide a scalar value to be precise

  • dy (float) – change in y for the perspective transform; instead of providing sigma you can provide a scalar value to be precise

  • seed (Optional[int]) – if provided, this will set the random seed to ensure consistency between runs

  • crop_out_black_border (bool) – if True, will crop out the black border resulting from the perspective transform by cropping to the largest center rectangle with no black

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.pixelization(image, output_path=None, ratio=1.0, metadata=None, bboxes=None, bbox_format=None)

Pixelizes an image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • ratio (float) – smaller values result in a more pixelated image, 1.0 indicates no change, and any value above one doesn’t have a noticeable effect

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.random_noise(image, output_path=None, mean=0.0, var=0.01, seed=42, metadata=None, bboxes=None, bbox_format=None)

Adds random noise to the image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • mean (float) – mean of the gaussian noise added

  • var (float) – variance of the gaussian noise added

  • seed (int) – if provided, this will set the random seed before generating noise

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.resize(image, output_path=None, width=None, height=None, resample=2, metadata=None, bboxes=None, bbox_format=None)

Resizes an image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • width (Optional[int]) – the desired width the image should be resized to have. If None, the original image width will be used

  • height (Optional[int]) – the desired height the image should be resized to have. If None, the original image height will be used

  • resample (Any) – A resampling filter. This can be one of PIL.Image.NEAREST, PIL.Image.BOX, PIL.Image.BILINEAR, PIL.Image.HAMMING, PIL.Image.BICUBIC, or PIL.Image.LANCZOS

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.rotate(image, output_path=None, degrees=15.0, metadata=None, bboxes=None, bbox_format=None)

Rotates the image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • degrees (float) – the amount of degrees that the original image will be rotated counter clockwise

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.saturation(image, output_path=None, factor=1.0, metadata=None, bboxes=None, bbox_format=None)

Alters the saturation of the image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • factor (float) – a saturation factor of below 1.0 lowers the saturation, a factor of 1.0 gives the original image, and a factor greater than 1.0 adds saturation

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.scale(image, output_path=None, factor=0.5, interpolation=None, metadata=None, bboxes=None, bbox_format=None)

Alters the resolution of an image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • factor (float) – the ratio by which the image should be downscaled or upscaled

  • interpolation (Optional[int]) – interpolation method. This can be one of PIL.Image.NEAREST, PIL.Image.BOX, PIL.Image.BILINEAR, PIL.Image.HAMMING, PIL.Image.BICUBIC or PIL.Image.LANCZOS

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.sharpen(image, output_path=None, factor=1.0, metadata=None, bboxes=None, bbox_format=None)

Changes the sharpness of the image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • factor (float) – a factor of below 1.0 blurs the image, a factor of 1.0 gives the original image, and a factor greater than 1.0 sharpens the image

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.shuffle_pixels(image, output_path=None, factor=1.0, seed=10, metadata=None, bboxes=None, bbox_format=None)

Shuffles the pixels of an image with respect to the shuffling factor. The factor denotes percentage of pixels to be shuffled and randomly selected Note: The actual number of pixels will be less than the percentage given due to the probability of pixels staying in place in the course of shuffling

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • factor (float) – a control parameter between 0.0 and 1.0. While a factor of 0.0 returns the original image, a factor of 1.0 performs full shuffling

  • seed (int) – seed for numpy random generator to select random pixels for shuffling

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.skew(image, output_path=None, skew_factor=0.5, axis=0, metadata=None, bboxes=None, bbox_format=None)

Skews an image with respect to its x or y-axis

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • skew_factor (float) – the level of skew to apply to the image; a larger absolute value will result in a more intense skew. Recommended range is between [-2, 2]

  • axis (int) – the axis along which the image will be skewed; can be set to 0 (x-axis) or 1 (y-axis)

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.functional.vflip(image, output_path=None, metadata=None, bboxes=None, bbox_format=None)

Vertically flips an image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.helpers module

augly.image.helpers.aug_np_wrapper(image, aug_function, **kwargs)

This function is a wrapper on all image augmentation functions such that a numpy array could be passed in as input instead of providing the path to the image or a PIL Image

Parameters
  • image (ndarray) – the numpy array representing the image to be augmented

  • aug_function (Callable[..., None]) – the augmentation function to be applied onto the image

  • **kwargs

    the input attributes to be passed into the augmentation function

Return type

ndarray

augly.image.intensity module

augly.image.intensity.apply_lambda_intensity(aug_function, **kwargs)
Return type

float

augly.image.intensity.apply_pil_filter_intensity(**kwargs)
Return type

float

augly.image.intensity.blur_intensity(radius, **kwargs)
Return type

float

augly.image.intensity.brightness_intensity(factor, **kwargs)
Return type

float

augly.image.intensity.change_aspect_ratio_intensity(ratio, metadata, **kwargs)
Return type

float

augly.image.intensity.clip_image_size_intensity(metadata, **kwargs)
Return type

float

augly.image.intensity.color_jitter_intensity(brightness_factor, contrast_factor, saturation_factor, **kwargs)
Return type

float

augly.image.intensity.contrast_intensity(factor, **kwargs)
Return type

float

augly.image.intensity.convert_color_intensity(**kwargs)
Return type

float

augly.image.intensity.crop_intensity(metadata, **kwargs)
Return type

float

augly.image.intensity.encoding_quality_intensity(quality, **kwargs)
Return type

float

augly.image.intensity.grayscale_intensity(**kwargs)
Return type

float

augly.image.intensity.hflip_intensity(**kwargs)
Return type

float

augly.image.intensity.masked_composite_intensity(mask, metadata, **kwargs)
Return type

float

augly.image.intensity.meme_format_intensity(metadata, **kwargs)
Return type

float

augly.image.intensity.mult_factor_intensity_helper(factor)
Return type

float

augly.image.intensity.normalize_mult_factor(factor)
Return type

float

augly.image.intensity.opacity_intensity(level, **kwargs)
Return type

float

augly.image.intensity.overlay_emoji_intensity(emoji_size, opacity, **kwargs)
Return type

float

augly.image.intensity.overlay_image_intensity(opacity, overlay_size, **kwargs)
Return type

float

augly.image.intensity.overlay_media_intensity_helper(opacity, overlay_content_size)
Return type

float

augly.image.intensity.overlay_onto_background_image_intensity(opacity, overlay_size, **kwargs)
Return type

float

augly.image.intensity.overlay_onto_screenshot_intensity(template_filepath, template_bboxes_filepath, metadata, **kwargs)
Return type

float

augly.image.intensity.overlay_stripes_intensity(line_width, line_angle, line_density, line_type, line_opacity, metadata, **kwargs)
Return type

float

augly.image.intensity.overlay_text_intensity(opacity, font_size, **kwargs)
Return type

float

augly.image.intensity.pad_intensity(metadata, **kwargs)
Return type

float

augly.image.intensity.pad_square_intensity(metadata, **kwargs)
Return type

float

augly.image.intensity.perspective_transform_intensity(sigma, **kwargs)
Return type

float

augly.image.intensity.pixelization_intensity(ratio, **kwargs)
Return type

float

augly.image.intensity.random_noise_intensity(mean, var, **kwargs)
Return type

float

augly.image.intensity.resize_intensity(metadata, **kwargs)
Return type

float

augly.image.intensity.resize_intensity_helper(metadata)

Computes intensity of any transform that resizes the src image. For these types of transforms the intensity is defined as the percentage of image area that has been cut out (if cropped/resized to smaller) or added (if padding/resized to bigger). When computing the percentage, the denominator should be the larger of the src & dst areas so the resulting percentage isn’t greater than 100.

Return type

float

augly.image.intensity.rotate_intensity(degrees, **kwargs)
Return type

float

augly.image.intensity.saturation_intensity(factor, **kwargs)
Return type

float

augly.image.intensity.scale_intensity(factor, **kwargs)
Return type

float

augly.image.intensity.sharpen_intensity(factor, **kwargs)
Return type

float

augly.image.intensity.shuffle_pixels_intensity(factor, **kwargs)
Return type

float

augly.image.intensity.skew_intensity(skew_factor, **kwargs)
Return type

float

augly.image.intensity.vflip_intensity(**kwargs)
Return type

float

augly.image.transforms module

class augly.image.transforms.ApplyLambda(aug_function=<function ApplyLambda.<lambda>>, p=1.0, **kwargs)

Bases: augly.image.transforms.BaseTransform

__init__(aug_function=<function ApplyLambda.<lambda>>, p=1.0, **kwargs)
Parameters
  • aug_function (Callable[..., Image]) – the augmentation function to be applied onto the image (should expect a PIL image as input and return one)

  • p (float) – the probability of the transform being applied; default value is 1.0

  • **kwargs

    the input attributes to be passed into the augmentation function to be applied

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Apply a user-defined lambda on an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.ApplyPILFilter(filter_type=<class 'PIL.ImageFilter.EDGE_ENHANCE_MORE'>, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(filter_type=<class 'PIL.ImageFilter.EDGE_ENHANCE_MORE'>, p=1.0)
Parameters
  • filter_type (Union[Callable, Filter]) – the PIL ImageFilter to apply to the image

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Applies a given PIL filter to the input image using Image.filter()

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.BaseRandomRangeTransform(min_val, max_val, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(min_val, max_val, p=1.0)
Parameters
  • min_val (float) – the lower value of the range

  • max_val (float) – the upper value of the range

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_random_transform(image, metadata=None, bboxes=None, bbox_format=None)

This function is to be implemented in the child classes. It has access to self.chosen_value which is the randomly chosen value from the range specified to pass into the augmentation function

Return type

Image

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)
Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.BaseTransform(p=1.0)

Bases: object

__call__(image, force=False, metadata=None, bboxes=None, bbox_format=None)
Parameters
  • image (Image) – PIL Image to be augmented

  • force (bool) – if set to True, the transform will be applied. Otherwise, application is determined by the probability set

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

__init__(p=1.0)
Parameters

p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

This function is to be implemented in the child classes. From this function, call the augmentation function with the parameters specified

Return type

Image

class augly.image.transforms.Blur(radius=2.0, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(radius=2.0, p=1.0)
Parameters
  • radius (float) – the larger the radius, the blurrier the image

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Blurs the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.Brightness(factor=1.0, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(factor=1.0, p=1.0)
Parameters
  • factor (float) – values less than 1.0 darken the image and values greater than 1.0 brighten the image. Setting factor to 1.0 will not alter the image’s brightness

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Alters the brightness of the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.ChangeAspectRatio(ratio=1.0, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(ratio=1.0, p=1.0)
Parameters
  • ratio (float) – aspect ratio, i.e. width/height, of the new image

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Alters the aspect ratio of the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.ClipImageSize(min_resolution=None, max_resolution=None, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(min_resolution=None, max_resolution=None, p=1.0)
Parameters
  • min_resolution (Optional[int]) – the minimum resolution, i.e. width * height, that the augmented image should have; if the input image has a lower resolution than this, the image will be scaled up as necessary

  • max_resolution (Optional[int]) – the maximum resolution, i.e. width * height, that the augmented image should have; if the input image has a higher resolution than this, the image will be scaled down as necessary

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Scales the image up or down if necessary to fit in the given min and max resolution

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.ColorJitter(brightness_factor=1.0, contrast_factor=1.0, saturation_factor=1.0, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(brightness_factor=1.0, contrast_factor=1.0, saturation_factor=1.0, p=1.0)
Parameters
  • brightness_factor (float) – a brightness factor below 1.0 darkens the image, a factor of 1.0 does not alter the image, and a factor greater than 1.0 brightens the image

  • contrast_factor (float) – a contrast factor below 1.0 removes contrast, a factor of 1.0 gives the original image, and a factor greater than 1.0 adds contrast

  • saturation_factor (float) – a saturation factor of below 1.0 lowers the saturation, a factor of 1.0 gives the original image, and a factor greater than 1.0 adds saturation

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Color jitters the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.Contrast(factor=1.0, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(factor=1.0, p=1.0)
Parameters
  • factor (float) – zero gives a grayscale image, values below 1.0 decrease contrast, a factor of 1.0 gives the original image, and a factor greater than 1.0 increases contrast

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Alters the contrast of the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.ConvertColor(mode=None, matrix=None, dither=None, palette=0, colors=256, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(mode=None, matrix=None, dither=None, palette=0, colors=256, p=1.0)
Parameters
  • mode (Optional[str]) – defines the type and depth of a pixel in the image. If mode is omitted, a mode is chosen so that all information in the image and the palette can be represented without a palette. For list of available modes, check: https://pillow.readthedocs.io/en/stable/handbook/concepts.html#concept-modes

  • matrix (Union[None, Tuple[float, float, float, float], Tuple[float, float, float, float, float, float, float, float, float, float, float, float]]) – an optional conversion matrix. If given, this should be 4- or 12-tuple containing floating point values.

  • dither (Optional[int]) – dithering method, used when converting from mode “RGB” to “P” or from “RGB” or “L” to “1”. Available methods are NONE or FLOYDSTEINBERG (default)

  • palette (int) – palette to use when converting from mode “RGB” to “P”. Available palettes are WEB or ADAPTIVE

  • colors (int) – number of colors to use for the ADAPTIVE palette. Defaults to 256

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Converts the image in terms of color modes

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.Crop(x1=0.25, y1=0.25, x2=0.75, y2=0.75, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(x1=0.25, y1=0.25, x2=0.75, y2=0.75, p=1.0)
Parameters
  • x1 (float) – position of the left edge of cropped image relative to the width of the original image; must be a float value between 0 and 1

  • y1 (float) – position of the top edge of cropped image relative to the height of the original image; must be a float value between 0 and 1

  • x2 (float) – position of the right edge of cropped image relative to the width of the original image; must be a float value between 0 and 1

  • y2 (float) – position of the bottom edge of cropped image relative to the height of the original image; must be a float value between 0 and 1

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Crops the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.EncodingQuality(quality=50, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(quality=50, p=1.0)
Parameters
  • quality (int) – JPEG encoding quality. 0 is lowest quality, 100 is highest

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Changes the JPEG encoding quality level

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.Grayscale(mode='luminosity', p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(mode='luminosity', p=1.0)
Parameters
  • mode (str) – the type of greyscale conversion to perform; two options are supported (“luminosity” and “average”)

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Alters an image to be grayscale

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.HFlip(p=1.0)

Bases: augly.image.transforms.BaseTransform

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Horizontally flips an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.MaskedComposite(transform_function, mask, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(transform_function, mask, p=1.0)
Parameters
  • mask (Image) – the path to an image or a variable of type PIL.Image.Image for masking. This image can have mode “1”, “L”, or “RGBA”, and must have the same size as the other two images. If the mask is not provided the function returns the augmented image

  • transform_function (BaseTransform) – the augmentation function to be applied. If transform_function is not provided, function returns the input image

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Applies given augmentation function to the masked area of the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.MemeFormat(text='LOL', font_file='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/fonts/Raleway-ExtraBold.ttf', opacity=1.0, text_color=(0, 0, 0), caption_height=250, meme_bg_color=(255, 255, 255), p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(text='LOL', font_file='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/fonts/Raleway-ExtraBold.ttf', opacity=1.0, text_color=(0, 0, 0), caption_height=250, meme_bg_color=(255, 255, 255), p=1.0)
Parameters
  • text (str) – the text to be overlaid/used in the meme. note: if using a very long string, please add in newline characters such that the text remains in a readable font size

  • font_file (str) – iopath uri to the .ttf font file

  • opacity (float) – the lower the opacity, the more transparent the text

  • text_color (Tuple[int, int, int]) – color of the text in RGB values

  • caption_height (int) – the height of the meme caption

  • meme_bg_color (Tuple[int, int, int]) – background color of the meme caption in RGB values

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Creates a new image that looks like a meme, given text and an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.Opacity(level=1.0, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(level=1.0, p=1.0)
Parameters
  • level (float) – the level the opacity should be set to, where 0 means completely transparent and 1 means no transparency at all

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Alters the opacity of an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.OverlayEmoji(emoji_path='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/twemojis/smileys/smiling_face_with_heart_eyes.png', opacity=1.0, emoji_size=0.15, x_pos=0.4, y_pos=0.8, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(emoji_path='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/twemojis/smileys/smiling_face_with_heart_eyes.png', opacity=1.0, emoji_size=0.15, x_pos=0.4, y_pos=0.8, p=1.0)
Parameters
  • emoji_path (str) – iopath uri to the emoji image

  • opacity (float) – the lower the opacity, the more transparent the overlaid emoji

  • emoji_size (float) – size of the emoji is emoji_size * height of the original image

  • x_pos (float) – position of emoji relative to the image width

  • y_pos (float) – position of emoji relative to the image height

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Overlay an emoji onto the original image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.OverlayImage(overlay, opacity=1.0, overlay_size=1.0, x_pos=0.4, y_pos=0.4, max_visible_opacity=0.75, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(overlay, opacity=1.0, overlay_size=1.0, x_pos=0.4, y_pos=0.4, max_visible_opacity=0.75, p=1.0)
Parameters
  • overlay (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image that will be overlaid

  • opacity (float) – the lower the opacity, the more transparent the overlaid image

  • overlay_size (float) – size of the overlaid image is overlay_size * height of the original image

  • x_pos (float) – position of overlaid image relative to the image width

  • y_pos (float) – position of overlaid image relative to the image height

  • max_visible_opacity (float) – if bboxes are passed in, this param will be used as the maximum opacity value through which the src image will still be considered visible; see the function overlay_image_bboxes_helper in utils/bboxes.py for more details about how this is used. If bboxes are not passed in this is not used

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Overlays an image onto another image at position (width * x_pos, height * y_pos)

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.OverlayOntoBackgroundImage(background_image, opacity=1.0, overlay_size=1.0, x_pos=0.4, y_pos=0.4, scale_bg=False, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(background_image, opacity=1.0, overlay_size=1.0, x_pos=0.4, y_pos=0.4, scale_bg=False, p=1.0)
Parameters
  • background_image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image onto which the source image will be overlaid

  • opacity (float) – the lower the opacity, the more transparent the overlaid image

  • overlay_size (float) – size of the overlaid image is overlay_size * height of the background image

  • x_pos (float) – position of overlaid image relative to the background image width with respect to the x-axis

  • y_pos (float) – position of overlaid image relative to the background image height with respect to the y-axis

  • scale_bg (bool) – if True, the background image will be scaled up or down so that overlay_size is respected; if False, the source image will be scaled instead

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Overlays the image onto a given background image at position (width * x_pos, height * y_pos)

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.OverlayOntoScreenshot(template_filepath='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/screenshot_templates/web.png', template_bboxes_filepath='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/screenshot_templates/bboxes.json', max_image_size_pixels=None, crop_src_to_fit=False, resize_src_to_match_template=True, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(template_filepath='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/screenshot_templates/web.png', template_bboxes_filepath='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/screenshot_templates/bboxes.json', max_image_size_pixels=None, crop_src_to_fit=False, resize_src_to_match_template=True, p=1.0)
Parameters
  • template_filepath (str) – iopath uri to the screenshot template

  • template_bboxes_filepath (str) – iopath uri to the file containing the bounding box for each template

  • max_image_size_pixels (Optional[int]) – if provided, the template image and/or src image will be scaled down to avoid an output image with an area greater than this size (in pixels)

  • crop_src_to_fit (bool) – if True, the src image will be cropped if necessary to fit into the template image if the aspect ratios are different. If False, the src image will instead be resized if needed

  • resize_src_to_match_template (bool) – if True, the src image will be resized if it is too big or small in both dimensions to better match the template image. If False, the template image will be resized to match the src image instead. It can be useful to set this to True if the src image is very large so that the augmented image isn’t huge, but instead is the same size as the template image

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Overlay the image onto a screenshot template so it looks like it was screenshotted on Instagram

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.OverlayStripes(line_width=0.5, line_color=(255, 255, 255), line_angle=0, line_density=0.5, line_type='solid', line_opacity=1.0, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(line_width=0.5, line_color=(255, 255, 255), line_angle=0, line_density=0.5, line_type='solid', line_opacity=1.0, p=1.0)
Parameters
  • line_width (float) – the width of individual stripes as a float value ranging from 0 to 1. Defaults to 0.5

  • line_color (Tuple[int, int, int]) – color of the overlaid lines in RGB values

  • line_angle (float) – the angle of the stripes in degrees, ranging from -360° to 360°. Defaults to 0° or horizontal stripes

  • line_density (float) – controls the distance between stripes represented as a float value ranging from 0 to 1, with 1 indicating more densely spaced stripes. Defaults to 0.5

  • line_type (Optional[str]) – the type of stripes. Current options include: dotted, dashed, and solid. Defaults to solid

  • line_opacity (float) – the opacity of the stripes, ranging from 0 to 1 with 1 being opaque. Defaults to 1

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Overlay stripe pattern onto the image (by default, stripes are horizontal)

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.OverlayText(text=[79, 66, 332, 903, 46], font_file='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/fonts/NotoNaskhArabic-Regular.ttf', font_size=0.15, opacity=1.0, color=(255, 0, 0), x_pos=0.0, y_pos=0.5, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(text=[79, 66, 332, 903, 46], font_file='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/fonts/NotoNaskhArabic-Regular.ttf', font_size=0.15, opacity=1.0, color=(255, 0, 0), x_pos=0.0, y_pos=0.5, p=1.0)
Parameters
  • text (List[Union[int, List[int]]]) – indices (into the file) of the characters to be overlaid. Each line of text is represented as a list of int indices; if a list of lists is supplied, multiple lines of text will be overlaid

  • font_file (str) – iopath uri to the .ttf font file

  • font_size (float) – size of the overlaid characters, calculated as font_size * min(height, width) of the original image

  • opacity (float) – the lower the opacity, the more transparent the overlaid text

  • color (Tuple[int, int, int]) – color of the overlaid text in RGB values

  • x_pos (float) – position of the overlaid text relative to the image width

  • y_pos (float) – position of the overlaid text relative to the image height

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Overlay text onto the image (by default, text is randomly overlaid)

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.Pad(w_factor=0.25, h_factor=0.25, color=(0, 0, 0), p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(w_factor=0.25, h_factor=0.25, color=(0, 0, 0), p=1.0)
Parameters
  • w_factor (float) – width * w_factor pixels are padded to both left and right of the image

  • h_factor (float) – height * h_factor pixels are padded to the top and the bottom of the image

  • color (Tuple[int, int, int]) – color of the padded border in RGB values

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Pads the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.PadSquare(color=(0, 0, 0), p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(color=(0, 0, 0), p=1.0)
Parameters
  • color (Tuple[int, int, int]) – color of the padded border in RGB values

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Pads the shorter edge of the image such that it is now square-shaped

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.PerspectiveTransform(sigma=50.0, dx=0.0, dy=0.0, seed=42, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(sigma=50.0, dx=0.0, dy=0.0, seed=42, p=1.0)
Parameters
  • sigma (float) – the standard deviation of the distribution of destination coordinates. the larger the sigma value, the more intense the transform

  • seed (Optional[int]) – if provided, this will set the random seed to ensure consistency between runs

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Apply a perspective transform to the image so it looks like it was taken as a photo from another device (e.g. taking a picture from your phone of a picture on a computer).

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.Pixelization(ratio=1.0, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(ratio=1.0, p=1.0)
Parameters
  • ratio (float) – smaller values result in a more pixelated image, 1.0 indicates no change, and any value above one doesn’t have a noticeable effect

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Pixelizes an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.RandomAspectRatio(min_ratio=0.5, max_ratio=2.0, p=1.0)

Bases: augly.image.transforms.BaseRandomRangeTransform

__init__(min_ratio=0.5, max_ratio=2.0, p=1.0)
Parameters
  • min_ratio (float) – the lower value on the range of aspect ratio values to choose from, i.e. the width/height ratio

  • max_ratio (float) – the upper value on the range of aspect ratio values to choose from, i.e. the width/height ratio

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_random_transform(image, metadata=None, bboxes=None, bbox_format=None)

Transform that randomly changes the aspect ratio of an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.RandomBlur(min_radius=0.0, max_radius=10.0, p=1.0)

Bases: augly.image.transforms.BaseRandomRangeTransform

__init__(min_radius=0.0, max_radius=10.0, p=1.0)
Parameters
  • min_radius (float) – the lower value on the range of blur values to choose from. The larger the radius, the blurrier the image

  • max_radius (float) – the upper value on the range of blur values to choose from. The larger the radius, the blurrier the image

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_random_transform(image, metadata=None, bboxes=None, bbox_format=None)

Transform that randomly blurs an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.RandomBrightness(min_factor=0.0, max_factor=2.0, p=1.0)

Bases: augly.image.transforms.BaseRandomRangeTransform

__init__(min_factor=0.0, max_factor=2.0, p=1.0)
Parameters
  • min_factor (float) – the lower value on the range of brightness values to choose from. The lower the factor, the darker the image

  • max_factor (float) – the upper value on the range of brightness values to choose from. The higher the factor, the brighter the image

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_random_transform(image, metadata=None, bboxes=None, bbox_format=None)

Transform that randomly changes the brightness of an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.RandomEmojiOverlay(emoji_directory='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/twemojis/smileys', opacity=1.0, emoji_size=0.15, x_pos=0.4, y_pos=0.8, seed=42, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(emoji_directory='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/twemojis/smileys', opacity=1.0, emoji_size=0.15, x_pos=0.4, y_pos=0.8, seed=42, p=1.0)
Parameters
  • emoji_directory (str) – iopath directory uri containing the emoji images

  • opacity (float) – the lower the opacity, the more transparent the overlaid emoji

  • emoji_size (Union[float, Tuple[float, float]]) – size of the emoji is emoji_size * height of the original image. If set to a tuple, a position will randomly be chosen from the range provided

  • x_pos (Union[float, Tuple[float, float]]) – position of emoji relative to the image width. If set to a tuple, a position will randomly be chosen from the range provided

  • y_pos (Union[float, Tuple[float, float]]) – position of emoji relative to the image height. If set to a tuple, a position will randomly be chosen from the range provided

  • seed (Optional[int]) – if provided, this will set the random seed to ensure consistency between runs

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Transform that overlays a random emoji onto an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.RandomNoise(mean=0.0, var=0.01, seed=42, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(mean=0.0, var=0.01, seed=42, p=1.0)
Parameters
  • mean (float) – mean of the gaussian noise added

  • var (float) – variance of the gaussian noise added

  • seed (int) – if provided, this will set the random seed before generating noise

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Adds random noise to the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.RandomPixelization(min_ratio=0.1, max_ratio=1.0, p=1.0)

Bases: augly.image.transforms.BaseRandomRangeTransform

__init__(min_ratio=0.1, max_ratio=1.0, p=1.0)
Parameters
  • min_ratio (float) – the lower value on the range of pixelization ratio values to choose from. Smaller values result in a more pixelated image, 1.0 indicates no change, and any value above one doesn’t have a noticeable effect

  • max_ratio (float) – the upper value on the range of pixelization ratio values to choose from. Smaller values result in a more pixelated image, 1.0 indicates no change, and any value above one doesn’t have a noticeable effect

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_random_transform(image, metadata=None, bboxes=None, bbox_format=None)

Transform that randomly pixelizes an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.RandomRotation(min_degrees=0.0, max_degrees=180.0, p=1.0)

Bases: augly.image.transforms.BaseRandomRangeTransform

__init__(min_degrees=0.0, max_degrees=180.0, p=1.0)
Parameters
  • min_degrees (float) – the lower value on the range of degree values to choose from

  • max_degrees (float) – the upper value on the range of degree values to choose from

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_random_transform(image, metadata=None, bboxes=None, bbox_format=None)

Transform that randomly rotates an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.Resize(width=None, height=None, resample=2, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(width=None, height=None, resample=2, p=1.0)
Parameters
  • width (Optional[int]) – the desired width the image should be resized to have. If None, the original image width will be used

  • height (Optional[int]) – the desired height the image should be resized to have. If None, the original image height will be used

  • resample (Any) – A resampling filter. This can be one of PIL.Image.NEAREST, PIL.Image.BOX, PIL.Image.BILINEAR, PIL.Image.HAMMING, PIL.Image.BICUBIC, or PIL.Image.LANCZOS

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Resizes an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.Rotate(degrees=15.0, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(degrees=15.0, p=1.0)
Parameters
  • degrees (float) – the amount of degrees that the original image will be rotated counter clockwise

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Rotates the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.Saturation(factor=1.0, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(factor=1.0, p=1.0)
Parameters
  • factor (float) – a saturation factor of below 1.0 lowers the saturation, a factor of 1.0 gives the original image, and a factor greater than 1.0 adds saturation

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Alters the saturation of an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.Scale(factor=0.5, interpolation=None, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(factor=0.5, interpolation=None, p=1.0)
Parameters
  • scale_factor – the ratio by which the image should be down-scaled or upscaled

  • interpolation (Optional[int]) – interpolation method. This can be one of PIL.Image.NEAREST, PIL.Image.BOX, PIL.Image.BILINEAR, PIL.Image.HAMMING, PIL.Image.BICUBIC or PIL.Image.LANCZOS

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Alters the resolution of an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.Sharpen(factor=1.0, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(factor=1.0, p=1.0)
Parameters
  • factor (float) – a factor of below 1.0 blurs the image, a factor of 1.0 gives the original image, and a factor greater than 1.0 sharpens the image

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Alters the sharpness of the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.ShufflePixels(factor=1.0, seed=10, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(factor=1.0, seed=10, p=1.0)
Parameters
  • factor (float) – a control parameter between 0.0 and 1.0. While a factor of 0.0 returns the original image, a factor of 1.0 performs full shuffling

  • seed (int) – seed for numpy random generator to select random pixels for shuffling

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Shuffles the pixels of an image with respect to the shuffling factor. The factor denotes percentage of pixels to be shuffled and randomly selected Note: The actual number of pixels will be less than the percentage given due to the probability of pixels staying in place in the course of shuffling

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.Skew(skew_factor=0.5, axis=0, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(skew_factor=0.5, axis=0, p=1.0)
Parameters
  • skew_factor (float) – the level of skew to apply to the image; a larger absolute value will result in a more intense skew. Recommended range is between [-2, 2]

  • axis (int) – the axis along which the image will be skewed; can be set to 0 (x-axis) or 1 (y-axis)

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Skews an image with respect to its x or y-axis

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.transforms.VFlip(p=1.0)

Bases: augly.image.transforms.BaseTransform

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Vertically flips an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

Module contents

class augly.image.ApplyLambda(aug_function=<function ApplyLambda.<lambda>>, p=1.0, **kwargs)

Bases: augly.image.transforms.BaseTransform

__init__(aug_function=<function ApplyLambda.<lambda>>, p=1.0, **kwargs)
Parameters
  • aug_function (Callable[..., Image]) – the augmentation function to be applied onto the image (should expect a PIL image as input and return one)

  • p (float) – the probability of the transform being applied; default value is 1.0

  • **kwargs

    the input attributes to be passed into the augmentation function to be applied

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Apply a user-defined lambda on an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.ApplyPILFilter(filter_type=<class 'PIL.ImageFilter.EDGE_ENHANCE_MORE'>, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(filter_type=<class 'PIL.ImageFilter.EDGE_ENHANCE_MORE'>, p=1.0)
Parameters
  • filter_type (Union[Callable, Filter]) – the PIL ImageFilter to apply to the image

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Applies a given PIL filter to the input image using Image.filter()

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.Blur(radius=2.0, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(radius=2.0, p=1.0)
Parameters
  • radius (float) – the larger the radius, the blurrier the image

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Blurs the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.Brightness(factor=1.0, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(factor=1.0, p=1.0)
Parameters
  • factor (float) – values less than 1.0 darken the image and values greater than 1.0 brighten the image. Setting factor to 1.0 will not alter the image’s brightness

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Alters the brightness of the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.ChangeAspectRatio(ratio=1.0, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(ratio=1.0, p=1.0)
Parameters
  • ratio (float) – aspect ratio, i.e. width/height, of the new image

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Alters the aspect ratio of the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.ClipImageSize(min_resolution=None, max_resolution=None, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(min_resolution=None, max_resolution=None, p=1.0)
Parameters
  • min_resolution (Optional[int]) – the minimum resolution, i.e. width * height, that the augmented image should have; if the input image has a lower resolution than this, the image will be scaled up as necessary

  • max_resolution (Optional[int]) – the maximum resolution, i.e. width * height, that the augmented image should have; if the input image has a higher resolution than this, the image will be scaled down as necessary

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Scales the image up or down if necessary to fit in the given min and max resolution

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.ColorJitter(brightness_factor=1.0, contrast_factor=1.0, saturation_factor=1.0, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(brightness_factor=1.0, contrast_factor=1.0, saturation_factor=1.0, p=1.0)
Parameters
  • brightness_factor (float) – a brightness factor below 1.0 darkens the image, a factor of 1.0 does not alter the image, and a factor greater than 1.0 brightens the image

  • contrast_factor (float) – a contrast factor below 1.0 removes contrast, a factor of 1.0 gives the original image, and a factor greater than 1.0 adds contrast

  • saturation_factor (float) – a saturation factor of below 1.0 lowers the saturation, a factor of 1.0 gives the original image, and a factor greater than 1.0 adds saturation

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Color jitters the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.Compose(transforms, p=1.0)

Bases: augly.image.composition.BaseComposition

__call__(image, metadata=None, bboxes=None, bbox_format=None)

Applies the list of transforms in order to the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies the type of bounding box that was passed in in bboxes. Must specify bbox_type if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.Contrast(factor=1.0, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(factor=1.0, p=1.0)
Parameters
  • factor (float) – zero gives a grayscale image, values below 1.0 decrease contrast, a factor of 1.0 gives the original image, and a factor greater than 1.0 increases contrast

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Alters the contrast of the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.ConvertColor(mode=None, matrix=None, dither=None, palette=0, colors=256, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(mode=None, matrix=None, dither=None, palette=0, colors=256, p=1.0)
Parameters
  • mode (Optional[str]) – defines the type and depth of a pixel in the image. If mode is omitted, a mode is chosen so that all information in the image and the palette can be represented without a palette. For list of available modes, check: https://pillow.readthedocs.io/en/stable/handbook/concepts.html#concept-modes

  • matrix (Union[None, Tuple[float, float, float, float], Tuple[float, float, float, float, float, float, float, float, float, float, float, float]]) – an optional conversion matrix. If given, this should be 4- or 12-tuple containing floating point values.

  • dither (Optional[int]) – dithering method, used when converting from mode “RGB” to “P” or from “RGB” or “L” to “1”. Available methods are NONE or FLOYDSTEINBERG (default)

  • palette (int) – palette to use when converting from mode “RGB” to “P”. Available palettes are WEB or ADAPTIVE

  • colors (int) – number of colors to use for the ADAPTIVE palette. Defaults to 256

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Converts the image in terms of color modes

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.Crop(x1=0.25, y1=0.25, x2=0.75, y2=0.75, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(x1=0.25, y1=0.25, x2=0.75, y2=0.75, p=1.0)
Parameters
  • x1 (float) – position of the left edge of cropped image relative to the width of the original image; must be a float value between 0 and 1

  • y1 (float) – position of the top edge of cropped image relative to the height of the original image; must be a float value between 0 and 1

  • x2 (float) – position of the right edge of cropped image relative to the width of the original image; must be a float value between 0 and 1

  • y2 (float) – position of the bottom edge of cropped image relative to the height of the original image; must be a float value between 0 and 1

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Crops the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.EncodingQuality(quality=50, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(quality=50, p=1.0)
Parameters
  • quality (int) – JPEG encoding quality. 0 is lowest quality, 100 is highest

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Changes the JPEG encoding quality level

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.Grayscale(mode='luminosity', p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(mode='luminosity', p=1.0)
Parameters
  • mode (str) – the type of greyscale conversion to perform; two options are supported (“luminosity” and “average”)

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Alters an image to be grayscale

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.HFlip(p=1.0)

Bases: augly.image.transforms.BaseTransform

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Horizontally flips an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.MaskedComposite(transform_function, mask, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(transform_function, mask, p=1.0)
Parameters
  • mask (Image) – the path to an image or a variable of type PIL.Image.Image for masking. This image can have mode “1”, “L”, or “RGBA”, and must have the same size as the other two images. If the mask is not provided the function returns the augmented image

  • transform_function (BaseTransform) – the augmentation function to be applied. If transform_function is not provided, function returns the input image

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Applies given augmentation function to the masked area of the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.MemeFormat(text='LOL', font_file='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/fonts/Raleway-ExtraBold.ttf', opacity=1.0, text_color=(0, 0, 0), caption_height=250, meme_bg_color=(255, 255, 255), p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(text='LOL', font_file='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/fonts/Raleway-ExtraBold.ttf', opacity=1.0, text_color=(0, 0, 0), caption_height=250, meme_bg_color=(255, 255, 255), p=1.0)
Parameters
  • text (str) – the text to be overlaid/used in the meme. note: if using a very long string, please add in newline characters such that the text remains in a readable font size

  • font_file (str) – iopath uri to the .ttf font file

  • opacity (float) – the lower the opacity, the more transparent the text

  • text_color (Tuple[int, int, int]) – color of the text in RGB values

  • caption_height (int) – the height of the meme caption

  • meme_bg_color (Tuple[int, int, int]) – background color of the meme caption in RGB values

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Creates a new image that looks like a meme, given text and an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.OneOf(transforms, p=1.0)

Bases: augly.image.composition.BaseComposition

__call__(image, metadata=None, bboxes=None, bbox_format=None)

Applies one of the transforms to the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies the type of bounding box that was passed in in bboxes. Must specify bbox_type if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

__init__(transforms, p=1.0)
Parameters
  • transforms (List[BaseTransform]) – a list of transforms to select from; one of which will be chosen to be applied to the media

  • p (float) – the probability of the transform being applied; default value is 1.0

class augly.image.Opacity(level=1.0, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(level=1.0, p=1.0)
Parameters
  • level (float) – the level the opacity should be set to, where 0 means completely transparent and 1 means no transparency at all

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Alters the opacity of an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.OverlayEmoji(emoji_path='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/twemojis/smileys/smiling_face_with_heart_eyes.png', opacity=1.0, emoji_size=0.15, x_pos=0.4, y_pos=0.8, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(emoji_path='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/twemojis/smileys/smiling_face_with_heart_eyes.png', opacity=1.0, emoji_size=0.15, x_pos=0.4, y_pos=0.8, p=1.0)
Parameters
  • emoji_path (str) – iopath uri to the emoji image

  • opacity (float) – the lower the opacity, the more transparent the overlaid emoji

  • emoji_size (float) – size of the emoji is emoji_size * height of the original image

  • x_pos (float) – position of emoji relative to the image width

  • y_pos (float) – position of emoji relative to the image height

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Overlay an emoji onto the original image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.OverlayImage(overlay, opacity=1.0, overlay_size=1.0, x_pos=0.4, y_pos=0.4, max_visible_opacity=0.75, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(overlay, opacity=1.0, overlay_size=1.0, x_pos=0.4, y_pos=0.4, max_visible_opacity=0.75, p=1.0)
Parameters
  • overlay (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image that will be overlaid

  • opacity (float) – the lower the opacity, the more transparent the overlaid image

  • overlay_size (float) – size of the overlaid image is overlay_size * height of the original image

  • x_pos (float) – position of overlaid image relative to the image width

  • y_pos (float) – position of overlaid image relative to the image height

  • max_visible_opacity (float) – if bboxes are passed in, this param will be used as the maximum opacity value through which the src image will still be considered visible; see the function overlay_image_bboxes_helper in utils/bboxes.py for more details about how this is used. If bboxes are not passed in this is not used

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Overlays an image onto another image at position (width * x_pos, height * y_pos)

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.OverlayOntoBackgroundImage(background_image, opacity=1.0, overlay_size=1.0, x_pos=0.4, y_pos=0.4, scale_bg=False, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(background_image, opacity=1.0, overlay_size=1.0, x_pos=0.4, y_pos=0.4, scale_bg=False, p=1.0)
Parameters
  • background_image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image onto which the source image will be overlaid

  • opacity (float) – the lower the opacity, the more transparent the overlaid image

  • overlay_size (float) – size of the overlaid image is overlay_size * height of the background image

  • x_pos (float) – position of overlaid image relative to the background image width with respect to the x-axis

  • y_pos (float) – position of overlaid image relative to the background image height with respect to the y-axis

  • scale_bg (bool) – if True, the background image will be scaled up or down so that overlay_size is respected; if False, the source image will be scaled instead

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Overlays the image onto a given background image at position (width * x_pos, height * y_pos)

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.OverlayOntoScreenshot(template_filepath='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/screenshot_templates/web.png', template_bboxes_filepath='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/screenshot_templates/bboxes.json', max_image_size_pixels=None, crop_src_to_fit=False, resize_src_to_match_template=True, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(template_filepath='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/screenshot_templates/web.png', template_bboxes_filepath='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/screenshot_templates/bboxes.json', max_image_size_pixels=None, crop_src_to_fit=False, resize_src_to_match_template=True, p=1.0)
Parameters
  • template_filepath (str) – iopath uri to the screenshot template

  • template_bboxes_filepath (str) – iopath uri to the file containing the bounding box for each template

  • max_image_size_pixels (Optional[int]) – if provided, the template image and/or src image will be scaled down to avoid an output image with an area greater than this size (in pixels)

  • crop_src_to_fit (bool) – if True, the src image will be cropped if necessary to fit into the template image if the aspect ratios are different. If False, the src image will instead be resized if needed

  • resize_src_to_match_template (bool) – if True, the src image will be resized if it is too big or small in both dimensions to better match the template image. If False, the template image will be resized to match the src image instead. It can be useful to set this to True if the src image is very large so that the augmented image isn’t huge, but instead is the same size as the template image

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Overlay the image onto a screenshot template so it looks like it was screenshotted on Instagram

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.OverlayStripes(line_width=0.5, line_color=(255, 255, 255), line_angle=0, line_density=0.5, line_type='solid', line_opacity=1.0, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(line_width=0.5, line_color=(255, 255, 255), line_angle=0, line_density=0.5, line_type='solid', line_opacity=1.0, p=1.0)
Parameters
  • line_width (float) – the width of individual stripes as a float value ranging from 0 to 1. Defaults to 0.5

  • line_color (Tuple[int, int, int]) – color of the overlaid lines in RGB values

  • line_angle (float) – the angle of the stripes in degrees, ranging from -360° to 360°. Defaults to 0° or horizontal stripes

  • line_density (float) – controls the distance between stripes represented as a float value ranging from 0 to 1, with 1 indicating more densely spaced stripes. Defaults to 0.5

  • line_type (Optional[str]) – the type of stripes. Current options include: dotted, dashed, and solid. Defaults to solid

  • line_opacity (float) – the opacity of the stripes, ranging from 0 to 1 with 1 being opaque. Defaults to 1

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Overlay stripe pattern onto the image (by default, stripes are horizontal)

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.OverlayText(text=[79, 66, 332, 903, 46], font_file='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/fonts/NotoNaskhArabic-Regular.ttf', font_size=0.15, opacity=1.0, color=(255, 0, 0), x_pos=0.0, y_pos=0.5, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(text=[79, 66, 332, 903, 46], font_file='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/fonts/NotoNaskhArabic-Regular.ttf', font_size=0.15, opacity=1.0, color=(255, 0, 0), x_pos=0.0, y_pos=0.5, p=1.0)
Parameters
  • text (List[Union[int, List[int]]]) – indices (into the file) of the characters to be overlaid. Each line of text is represented as a list of int indices; if a list of lists is supplied, multiple lines of text will be overlaid

  • font_file (str) – iopath uri to the .ttf font file

  • font_size (float) – size of the overlaid characters, calculated as font_size * min(height, width) of the original image

  • opacity (float) – the lower the opacity, the more transparent the overlaid text

  • color (Tuple[int, int, int]) – color of the overlaid text in RGB values

  • x_pos (float) – position of the overlaid text relative to the image width

  • y_pos (float) – position of the overlaid text relative to the image height

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Overlay text onto the image (by default, text is randomly overlaid)

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.Pad(w_factor=0.25, h_factor=0.25, color=(0, 0, 0), p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(w_factor=0.25, h_factor=0.25, color=(0, 0, 0), p=1.0)
Parameters
  • w_factor (float) – width * w_factor pixels are padded to both left and right of the image

  • h_factor (float) – height * h_factor pixels are padded to the top and the bottom of the image

  • color (Tuple[int, int, int]) – color of the padded border in RGB values

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Pads the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.PadSquare(color=(0, 0, 0), p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(color=(0, 0, 0), p=1.0)
Parameters
  • color (Tuple[int, int, int]) – color of the padded border in RGB values

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Pads the shorter edge of the image such that it is now square-shaped

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.PerspectiveTransform(sigma=50.0, dx=0.0, dy=0.0, seed=42, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(sigma=50.0, dx=0.0, dy=0.0, seed=42, p=1.0)
Parameters
  • sigma (float) – the standard deviation of the distribution of destination coordinates. the larger the sigma value, the more intense the transform

  • seed (Optional[int]) – if provided, this will set the random seed to ensure consistency between runs

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Apply a perspective transform to the image so it looks like it was taken as a photo from another device (e.g. taking a picture from your phone of a picture on a computer).

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.Pixelization(ratio=1.0, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(ratio=1.0, p=1.0)
Parameters
  • ratio (float) – smaller values result in a more pixelated image, 1.0 indicates no change, and any value above one doesn’t have a noticeable effect

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Pixelizes an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.RandomAspectRatio(min_ratio=0.5, max_ratio=2.0, p=1.0)

Bases: augly.image.transforms.BaseRandomRangeTransform

__init__(min_ratio=0.5, max_ratio=2.0, p=1.0)
Parameters
  • min_ratio (float) – the lower value on the range of aspect ratio values to choose from, i.e. the width/height ratio

  • max_ratio (float) – the upper value on the range of aspect ratio values to choose from, i.e. the width/height ratio

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_random_transform(image, metadata=None, bboxes=None, bbox_format=None)

Transform that randomly changes the aspect ratio of an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.RandomBlur(min_radius=0.0, max_radius=10.0, p=1.0)

Bases: augly.image.transforms.BaseRandomRangeTransform

__init__(min_radius=0.0, max_radius=10.0, p=1.0)
Parameters
  • min_radius (float) – the lower value on the range of blur values to choose from. The larger the radius, the blurrier the image

  • max_radius (float) – the upper value on the range of blur values to choose from. The larger the radius, the blurrier the image

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_random_transform(image, metadata=None, bboxes=None, bbox_format=None)

Transform that randomly blurs an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.RandomBrightness(min_factor=0.0, max_factor=2.0, p=1.0)

Bases: augly.image.transforms.BaseRandomRangeTransform

__init__(min_factor=0.0, max_factor=2.0, p=1.0)
Parameters
  • min_factor (float) – the lower value on the range of brightness values to choose from. The lower the factor, the darker the image

  • max_factor (float) – the upper value on the range of brightness values to choose from. The higher the factor, the brighter the image

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_random_transform(image, metadata=None, bboxes=None, bbox_format=None)

Transform that randomly changes the brightness of an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.RandomEmojiOverlay(emoji_directory='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/twemojis/smileys', opacity=1.0, emoji_size=0.15, x_pos=0.4, y_pos=0.8, seed=42, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(emoji_directory='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/twemojis/smileys', opacity=1.0, emoji_size=0.15, x_pos=0.4, y_pos=0.8, seed=42, p=1.0)
Parameters
  • emoji_directory (str) – iopath directory uri containing the emoji images

  • opacity (float) – the lower the opacity, the more transparent the overlaid emoji

  • emoji_size (Union[float, Tuple[float, float]]) – size of the emoji is emoji_size * height of the original image. If set to a tuple, a position will randomly be chosen from the range provided

  • x_pos (Union[float, Tuple[float, float]]) – position of emoji relative to the image width. If set to a tuple, a position will randomly be chosen from the range provided

  • y_pos (Union[float, Tuple[float, float]]) – position of emoji relative to the image height. If set to a tuple, a position will randomly be chosen from the range provided

  • seed (Optional[int]) – if provided, this will set the random seed to ensure consistency between runs

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Transform that overlays a random emoji onto an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.RandomNoise(mean=0.0, var=0.01, seed=42, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(mean=0.0, var=0.01, seed=42, p=1.0)
Parameters
  • mean (float) – mean of the gaussian noise added

  • var (float) – variance of the gaussian noise added

  • seed (int) – if provided, this will set the random seed before generating noise

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Adds random noise to the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.RandomPixelization(min_ratio=0.1, max_ratio=1.0, p=1.0)

Bases: augly.image.transforms.BaseRandomRangeTransform

__init__(min_ratio=0.1, max_ratio=1.0, p=1.0)
Parameters
  • min_ratio (float) – the lower value on the range of pixelization ratio values to choose from. Smaller values result in a more pixelated image, 1.0 indicates no change, and any value above one doesn’t have a noticeable effect

  • max_ratio (float) – the upper value on the range of pixelization ratio values to choose from. Smaller values result in a more pixelated image, 1.0 indicates no change, and any value above one doesn’t have a noticeable effect

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_random_transform(image, metadata=None, bboxes=None, bbox_format=None)

Transform that randomly pixelizes an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.RandomRotation(min_degrees=0.0, max_degrees=180.0, p=1.0)

Bases: augly.image.transforms.BaseRandomRangeTransform

__init__(min_degrees=0.0, max_degrees=180.0, p=1.0)
Parameters
  • min_degrees (float) – the lower value on the range of degree values to choose from

  • max_degrees (float) – the upper value on the range of degree values to choose from

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_random_transform(image, metadata=None, bboxes=None, bbox_format=None)

Transform that randomly rotates an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.Resize(width=None, height=None, resample=2, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(width=None, height=None, resample=2, p=1.0)
Parameters
  • width (Optional[int]) – the desired width the image should be resized to have. If None, the original image width will be used

  • height (Optional[int]) – the desired height the image should be resized to have. If None, the original image height will be used

  • resample (Any) – A resampling filter. This can be one of PIL.Image.NEAREST, PIL.Image.BOX, PIL.Image.BILINEAR, PIL.Image.HAMMING, PIL.Image.BICUBIC, or PIL.Image.LANCZOS

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Resizes an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.Rotate(degrees=15.0, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(degrees=15.0, p=1.0)
Parameters
  • degrees (float) – the amount of degrees that the original image will be rotated counter clockwise

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Rotates the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.Saturation(factor=1.0, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(factor=1.0, p=1.0)
Parameters
  • factor (float) – a saturation factor of below 1.0 lowers the saturation, a factor of 1.0 gives the original image, and a factor greater than 1.0 adds saturation

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Alters the saturation of an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.Scale(factor=0.5, interpolation=None, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(factor=0.5, interpolation=None, p=1.0)
Parameters
  • scale_factor – the ratio by which the image should be down-scaled or upscaled

  • interpolation (Optional[int]) – interpolation method. This can be one of PIL.Image.NEAREST, PIL.Image.BOX, PIL.Image.BILINEAR, PIL.Image.HAMMING, PIL.Image.BICUBIC or PIL.Image.LANCZOS

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Alters the resolution of an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.Sharpen(factor=1.0, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(factor=1.0, p=1.0)
Parameters
  • factor (float) – a factor of below 1.0 blurs the image, a factor of 1.0 gives the original image, and a factor greater than 1.0 sharpens the image

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Alters the sharpness of the image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.ShufflePixels(factor=1.0, seed=10, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(factor=1.0, seed=10, p=1.0)
Parameters
  • factor (float) – a control parameter between 0.0 and 1.0. While a factor of 0.0 returns the original image, a factor of 1.0 performs full shuffling

  • seed (int) – seed for numpy random generator to select random pixels for shuffling

  • p (float) – the probability of the transform being applied; default value is 1.0

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Shuffles the pixels of an image with respect to the shuffling factor. The factor denotes percentage of pixels to be shuffled and randomly selected Note: The actual number of pixels will be less than the percentage given due to the probability of pixels staying in place in the course of shuffling

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.Skew(skew_factor=0.5, axis=0, p=1.0)

Bases: augly.image.transforms.BaseTransform

__init__(skew_factor=0.5, axis=0, p=1.0)
Parameters
  • skew_factor (float) – the level of skew to apply to the image; a larger absolute value will result in a more intense skew. Recommended range is between [-2, 2]

  • axis (int) – the axis along which the image will be skewed; can be set to 0 (x-axis) or 1 (y-axis)

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Skews an image with respect to its x or y-axis

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

class augly.image.VFlip(p=1.0)

Bases: augly.image.transforms.BaseTransform

apply_transform(image, metadata=None, bboxes=None, bbox_format=None)

Vertically flips an image

Parameters
  • image (Image) – PIL Image to be augmented

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Augmented PIL Image

augly.image.apply_lambda(image, output_path=None, aug_function=<function <lambda>>, metadata=None, bboxes=None, bbox_format=None, **kwargs)

Apply a user-defined lambda on an image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • aug_function (Callable[..., Image]) – the augmentation function to be applied onto the image (should expect a PIL image as input and return one)

  • **kwargs

    the input attributes to be passed into the augmentation function to be applied

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.apply_lambda_intensity(aug_function, **kwargs)
Return type

float

augly.image.apply_pil_filter(image, output_path=None, filter_type=<class 'PIL.ImageFilter.EDGE_ENHANCE_MORE'>, metadata=None, bboxes=None, bbox_format=None)

Applies a given PIL filter to the input image using Image.filter()

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • filter_type (Union[Callable, Filter]) – the PIL ImageFilter to apply to the image

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.apply_pil_filter_intensity(**kwargs)
Return type

float

augly.image.aug_np_wrapper(image, aug_function, **kwargs)

This function is a wrapper on all image augmentation functions such that a numpy array could be passed in as input instead of providing the path to the image or a PIL Image

Parameters
  • image (ndarray) – the numpy array representing the image to be augmented

  • aug_function (Callable[..., None]) – the augmentation function to be applied onto the image

  • **kwargs

    the input attributes to be passed into the augmentation function

Return type

ndarray

augly.image.blur(image, output_path=None, radius=2.0, metadata=None, bboxes=None, bbox_format=None)

Blurs the image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • radius (float) – the larger the radius, the blurrier the image

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.blur_intensity(radius, **kwargs)
Return type

float

augly.image.brightness(image, output_path=None, factor=1.0, metadata=None, bboxes=None, bbox_format=None)

Changes the brightness of the image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • factor (float) – values less than 1.0 darken the image and values greater than 1.0 brighten the image. Setting factor to 1.0 will not alter the image’s brightness

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.brightness_intensity(factor, **kwargs)
Return type

float

augly.image.change_aspect_ratio(image, output_path=None, ratio=1.0, metadata=None, bboxes=None, bbox_format=None)

Changes the aspect ratio of the image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • ratio (float) – aspect ratio, i.e. width/height, of the new image

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.change_aspect_ratio_intensity(ratio, metadata, **kwargs)
Return type

float

augly.image.clip_image_size(image, output_path=None, min_resolution=None, max_resolution=None, metadata=None, bboxes=None, bbox_format=None)

Scales the image up or down if necessary to fit in the given min and max resolution

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • min_resolution (Optional[int]) – the minimum resolution, i.e. width * height, that the augmented image should have; if the input image has a lower resolution than this, the image will be scaled up as necessary

  • max_resolution (Optional[int]) – the maximum resolution, i.e. width * height, that the augmented image should have; if the input image has a higher resolution than this, the image will be scaled down as necessary

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.clip_image_size_intensity(metadata, **kwargs)
Return type

float

augly.image.color_jitter(image, output_path=None, brightness_factor=1.0, contrast_factor=1.0, saturation_factor=1.0, metadata=None, bboxes=None, bbox_format=None)

Color jitters the image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • brightness_factor (float) – a brightness factor below 1.0 darkens the image, a factor of 1.0 does not alter the image, and a factor greater than 1.0 brightens the image

  • contrast_factor (float) – a contrast factor below 1.0 removes contrast, a factor of 1.0 gives the original image, and a factor greater than 1.0 adds contrast

  • saturation_factor (float) – a saturation factor of below 1.0 lowers the saturation, a factor of 1.0 gives the original image, and a factor greater than 1.0 adds saturation

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.color_jitter_intensity(brightness_factor, contrast_factor, saturation_factor, **kwargs)
Return type

float

augly.image.contrast(image, output_path=None, factor=1.0, metadata=None, bboxes=None, bbox_format=None)

Alters the contrast of the image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • factor (float) – zero gives a grayscale image, values below 1.0 decreases contrast, a factor of 1.0 gives the original image, and a factor greater than 1.0 increases contrast

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Image.Image - Augmented PIL Image

augly.image.contrast_intensity(factor, **kwargs)
Return type

float

augly.image.convert_color(image, output_path=None, mode=None, matrix=None, dither=None, palette=0, colors=256, metadata=None, bboxes=None, bbox_format=None)

Converts the image in terms of color modes

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • mode (Optional[str]) – defines the type and depth of a pixel in the image. If mode is omitted, a mode is chosen so that all information in the image and the palette can be represented without a palette. For list of available modes, check: https://pillow.readthedocs.io/en/stable/handbook/concepts.html#concept-modes

  • matrix (Union[None, Tuple[float, float, float, float], Tuple[float, float, float, float, float, float, float, float, float, float, float, float]]) – an optional conversion matrix. If given, this should be 4- or 12-tuple containing floating point values

  • dither (Optional[int]) – dithering method, used when converting from mode “RGB” to “P” or from “RGB” or “L” to “1”. Available methods are NONE or FLOYDSTEINBERG (default).

  • palette (int) – palette to use when converting from mode “RGB” to “P”. Available palettes are WEB or ADAPTIVE

  • colors (int) – number of colors to use for the ADAPTIVE palette. Defaults to 256.

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

Image.Image - Augmented PIL Image

augly.image.convert_color_intensity(**kwargs)
Return type

float

augly.image.crop(image, output_path=None, x1=0.25, y1=0.25, x2=0.75, y2=0.75, metadata=None, bboxes=None, bbox_format=None)

Crops the image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • x1 (float) – position of the left edge of cropped image relative to the width of the original image; must be a float value between 0 and 1

  • y1 (float) – position of the top edge of cropped image relative to the height of the original image; must be a float value between 0 and 1

  • x2 (float) – position of the right edge of cropped image relative to the width of the original image; must be a float value between 0 and 1

  • y2 (float) – position of the bottom edge of cropped image relative to the height of the original image; must be a float value between 0 and 1

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.crop_intensity(metadata, **kwargs)
Return type

float

augly.image.encoding_quality(image, output_path=None, quality=50, metadata=None, bboxes=None, bbox_format=None)

Changes the JPEG encoding quality level

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • quality (int) – JPEG encoding quality. 0 is lowest quality, 100 is highest

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.encoding_quality_intensity(quality, **kwargs)
Return type

float

augly.image.grayscale(image, output_path=None, mode='luminosity', metadata=None, bboxes=None, bbox_format=None)

Changes an image to be grayscale

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • mode (str) – the type of greyscale conversion to perform; two options are supported (“luminosity” and “average”)

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.grayscale_intensity(**kwargs)
Return type

float

augly.image.hflip(image, output_path=None, metadata=None, bboxes=None, bbox_format=None)

Horizontally flips an image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.hflip_intensity(**kwargs)
Return type

float

augly.image.masked_composite(image, output_path=None, mask=None, transform_function=None, metadata=None, bboxes=None, bbox_format=None)

Applies given augmentation function to the masked area of the image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • mask (Union[str, Image, None]) – the path to an image or a variable of type PIL.Image.Image for masking. This image can have mode “1”, “L”, or “RGBA”, and must have the same size as the other two images. If the mask is not provided the function returns the augmented image

  • transform_function (Optional[Callable]) – the augmentation function to be applied. If transform_function is not provided, the function returns the input image

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.masked_composite_intensity(mask, metadata, **kwargs)
Return type

float

augly.image.meme_format(image, output_path=None, text='LOL', font_file='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/fonts/Raleway-ExtraBold.ttf', opacity=1.0, text_color=(0, 0, 0), caption_height=250, meme_bg_color=(255, 255, 255), metadata=None, bboxes=None, bbox_format=None)

Creates a new image that looks like a meme, given text and an image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • text (str) – the text to be overlaid/used in the meme. note: if using a very long string, please add in newline characters such that the text remains in a readable font size.

  • font_file (str) – iopath uri to a .ttf font file

  • opacity (float) – the lower the opacity, the more transparent the text

  • text_color (Tuple[int, int, int]) – color of the text in RGB values

  • caption_height (int) – the height of the meme caption

  • meme_bg_color (Tuple[int, int, int]) – background color of the meme caption in RGB values

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.meme_format_intensity(metadata, **kwargs)
Return type

float

augly.image.opacity(image, output_path=None, level=1.0, metadata=None, bboxes=None, bbox_format=None)

Alter the opacity of an image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • level (float) – the level the opacity should be set to, where 0 means completely transparent and 1 means no transparency at all

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.opacity_intensity(level, **kwargs)
Return type

float

augly.image.overlay_emoji(image, output_path=None, emoji_path='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/twemojis/smileys/smiling_face_with_heart_eyes.png', opacity=1.0, emoji_size=0.15, x_pos=0.4, y_pos=0.8, metadata=None, bboxes=None, bbox_format=None)

Overlay an emoji onto the original image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • emoji_path (str) – iopath uri to the emoji image

  • opacity (float) – the lower the opacity, the more transparent the overlaid emoji

  • emoji_size (float) – size of the emoji is emoji_size * height of the original image

  • x_pos (float) – position of emoji relative to the image width

  • y_pos (float) – position of emoji relative to the image height

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.overlay_emoji_intensity(emoji_size, opacity, **kwargs)
Return type

float

augly.image.overlay_image(image, overlay, output_path=None, opacity=1.0, overlay_size=1.0, x_pos=0.4, y_pos=0.4, max_visible_opacity=0.75, metadata=None, bboxes=None, bbox_format=None)

Overlays an image onto another image at position (width * x_pos, height * y_pos)

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • overlay (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image that will be overlaid

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • opacity (float) – the lower the opacity, the more transparent the overlaid image

  • overlay_size (float) – size of the overlaid image is overlay_size * height of the original image

  • x_pos (float) – position of overlaid image relative to the image width

  • max_visible_opacity (float) – if bboxes are passed in, this param will be used as the maximum opacity value through which the src image will still be considered visible; see the function overlay_image_bboxes_helper in utils/bboxes.py for more details about how this is used. If bboxes are not passed in this is not used

  • y_pos (float) – position of overlaid image relative to the image height

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.overlay_image_intensity(opacity, overlay_size, **kwargs)
Return type

float

augly.image.overlay_onto_background_image(image, background_image, output_path=None, opacity=1.0, overlay_size=1.0, x_pos=0.4, y_pos=0.4, scale_bg=False, metadata=None, bboxes=None, bbox_format=None)

Overlays the image onto a given background image at position (width * x_pos, height * y_pos)

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • background_image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image onto which the source image will be overlaid

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • opacity (float) – the lower the opacity, the more transparent the overlaid image

  • overlay_size (float) – size of the overlaid image is overlay_size * height of the background image

  • x_pos (float) – position of overlaid image relative to the background image width with respect to the x-axis

  • y_pos (float) – position of overlaid image relative to the background image height with respect to the y-axis

  • scale_bg (bool) – if True, the background image will be scaled up or down so that overlay_size is respected; if False, the source image will be scaled instead

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.overlay_onto_background_image_intensity(opacity, overlay_size, **kwargs)
Return type

float

augly.image.overlay_onto_screenshot(image, output_path=None, template_filepath='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/screenshot_templates/web.png', template_bboxes_filepath='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/screenshot_templates/bboxes.json', max_image_size_pixels=None, crop_src_to_fit=False, resize_src_to_match_template=True, metadata=None, bboxes=None, bbox_format=None)

Overlay the image onto a screenshot template so it looks like it was screenshotted on Instagram

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • template_filepath (str) – iopath uri to the screenshot template

  • template_bboxes_filepath (str) – iopath uri to the file containing the bounding box for each template

  • max_image_size_pixels (Optional[int]) – if provided, the template image and/or src image will be scaled down to avoid an output image with an area greater than this size (in pixels)

  • crop_src_to_fit (bool) – if True, the src image will be cropped if necessary to fit into the template image if the aspect ratios are different. If False, the src image will instead be resized if needed

  • resize_src_to_match_template (bool) – if True, the src image will be resized if it is too big or small in both dimensions to better match the template image. If False, the template image will be resized to match the src image instead. It can be useful to set this to True if the src image is very large so that the augmented image isn’t huge, but instead is the same size as the template image

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.overlay_onto_screenshot_intensity(template_filepath, template_bboxes_filepath, metadata, **kwargs)
Return type

float

augly.image.overlay_stripes(image, output_path=None, line_width=0.5, line_color=(255, 255, 255), line_angle=0, line_density=0.5, line_type='solid', line_opacity=1.0, metadata=None, bboxes=None, bbox_format=None)

Overlay stripe pattern onto the image (by default, white horizontal stripes are overlaid)

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • line_width (float) – the width of individual stripes as a float value ranging from 0 to 1. Defaults to 0.5

  • line_color (Tuple[int, int, int]) – color of the overlaid stripes in RGB values

  • line_angle (float) – the angle of the stripes in degrees, ranging from -360° to 360°. Defaults to 0° or horizontal stripes

  • line_density (float) – controls the distance between stripes represented as a float value ranging from 0 to 1, with 1 indicating more densely spaced stripes. Defaults to 0.5

  • line_type (Optional[str]) – the type of stripes. Current options include: dotted, dashed, and solid. Defaults to solid

  • line_opacity (float) – the opacity of the stripes, ranging from 0 to 1 with 1 being opaque. Defaults to 1.0

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.overlay_stripes_intensity(line_width, line_angle, line_density, line_type, line_opacity, metadata, **kwargs)
Return type

float

augly.image.overlay_text(image, output_path=None, text=[79, 66, 332, 903, 46], font_file='/home/docs/checkouts/readthedocs.org/user_builds/augly/checkouts/latest/augly/assets/fonts/NotoNaskhArabic-Regular.ttf', font_size=0.15, opacity=1.0, color=(255, 0, 0), x_pos=0.0, y_pos=0.5, metadata=None, bboxes=None, bbox_format=None)

Overlay text onto the image (by default, text is randomly overlaid)

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • text (List[Union[int, List[int]]]) – indices (into the file) of the characters to be overlaid. Each line of text is represented as a list of int indices; if a list of lists is supplied, multiple lines of text will be overlaid

  • font_file (str) – iopath uri to the .ttf font file

  • font_size (float) – size of the overlaid characters, calculated as font_size * min(height, width) of the original image

  • opacity (float) – the lower the opacity, the more transparent the overlaid text

  • color (Tuple[int, int, int]) – color of the overlaid text in RGB values

  • x_pos (float) – position of the overlaid text relative to the image width

  • y_pos (float) – position of the overlaid text relative to the image height

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.overlay_text_intensity(opacity, font_size, **kwargs)
Return type

float

augly.image.pad(image, output_path=None, w_factor=0.25, h_factor=0.25, color=(0, 0, 0), metadata=None, bboxes=None, bbox_format=None)

Pads the image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • w_factor (float) – width * w_factor pixels are padded to both left and right of the image

  • h_factor (float) – height * h_factor pixels are padded to the top and the bottom of the image

  • color (Tuple[int, int, int]) – color of the padded border in RGB values

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.pad_intensity(metadata, **kwargs)
Return type

float

augly.image.pad_square(image, output_path=None, color=(0, 0, 0), metadata=None, bboxes=None, bbox_format=None)

Pads the shorter edge of the image such that it is now square-shaped

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • color (Tuple[int, int, int]) – color of the padded border in RGB values

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.pad_square_intensity(metadata, **kwargs)
Return type

float

augly.image.perspective_transform(image, output_path=None, sigma=50.0, dx=0.0, dy=0.0, seed=42, crop_out_black_border=False, metadata=None, bboxes=None, bbox_format=None)

Apply a perspective transform to the image so it looks like it was taken as a photo from another device (e.g. taking a picture from your phone of a picture on a computer).

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • sigma (float) – the standard deviation of the distribution of destination coordinates. the larger the sigma value, the more intense the transform

  • dx (float) – change in x for the perspective transform; instead of providing sigma you can provide a scalar value to be precise

  • dy (float) – change in y for the perspective transform; instead of providing sigma you can provide a scalar value to be precise

  • seed (Optional[int]) – if provided, this will set the random seed to ensure consistency between runs

  • crop_out_black_border (bool) – if True, will crop out the black border resulting from the perspective transform by cropping to the largest center rectangle with no black

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.perspective_transform_intensity(sigma, **kwargs)
Return type

float

augly.image.pixelization(image, output_path=None, ratio=1.0, metadata=None, bboxes=None, bbox_format=None)

Pixelizes an image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • ratio (float) – smaller values result in a more pixelated image, 1.0 indicates no change, and any value above one doesn’t have a noticeable effect

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.pixelization_intensity(ratio, **kwargs)
Return type

float

augly.image.random_noise(image, output_path=None, mean=0.0, var=0.01, seed=42, metadata=None, bboxes=None, bbox_format=None)

Adds random noise to the image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • mean (float) – mean of the gaussian noise added

  • var (float) – variance of the gaussian noise added

  • seed (int) – if provided, this will set the random seed before generating noise

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.random_noise_intensity(mean, var, **kwargs)
Return type

float

augly.image.resize(image, output_path=None, width=None, height=None, resample=2, metadata=None, bboxes=None, bbox_format=None)

Resizes an image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • width (Optional[int]) – the desired width the image should be resized to have. If None, the original image width will be used

  • height (Optional[int]) – the desired height the image should be resized to have. If None, the original image height will be used

  • resample (Any) – A resampling filter. This can be one of PIL.Image.NEAREST, PIL.Image.BOX, PIL.Image.BILINEAR, PIL.Image.HAMMING, PIL.Image.BICUBIC, or PIL.Image.LANCZOS

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.resize_intensity(metadata, **kwargs)
Return type

float

augly.image.rotate(image, output_path=None, degrees=15.0, metadata=None, bboxes=None, bbox_format=None)

Rotates the image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • degrees (float) – the amount of degrees that the original image will be rotated counter clockwise

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.rotate_intensity(degrees, **kwargs)
Return type

float

augly.image.saturation(image, output_path=None, factor=1.0, metadata=None, bboxes=None, bbox_format=None)

Alters the saturation of the image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • factor (float) – a saturation factor of below 1.0 lowers the saturation, a factor of 1.0 gives the original image, and a factor greater than 1.0 adds saturation

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.saturation_intensity(factor, **kwargs)
Return type

float

augly.image.scale(image, output_path=None, factor=0.5, interpolation=None, metadata=None, bboxes=None, bbox_format=None)

Alters the resolution of an image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • factor (float) – the ratio by which the image should be downscaled or upscaled

  • interpolation (Optional[int]) – interpolation method. This can be one of PIL.Image.NEAREST, PIL.Image.BOX, PIL.Image.BILINEAR, PIL.Image.HAMMING, PIL.Image.BICUBIC or PIL.Image.LANCZOS

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.scale_intensity(factor, **kwargs)
Return type

float

augly.image.sharpen(image, output_path=None, factor=1.0, metadata=None, bboxes=None, bbox_format=None)

Changes the sharpness of the image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • factor (float) – a factor of below 1.0 blurs the image, a factor of 1.0 gives the original image, and a factor greater than 1.0 sharpens the image

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.sharpen_intensity(factor, **kwargs)
Return type

float

augly.image.shuffle_pixels(image, output_path=None, factor=1.0, seed=10, metadata=None, bboxes=None, bbox_format=None)

Shuffles the pixels of an image with respect to the shuffling factor. The factor denotes percentage of pixels to be shuffled and randomly selected Note: The actual number of pixels will be less than the percentage given due to the probability of pixels staying in place in the course of shuffling

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • factor (float) – a control parameter between 0.0 and 1.0. While a factor of 0.0 returns the original image, a factor of 1.0 performs full shuffling

  • seed (int) – seed for numpy random generator to select random pixels for shuffling

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.shuffle_pixels_intensity(factor, **kwargs)
Return type

float

augly.image.skew(image, output_path=None, skew_factor=0.5, axis=0, metadata=None, bboxes=None, bbox_format=None)

Skews an image with respect to its x or y-axis

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • skew_factor (float) – the level of skew to apply to the image; a larger absolute value will result in a more intense skew. Recommended range is between [-2, 2]

  • axis (int) – the axis along which the image will be skewed; can be set to 0 (x-axis) or 1 (y-axis)

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.skew_intensity(skew_factor, **kwargs)
Return type

float

augly.image.vflip(image, output_path=None, metadata=None, bboxes=None, bbox_format=None)

Vertically flips an image

Parameters
  • image (Union[str, Image]) – the path to an image or a variable of type PIL.Image.Image to be augmented

  • output_path (Optional[str]) – the path in which the resulting image will be stored. If None, the resulting PIL Image will still be returned

  • metadata (Optional[List[Dict[str, Any]]]) – if set to be a list, metadata about the function execution including its name, the source & dest width, height, etc. will be appended to the inputted list. If set to None, no metadata will be appended or returned

  • bboxes (Optional[List[Tuple]]) – a list of bounding boxes can be passed in here if desired. If provided, this list will be modified in place such that each bounding box is transformed according to this function

  • bbox_format (Optional[str]) – signifies what bounding box format was used in bboxes. Must specify bbox_format if bboxes is provided. Supported bbox_format values are “pascal_voc”, “pascal_voc_norm”, “coco”, and “yolo”

Return type

Image

Returns

the augmented PIL Image

augly.image.vflip_intensity(**kwargs)
Return type

float