imgaug

Collection of basic functions used throughout imgaug.

imgaug.imgaug.BackgroundAugmenter(*args, **kwargs)
imgaug.imgaug.Batch(*args, **kwargs)
imgaug.imgaug.BatchLoader(*args, **kwargs)
imgaug.imgaug.BoundingBox(*args, **kwargs)
imgaug.imgaug.BoundingBoxesOnImage(*args, **kwargs)
exception imgaug.imgaug.DeprecationWarning[source]

Bases: Warning

Warning for deprecated calls.

Since python 2.7 DeprecatedWarning is silent by default. So we define our own DeprecatedWarning here so that it is not silent by default.

imgaug.imgaug.HeatmapsOnImage(*args, **kwargs)
class imgaug.imgaug.HooksHeatmaps(activator=None, propagator=None, preprocessor=None, postprocessor=None)[source]

Bases: imgaug.imgaug.HooksImages

Class to intervene with heatmap augmentation runs.

This is e.g. useful to dynamically deactivate some augmenters.

This class is currently the same as the one for images. This may or may not change in the future.

Methods

is_activated(self, images, augmenter, …) Estimate whether an augmenter may be executed.
is_propagating(self, images, augmenter, …) Estimate whether an augmenter may call its children.
postprocess(self, images, augmenter, parents) Postprocess input data per augmenter after augmentation.
preprocess(self, images, augmenter, parents) Preprocess input data per augmenter before augmentation.
class imgaug.imgaug.HooksImages(activator=None, propagator=None, preprocessor=None, postprocessor=None)[source]

Bases: object

Class to intervene with image augmentation runs.

This is e.g. useful to dynamically deactivate some augmenters.

Parameters:
  • activator (None or callable, optional) – A function that gives permission to execute an augmenter. The expected interface is:

    ``f(images, augmenter, parents, default)``
    

    where images are the input images to augment, augmenter is the instance of the augmenter to execute, parents are previously executed augmenters and default is an expected default value to be returned if the activator function does not plan to make a decision for the given inputs.

  • propagator (None or callable, optional) – A function that gives permission to propagate the augmentation further to the children of an augmenter. This happens after the activator. In theory, an augmenter may augment images itself (if allowed by the activator) and then execute child augmenters afterwards (if allowed by the propagator). If the activator returned False, the propagation step will never be executed. The expected interface is:

    ``f(images, augmenter, parents, default)``
    

    with all arguments having identical meaning to the activator.

  • preprocessor (None or callable, optional) – A function to call before an augmenter performed any augmentations. The interface is:

    f(images, augmenter, parents)

    with all arguments having identical meaning to the activator. It is expected to return the input images, optionally modified.

  • postprocessor (None or callable, optional) – A function to call after an augmenter performed augmentations. The interface is the same as for the preprocessor.

Examples

>>> import numpy as np
>>> import imgaug as ia
>>> import imgaug.augmenters as iaa
>>> seq = iaa.Sequential([
>>>     iaa.GaussianBlur(3.0, name="blur"),
>>>     iaa.Dropout(0.05, name="dropout"),
>>>     iaa.Affine(translate_px=-5, name="affine")
>>> ])
>>> images = [np.zeros((10, 10), dtype=np.uint8)]
>>>
>>> def activator(images, augmenter, parents, default):
>>>     return False if augmenter.name in ["blur", "dropout"] else default
>>>
>>> seq_det = seq.to_deterministic()
>>> images_aug = seq_det.augment_images(images)
>>> heatmaps = [np.random.rand(*(3, 10, 10))]
>>> heatmaps_aug = seq_det.augment_images(
>>>     heatmaps,
>>>     hooks=ia.HooksImages(activator=activator)
>>> )

This augments images and their respective heatmaps in the same way. The heatmaps however are only modified by Affine, not by GaussianBlur or Dropout.

Methods

is_activated(self, images, augmenter, …) Estimate whether an augmenter may be executed.
is_propagating(self, images, augmenter, …) Estimate whether an augmenter may call its children.
postprocess(self, images, augmenter, parents) Postprocess input data per augmenter after augmentation.
preprocess(self, images, augmenter, parents) Preprocess input data per augmenter before augmentation.
is_activated(self, images, augmenter, parents, default)[source]

Estimate whether an augmenter may be executed.

This also affects propagation of data to child augmenters.

Returns:If True, the augmenter may be executed. Otherwise False.
Return type:bool
is_propagating(self, images, augmenter, parents, default)[source]

Estimate whether an augmenter may call its children.

This function decides whether an augmenter with children is allowed to call these in order to further augment the inputs. Note that if the augmenter itself performs augmentations (before/after calling its children), these may still be executed, even if this method returns False.

Returns:If True, the augmenter may propagate data to its children. Otherwise False.
Return type:bool
postprocess(self, images, augmenter, parents)[source]

Postprocess input data per augmenter after augmentation.

Returns:The input images, optionally modified.
Return type:(N,H,W,C) ndarray or (N,H,W) ndarray or list of (H,W,C) ndarray or list of (H,W) ndarray
preprocess(self, images, augmenter, parents)[source]

Preprocess input data per augmenter before augmentation.

Returns:The input images, optionally modified.
Return type:(N,H,W,C) ndarray or (N,H,W) ndarray or list of (H,W,C) ndarray or list of (H,W) ndarray
class imgaug.imgaug.HooksKeypoints(activator=None, propagator=None, preprocessor=None, postprocessor=None)[source]

Bases: imgaug.imgaug.HooksImages

Class to intervene with keypoint augmentation runs.

This is e.g. useful to dynamically deactivate some augmenters.

This class is currently the same as the one for images. This may or may not change in the future.

Methods

is_activated(self, images, augmenter, …) Estimate whether an augmenter may be executed.
is_propagating(self, images, augmenter, …) Estimate whether an augmenter may call its children.
postprocess(self, images, augmenter, parents) Postprocess input data per augmenter after augmentation.
preprocess(self, images, augmenter, parents) Preprocess input data per augmenter before augmentation.
imgaug.imgaug.Keypoint(*args, **kwargs)
imgaug.imgaug.KeypointsOnImage(*args, **kwargs)
imgaug.imgaug.MultiPolygon(*args, **kwargs)
imgaug.imgaug.Polygon(*args, **kwargs)
imgaug.imgaug.PolygonsOnImage(*args, **kwargs)
imgaug.imgaug.SegmentationMapsOnImage(*args, **kwargs)
imgaug.imgaug.angle_between_vectors(v1, v2)[source]

Calculcate the angle in radians between vectors v1 and v2.

From http://stackoverflow.com/questions/2827393/angles-between-two-n-dimensional-vectors-in-python

Parameters:
  • v1 ((N,) ndarray) – First vector.
  • v2 ((N,) ndarray) – Second vector.
Returns:

Angle in radians.

Return type:

float

Examples

>>> angle_between_vectors(np.float32([1, 0, 0]), np.float32([0, 1, 0]))
1.570796...
>>> angle_between_vectors(np.float32([1, 0, 0]), np.float32([1, 0, 0]))
0.0
>>> angle_between_vectors(np.float32([1, 0, 0]), np.float32([-1, 0, 0]))
3.141592...
imgaug.imgaug.apply_lut(image, table)[source]

Map an input image to a new one using a lookup table.

Added in 0.4.0.

Supported dtypes:

Parameters:
Returns:

Image after mapping via lookup table.

Return type:

ndarray

imgaug.imgaug.apply_lut_(image, table)[source]

Map an input image in-place to a new one using a lookup table.

Added in 0.4.0.

Supported dtypes:

  • uint8: yes; fully tested
  • uint16: no
  • uint32: no
  • uint64: no
  • int8: no
  • int16: no
  • int32: no
  • int64: no
  • float16: no
  • float32: no
  • float64: no
  • float128: no
  • bool: no
Parameters:
  • image (ndarray) – Image of dtype uint8 and shape (H,W) or (H,W,C).
  • table (ndarray or list of ndarray) – Table of dtype uint8 containing the mapping from old to new values. Either a list of C (256,) arrays or a single array of shape (256,) or (256, C) or (1, 256, C). In case of (256,) the same table is used for all channels, otherwise a channelwise table is used and C is expected to match the number of channels.
Returns:

Image after mapping via lookup table. This might be the same array instance as provided via image.

Return type:

ndarray

imgaug.imgaug.avg_pool(arr, block_size, pad_mode='reflect', pad_cval=128, preserve_dtype=True, cval=None)[source]

Resize an array using average pooling.

Defaults to pad_mode="reflect" to ensure that padded values do not affect the average.

Supported dtypes:

See pool().
Parameters:
  • arr ((H,W) ndarray or (H,W,C) ndarray) – Image-like array to pool. See pool() for details.
  • block_size (int or tuple of int or tuple of int) – Size of each block of values to pool. See pool() for details.
  • pad_mode (str, optional) – Padding mode to use if the array cannot be divided by block_size without remainder. See pad() for details.
  • pad_cval (number, optional) – Padding value. See pool() for details.
  • preserve_dtype (bool, optional) – Whether to preserve the input array dtype. See pool() for details.
  • cval (None or number, optional) – Deprecated. Old name for pad_cval.
Returns:

Array after average pooling.

Return type:

(H’,W’) ndarray or (H’,W’,C’) ndarray

imgaug.imgaug.caller_name()[source]

Return the name of the caller, e.g. a function.

Returns:The name of the caller as a string
Return type:str
imgaug.imgaug.compute_geometric_median(*args, **kwargs)
imgaug.imgaug.compute_line_intersection_point(x1, y1, x2, y2, x3, y3, x4, y4)[source]

Compute the intersection point of two lines.

Taken from https://stackoverflow.com/a/20679579 .

Parameters:
  • x1 (number) – x coordinate of the first point on line 1. (The lines extends beyond this point.)
  • y1 (number) – y coordinate of the first point on line 1. (The lines extends beyond this point.)
  • x2 (number) – x coordinate of the second point on line 1. (The lines extends beyond this point.)
  • y2 (number) – y coordinate of the second point on line 1. (The lines extends beyond this point.)
  • x3 (number) – x coordinate of the first point on line 2. (The lines extends beyond this point.)
  • y3 (number) – y coordinate of the first point on line 2. (The lines extends beyond this point.)
  • x4 (number) – x coordinate of the second point on line 2. (The lines extends beyond this point.)
  • y4 (number) – y coordinate of the second point on line 2. (The lines extends beyond this point.)
Returns:

The coordinate of the intersection point as a tuple (x, y). If the lines are parallel (no intersection point or an infinite number of them), the result is False.

Return type:

tuple of number or bool

imgaug.imgaug.compute_paddings_for_aspect_ratio(*args, **kwargs)
imgaug.imgaug.compute_paddings_to_reach_exponents_of(*args, **kwargs)
imgaug.imgaug.compute_paddings_to_reach_multiples_of(*args, **kwargs)
imgaug.imgaug.copy_random_state(random_state, force_copy=False)[source]

Deprecated. Use imgaug.random.copy_generator_unless_global_rng instead.

Copy an existing numpy (random number) generator.

Parameters:
  • random_state (numpy.random.Generator or numpy.random.RandomState) – The generator to copy.
  • force_copy (bool, optional) – If True, this function will always create a copy of every random state. If False, it will not copy numpy’s default random state, but all other random states.
Returns:

rs_copy – The copied random state.

Return type:

numpy.random.RandomState

imgaug.imgaug.current_random_state()[source]

Deprecated. Use imgaug.random.get_global_rng instead.

Get or create the current global RNG of imgaug.

Note that the first call to this function will create a global RNG.

Returns:The global RNG to use.
Return type:imgaug.random.RNG
class imgaug.imgaug.deprecated(alt_func=None, behavior='warn', removed_version=None, comment=None)[source]

Bases: object

Decorator to mark deprecated functions with warning.

Adapted from <https://github.com/scikit-image/scikit-image/blob/master/skimage/_shared/utils.py>.

Parameters:
  • alt_func (None or str, optional) – If given, tell user what function to use instead.
  • behavior ({‘warn’, ‘raise’}, optional) – Behavior during call to deprecated function: warn means that the user is warned that the function is deprecated; raise means that an error is raised.
  • removed_version (None or str, optional) – The package version in which the deprecated function will be removed.
  • comment (None or str, optional) – An optional comment that will be appended to the warning message.

Methods

__call__(self, func) Call self as a function.
imgaug.imgaug.derive_random_state(random_state)[source]

Deprecated. Use imgaug.random.derive_generator_ instead.

Derive a child numpy random generator from another one.

Parameters:random_state (numpy.random.Generator or numpy.random.RandomState) – The generator from which to derive a new child generator.
Returns:In numpy <=1.16 a RandomState, in 1.17+ a Generator. In both cases a derived child generator.
Return type:numpy.random.Generator or numpy.random.RandomState
imgaug.imgaug.derive_random_states(random_state, n=1)[source]

Deprecated. Use imgaug.random.derive_generators_ instead.

Derive child numpy random generators from another one.

Parameters:
  • random_state (numpy.random.Generator or numpy.random.RandomState) – The generator from which to derive new child generators.
  • n (int, optional) – Number of child generators to derive.
Returns:

In numpy <=1.16 a list of RandomState s, in 1.17+ a list of Generator s. In both cases lists of derived child generators.

Return type:

list of numpy.random.Generator or list of numpy.random.RandomState

imgaug.imgaug.do_assert(condition, message='Assertion failed.')[source]

Assert that a condition holds or raise an Exception otherwise.

This was added because assert statements are removed in optimized code. It replaced assert statements throughout the library, but that was reverted again for readability and performance reasons.

Parameters:
  • condition (bool) – If False, an exception is raised.
  • message (str, optional) – Error message.
imgaug.imgaug.draw_grid(images, rows=None, cols=None)[source]

Combine multiple images into a single grid-like image.

Calling this function with four images of the same shape and rows=2, cols=2 will combine the four images to a single image array of shape (2*H, 2*W, C), where H is the height of any of the images (analogous W) and C is the number of channels of any image.

Calling this function with four images of the same shape and rows=4, cols=1 is analogous to calling numpy.vstack() on the images.

Supported dtypes:

  • uint8: yes; fully tested
  • uint16: yes; fully tested
  • uint32: yes; fully tested
  • uint64: yes; fully tested
  • int8: yes; fully tested
  • int16: yes; fully tested
  • int32: yes; fully tested
  • int64: yes; fully tested
  • float16: yes; fully tested
  • float32: yes; fully tested
  • float64: yes; fully tested
  • float128: yes; fully tested
  • bool: yes; fully tested
Parameters:
  • images ((N,H,W,3) ndarray or iterable of (H,W,3) array) – The input images to convert to a grid.
  • rows (None or int, optional) – The number of rows to show in the grid. If None, it will be automatically derived.
  • cols (None or int, optional) – The number of cols to show in the grid. If None, it will be automatically derived.
Returns:

Image of the generated grid.

Return type:

(H’,W’,3) ndarray

imgaug.imgaug.draw_text(img, y, x, text, color=(0, 255, 0), size=25)[source]

Draw text on an image.

This uses by default DejaVuSans as its font, which is included in this library.

Supported dtypes:

  • uint8: yes; fully tested
  • uint16: no
  • uint32: no
  • uint64: no
  • int8: no
  • int16: no
  • int32: no
  • int64: no
  • float16: no
  • float32: yes; not tested
  • float64: no
  • float128: no
  • bool: no

TODO check if other dtypes could be enabled

Parameters:
  • img ((H,W,3) ndarray) – The image array to draw text on. Expected to be of dtype uint8 or float32 (expected value range is [0.0, 255.0]).
  • y (int) – x-coordinate of the top left corner of the text.
  • x (int) – y- coordinate of the top left corner of the text.
  • text (str) – The text to draw.
  • color (iterable of int, optional) – Color of the text to draw. For RGB-images this is expected to be an RGB color.
  • size (int, optional) – Font size of the text to draw.
Returns:

Input image with text drawn on it.

Return type:

(H,W,3) ndarray

imgaug.imgaug.dummy_random_state()[source]

Deprecated. Use imgaug.random.convert_seed_to_rng instead.

Create a dummy random state using a seed of 1.

Returns:The new random state.
Return type:imgaug.random.RNG
imgaug.imgaug.flatten(nested_iterable)[source]

Flatten arbitrarily nested lists/tuples.

Code partially taken from https://stackoverflow.com/a/10824420.

Parameters:nested_iterable – A list or tuple of arbitrarily nested values.
Yields:any – All values in nested_iterable, flattened.
imgaug.imgaug.forward_random_state(random_state)[source]

Deprecated. Use imgaug.random.advance_generator_ instead.

Advance a numpy random generator’s internal state.

Parameters:random_state (numpy.random.Generator or numpy.random.RandomState) – Generator of which to advance the internal state.
imgaug.imgaug.imresize_many_images(images, sizes=None, interpolation=None)[source]

Resize each image in a list or array to a specified size.

Supported dtypes:

  • uint8: yes; fully tested
  • uint16: yes; tested
  • uint32: no (1)
  • uint64: no (2)
  • int8: yes; tested (3)
  • int16: yes; tested
  • int32: limited; tested (4)
  • int64: no (2)
  • float16: yes; tested (5)
  • float32: yes; tested
  • float64: yes; tested
  • float128: no (1)
  • bool: yes; tested (6)
    1. rejected by cv2.imresize
    1. results too inaccurate
    1. mapped internally to int16 when interpolation!=”nearest”
    1. only supported for interpolation=”nearest”, other interpolations lead to cv2 error
    1. mapped internally to float32
    1. mapped internally to uint8
Parameters:
  • images ((N,H,W,[C]) ndarray or list of (H,W,[C]) ndarray) – Array of the images to resize. Usually recommended to be of dtype uint8.

  • sizes (float or iterable of int or iterable of float) – The new size of the images, given either as a fraction (a single float) or as a (height, width) tuple of two integers or as a (height fraction, width fraction) tuple of two floats.

  • interpolation (None or str or int, optional) – The interpolation to use during resize. If int, then expected to be one of:

    • cv2.INTER_NEAREST (nearest neighbour interpolation)
    • cv2.INTER_LINEAR (linear interpolation)
    • cv2.INTER_AREA (area interpolation)
    • cv2.INTER_CUBIC (cubic interpolation)

    If str, then expected to be one of:

    • nearest (identical to cv2.INTER_NEAREST)
    • linear (identical to cv2.INTER_LINEAR)
    • area (identical to cv2.INTER_AREA)
    • cubic (identical to cv2.INTER_CUBIC)

    If None, the interpolation will be chosen automatically. For size increases, area interpolation will be picked and for size decreases, linear interpolation will be picked.

Returns:

Array of the resized images.

Return type:

(N,H’,W’,[C]) ndarray

Examples

>>> import imgaug as ia
>>> images = np.zeros((2, 8, 16, 3), dtype=np.uint8)
>>> images_resized = ia.imresize_many_images(images, 2.0)
>>> images_resized.shape
(2, 16, 32, 3)

Convert two RGB images of height 8 and width 16 to images of height 2*8=16 and width 2*16=32.

>>> images_resized = ia.imresize_many_images(images, (2.0, 4.0))
>>> images_resized.shape
(2, 16, 64, 3)

Convert two RGB images of height 8 and width 16 to images of height 2*8=16 and width 4*16=64.

>>> images_resized = ia.imresize_many_images(images, (16, 32))
>>> images_resized.shape
(2, 16, 32, 3)

Converts two RGB images of height 8 and width 16 to images of height 16 and width 32.

imgaug.imgaug.imresize_single_image(image, sizes, interpolation=None)[source]

Resize a single image.

Supported dtypes:

Parameters:
  • image ((H,W,C) ndarray or (H,W) ndarray) – Array of the image to resize. Usually recommended to be of dtype uint8.
  • sizes (float or iterable of int or iterable of float) – See imresize_many_images().
  • interpolation (None or str or int, optional) – See imresize_many_images().
Returns:

The resized image.

Return type:

(H’,W’,C) ndarray or (H’,W’) ndarray

imgaug.imgaug.imshow(image, backend='matplotlib')[source]

Show an image in a window.

Supported dtypes:

  • uint8: yes; not tested
  • uint16: ?
  • uint32: ?
  • uint64: ?
  • int8: ?
  • int16: ?
  • int32: ?
  • int64: ?
  • float16: ?
  • float32: ?
  • float64: ?
  • float128: ?
  • bool: ?
Parameters:
  • image ((H,W,3) ndarray) – Image to show.
  • backend ({‘matplotlib’, ‘cv2’}, optional) – Library to use to show the image. May be either matplotlib or OpenCV (‘cv2’). OpenCV tends to be faster, but apparently causes more technical issues.
imgaug.imgaug.is_callable(val)[source]

Check whether a variable is a callable, e.g. a function.

Parameters:val – The variable to check.
Returns:True if the variable is a callable. Otherwise False.
Return type:bool
imgaug.imgaug.is_float_array(val)[source]

Check whether a variable is a numpy float array.

Parameters:val – The variable to check.
Returns:True if the variable is a numpy float array. Otherwise False.
Return type:bool
imgaug.imgaug.is_generator(val)[source]

Check whether a variable is a generator.

Parameters:val – The variable to check.
Returns:True is the variable is a generator. Otherwise False.
Return type:bool
imgaug.imgaug.is_integer_array(val)[source]

Check whether a variable is a numpy integer array.

Parameters:val – The variable to check.
Returns:True if the variable is a numpy integer array. Otherwise False.
Return type:bool
imgaug.imgaug.is_iterable(val)[source]

Checks whether a variable is iterable.

Parameters:val – The variable to check.
Returns:True if the variable is an iterable. Otherwise False.
Return type:bool
imgaug.imgaug.is_np_array(val)[source]

Check whether a variable is a numpy array.

Parameters:val – The variable to check.
Returns:True if the variable is a numpy array. Otherwise False.
Return type:bool
imgaug.imgaug.is_np_scalar(val)[source]

Check whether a variable is a numpy scalar.

Parameters:val – The variable to check.
Returns:True if the variable is a numpy scalar. Otherwise False.
Return type:bool
imgaug.imgaug.is_single_bool(val)[source]

Check whether a variable is a bool.

Parameters:val – The variable to check.
Returns:True if the variable is a bool. Otherwise False.
Return type:bool
imgaug.imgaug.is_single_float(val)[source]

Check whether a variable is a float.

Parameters:val – The variable to check.
Returns:True if the variable is a float. Otherwise False.
Return type:bool
imgaug.imgaug.is_single_integer(val)[source]

Check whether a variable is an int.

Parameters:val – The variable to check.
Returns:True if the variable is an int. Otherwise False.
Return type:bool
imgaug.imgaug.is_single_number(val)[source]

Check whether a variable is a number, i.e. an int or float.

Parameters:val – The variable to check.
Returns:True if the variable is a number. Otherwise False.
Return type:bool
imgaug.imgaug.is_string(val)[source]

Check whether a variable is a string.

Parameters:val – The variable to check.
Returns:True if the variable is a string. Otherwise False.
Return type:bool
imgaug.imgaug.max_pool(arr, block_size, pad_mode='edge', pad_cval=0, preserve_dtype=True, cval=None)[source]

Resize an array using max-pooling.

Defaults to pad_mode="edge" to ensure that padded values do not affect the maximum, even if the dtype was something else than uint8.

Supported dtypes:

See pool().
Parameters:
  • arr ((H,W) ndarray or (H,W,C) ndarray) – Image-like array to pool. See pool() for details.
  • block_size (int or tuple of int or tuple of int) – Size of each block of values to pool. See pool() for details.
  • pad_mode (str, optional) – Padding mode to use if the array cannot be divided by block_size without remainder. See pad() for details.
  • pad_cval (number, optional) – Padding value. See pool() for details.
  • preserve_dtype (bool, optional) – Whether to preserve the input array dtype. See pool() for details.
  • cval (None or number, optional) – Deprecated. Old name for pad_cval.
Returns:

Array after max-pooling.

Return type:

(H’,W’) ndarray or (H’,W’,C’) ndarray

imgaug.imgaug.median_pool(arr, block_size, pad_mode='reflect', pad_cval=128, preserve_dtype=True)[source]

Resize an array using median-pooling.

Defaults to pad_mode="reflect" to ensure that padded values do not affect the average.

Supported dtypes:

See pool().
Parameters:
  • arr ((H,W) ndarray or (H,W,C) ndarray) – Image-like array to pool. See pool() for details.
  • block_size (int or tuple of int or tuple of int) – Size of each block of values to pool. See pool() for details.
  • pad_mode (str, optional) – Padding mode to use if the array cannot be divided by block_size without remainder. See pad() for details.
  • pad_cval (number, optional) – Padding value. See pool() for details.
  • preserve_dtype (bool, optional) – Whether to preserve the input array dtype. See pool() for details.
Returns:

Array after min-pooling.

Return type:

(H’,W’) ndarray or (H’,W’,C’) ndarray

imgaug.imgaug.min_pool(arr, block_size, pad_mode='edge', pad_cval=255, preserve_dtype=True)[source]

Resize an array using min-pooling.

Defaults to pad_mode="edge" to ensure that padded values do not affect the minimum, even if the dtype was something else than uint8.

Supported dtypes:

See pool().
Parameters:
  • arr ((H,W) ndarray or (H,W,C) ndarray) – Image-like array to pool. See pool() for details.
  • block_size (int or tuple of int or tuple of int) – Size of each block of values to pool. See pool() for details.
  • pad_mode (str, optional) – Padding mode to use if the array cannot be divided by block_size without remainder. See pad() for details.
  • pad_cval (number, optional) – Padding value. See pool() for details.
  • preserve_dtype (bool, optional) – Whether to preserve the input array dtype. See pool() for details.
Returns:

Array after min-pooling.

Return type:

(H’,W’) ndarray or (H’,W’,C’) ndarray

imgaug.imgaug.new_random_state(seed=None, fully_random=False)[source]

Deprecated. Use imgaug.random.convert_seed_to_rng instead.

Create a new numpy random number generator.

Parameters:
  • seed (None or int, optional) – The seed value to use. If None and fully_random is False, the seed will be derived from the global RNG. If fully_random is True, the seed will be provided by the OS.
  • fully_random (bool, optional) – Whether the seed will be provided by the OS.
Returns:

In numpy <=1.16 a RandomState, in 1.17+ a Generator. Both are initialized with the provided seed.

Return type:

numpy.random.Generator or numpy.random.RandomState

imgaug.imgaug.normalize_random_state(random_state)[source]

Deprecated. Use imgaug.random.normalize_generator instead.

Normalize various inputs to a numpy random generator.

Parameters:random_state (None or int or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.bit_generator.SeedSequence or numpy.random.RandomState) – See normalize_generator().
Returns:In numpy <=1.16 a RandomState, in 1.17+ a Generator (even if the input was a RandomState).
Return type:numpy.random.Generator or numpy.random.RandomState
imgaug.imgaug.pad(*args, **kwargs)
imgaug.imgaug.pad_to_aspect_ratio(*args, **kwargs)
imgaug.imgaug.pad_to_multiples_of(*args, **kwargs)
imgaug.imgaug.pool(arr, block_size, func, pad_mode='constant', pad_cval=0, preserve_dtype=True, cval=None)[source]

Resize an array by pooling values within blocks.

Supported dtypes:

  • uint8: yes; fully tested
  • uint16: yes; tested
  • uint32: yes; tested (2)
  • uint64: no (1)
  • int8: yes; tested
  • int16: yes; tested
  • int32: yes; tested (2)
  • int64: no (1)
  • float16: yes; tested
  • float32: yes; tested
  • float64: yes; tested
  • float128: yes; tested (2)
  • bool: yes; tested
    1. results too inaccurate (at least when using np.average as func)
    1. Note that scikit-image documentation says that the wrapped pooling function converts inputs to float64. Actual tests showed no indication of that happening (at least when using preserve_dtype=True).
Parameters:
  • arr ((H,W) ndarray or (H,W,C) ndarray) – Image-like array to pool. Ideally of datatype float64.

  • block_size (int or tuple of int) –

    Spatial size of each group of values to pool, aka kernel size.

    • If a single int, then a symmetric block of that size along height and width will be used.
    • If a tuple of two values, it is assumed to be the block size along height and width of the image-like, with pooling happening per channel.
    • If a tuple of three values, it is assumed to be the block size along height, width and channels.
  • func (callable) – Function to apply to a given block in order to convert it to a single number, e.g. numpy.average(), numpy.min(), numpy.max().

  • pad_mode (str, optional) – Padding mode to use if the array cannot be divided by block_size without remainder. See pad() for details.

  • pad_cval (number, optional) – Value to use for padding if mode is constant. See numpy.pad() for details.

  • preserve_dtype (bool, optional) – Whether to convert the array back to the input datatype if it is changed away from that in the pooling process.

  • cval (None or number, optional) – Deprecated. Old name for pad_cval.

Returns:

Array after pooling.

Return type:

(H’,W’) ndarray or (H’,W’,C’) ndarray

imgaug.imgaug.quokka(size=None, extract=None)[source]

Return an image of a quokka as a numpy array.

Parameters:
  • size (None or float or tuple of int, optional) – Size of the output image. Input into imresize_single_image(). Usually expected to be a tuple (H, W), where H is the desired height and W is the width. If None, then the image will not be resized.

  • extract (None or ‘square’ or tuple of number or imgaug.augmentables.bbs.BoundingBox or imgaug.augmentables.bbs.BoundingBoxesOnImage) –

    Subarea of the quokka image to extract:

    • If None, then the whole image will be used.
    • If str square, then a squared area (x: 0 to max 643, y: 0 to max 643) will be extracted from the image.
    • If a tuple, then expected to contain four number s denoting (x1, y1, x2, y2).
    • If a BoundingBox, then that bounding box’s area will be extracted from the image.
    • If a BoundingBoxesOnImage, then expected to contain exactly one bounding box and a shape matching the full image dimensions (i.e. (643, 960, *)). Then the one bounding box will be used similar to BoundingBox above.
Returns:

The image array of dtype uint8.

Return type:

(H,W,3) ndarray

imgaug.imgaug.quokka_bounding_boxes(size=None, extract=None)[source]

Return example bounding boxes on the standard example quokke image.

Currently only a single bounding box is returned that covers the quokka.

Parameters:
  • size (None or float or tuple of int or tuple of float, optional) – Size of the output image on which the BBs are placed. If None, then the BBs are not projected to any new size (positions on the original image are used). float s lead to relative size changes, int s to absolute sizes in pixels.
  • extract (None or ‘square’ or tuple of number or imgaug.augmentables.bbs.BoundingBox or imgaug.augmentables.bbs.BoundingBoxesOnImage) – Subarea to extract from the image. See quokka().
Returns:

Example BBs on the quokka image.

Return type:

imgaug.augmentables.bbs.BoundingBoxesOnImage

imgaug.imgaug.quokka_heatmap(size=None, extract=None)[source]

Return a heatmap (here: depth map) for the standard example quokka image.

Parameters:
  • size (None or float or tuple of int, optional) – See quokka().
  • extract (None or ‘square’ or tuple of number or imgaug.augmentables.bbs.BoundingBox or imgaug.augmentables.bbs.BoundingBoxesOnImage) – See quokka().
Returns:

Depth map as an heatmap object. Values close to 0.0 denote objects that are close to the camera. Values close to 1.0 denote objects that are furthest away (among all shown objects).

Return type:

imgaug.augmentables.heatmaps.HeatmapsOnImage

imgaug.imgaug.quokka_keypoints(size=None, extract=None)[source]

Return example keypoints on the standard example quokke image.

The keypoints cover the eyes, ears, nose and paws.

Parameters:
  • size (None or float or tuple of int or tuple of float, optional) – Size of the output image on which the keypoints are placed. If None, then the keypoints are not projected to any new size (positions on the original image are used). float s lead to relative size changes, int s to absolute sizes in pixels.
  • extract (None or ‘square’ or tuple of number or imgaug.augmentables.bbs.BoundingBox or imgaug.augmentables.bbs.BoundingBoxesOnImage) – Subarea to extract from the image. See quokka().
Returns:

Example keypoints on the quokka image.

Return type:

imgaug.augmentables.kps.KeypointsOnImage

imgaug.imgaug.quokka_polygons(size=None, extract=None)[source]

Returns example polygons on the standard example quokke image.

The result contains one polygon, covering the quokka’s outline.

Parameters:
  • size (None or float or tuple of int or tuple of float, optional) – Size of the output image on which the polygons are placed. If None, then the polygons are not projected to any new size (positions on the original image are used). float s lead to relative size changes, int s to absolute sizes in pixels.
  • extract (None or ‘square’ or tuple of number or imgaug.augmentables.bbs.BoundingBox or imgaug.augmentables.bbs.BoundingBoxesOnImage) – Subarea to extract from the image. See quokka().
Returns:

Example polygons on the quokka image.

Return type:

imgaug.augmentables.polys.PolygonsOnImage

imgaug.imgaug.quokka_segmentation_map(size=None, extract=None)[source]

Return a segmentation map for the standard example quokka image.

Parameters:
  • size (None or float or tuple of int, optional) – See quokka().
  • extract (None or ‘square’ or tuple of number or imgaug.augmentables.bbs.BoundingBox or imgaug.augmentables.bbs.BoundingBoxesOnImage) – See quokka().
Returns:

Segmentation map object.

Return type:

imgaug.augmentables.segmaps.SegmentationMapsOnImage

imgaug.imgaug.quokka_square(size=None)[source]

Return an (square) image of a quokka as a numpy array.

Parameters:size (None or float or tuple of int, optional) – Size of the output image. Input into imresize_single_image(). Usually expected to be a tuple (H, W), where H is the desired height and W is the width. If None, then the image will not be resized.
Returns:The image array of dtype uint8.
Return type:(H,W,3) ndarray
imgaug.imgaug.seed(entropy=None, seedval=None)[source]

Set the seed of imgaug’s global RNG.

The global RNG controls most of the “randomness” in imgaug.

The global RNG is the default one used by all augmenters. Under special circumstances (e.g. when an augmenter is switched to deterministic mode), the global RNG is replaced with a local one. The state of that replacement may be dependent on the global RNG’s state at the time of creating the child RNG.

Note

This function is not yet marked as deprecated, but might be in the future. The preferred way to seed imgaug is via seed().

Parameters:
  • entropy (int) – The seed value to use.
  • seedval (None or int, optional) – Deprecated since 0.4.0.
imgaug.imgaug.show_grid(images, rows=None, cols=None)[source]

Combine multiple images into a single image and plot the result.

This will show a window of the results of draw_grid().

Supported dtypes:

minimum of (
draw_grid(), imshow()

)

Parameters:
  • images ((N,H,W,3) ndarray or iterable of (H,W,3) array) – See draw_grid().
  • rows (None or int, optional) – See draw_grid().
  • cols (None or int, optional) – See draw_grid().
imgaug.imgaug.warn(msg, category=<class 'UserWarning'>, stacklevel=2)[source]

Generate a a warning with stacktrace.

Parameters:
  • msg (str) – The message of the warning.
  • category (class) – The class of the warning to produce.
  • stacklevel (int, optional) – How many steps above this function to “jump” in the stacktrace when displaying file and line number of the error message. Usually 2.
imgaug.imgaug.warn_deprecated(msg, stacklevel=2)[source]

Generate a non-silent deprecation warning with stacktrace.

The used warning is imgaug.imgaug.DeprecationWarning.

Parameters:
  • msg (str) – The message of the warning.
  • stacklevel (int, optional) – How many steps above this function to “jump” in the stacktrace when displaying file and line number of the error message. Usually 2