imgaug.augmenters.geometric

Augmenters that apply affine or similar transformations.

List of augmenters:

class imgaug.augmenters.geometric.Affine(scale=None, translate_percent=None, translate_px=None, rotate=None, shear=None, order=1, cval=0, mode='constant', fit_output=False, backend='auto', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Augmenter to apply affine transformations to images.

This is mostly a wrapper around the corresponding classes and functions in OpenCV and skimage.

Affine transformations involve:

  • Translation (“move” image on the x-/y-axis)
  • Rotation
  • Scaling (“zoom” in/out)
  • Shear (move one side of the image, turning a square into a trapezoid)

All such transformations can create “new” pixels in the image without a defined content, e.g. if the image is translated to the left, pixels are created on the right. A method has to be defined to deal with these pixel values. The parameters cval and mode of this class deal with this.

Some transformations involve interpolations between several pixels of the input image to generate output pixel values. The parameter order deals with the method of interpolation used for this.

Note

While this augmenter supports segmentation maps and heatmaps that have a different size than the corresponding image, it is strongly recommended to use the same aspect ratios. E.g. for an image of shape (200, 100, 3), good segmap/heatmap array shapes also follow a 2:1 ratio and ideally are (200, 100, C), (100, 50, C) or (50, 25, C). Otherwise, transformations involving rotations or shearing will produce unaligned outputs. For performance reasons, there is no explicit validation of whether the aspect ratios are similar.

Supported dtypes:

if (backend=”skimage”, order in [0, 1]):

  • uint8: yes; tested
  • uint16: yes; tested
  • uint32: yes; tested (1)
  • uint64: no (2)
  • int8: yes; tested
  • int16: yes; tested
  • int32: yes; tested (1)
  • int64: no (2)
  • float16: yes; tested
  • float32: yes; tested
  • float64: yes; tested
  • float128: no (2)
  • bool: yes; tested
    1. scikit-image converts internally to float64, which might affect the accuracy of large integers. In tests this seemed to not be an issue.
    1. results too inaccurate

if (backend=”skimage”, order in [3, 4]):

  • uint8: yes; tested
  • uint16: yes; tested
  • uint32: yes; tested (1)
  • uint64: no (2)
  • int8: yes; tested
  • int16: yes; tested
  • int32: yes; tested (1)
  • int64: no (2)
  • float16: yes; tested
  • float32: yes; tested
  • float64: limited; tested (3)
  • float128: no (2)
  • bool: yes; tested
    1. scikit-image converts internally to float64, which might affect the accuracy of large integers. In tests this seemed to not be an issue.
    1. results too inaccurate
    1. NaN around minimum and maximum of float64 value range

if (backend=”skimage”, order=5]):

  • uint8: yes; tested
  • uint16: yes; tested
  • uint32: yes; tested (1)
  • uint64: no (2)
  • int8: yes; tested
  • int16: yes; tested
  • int32: yes; tested (1)
  • int64: no (2)
  • float16: yes; tested
  • float32: yes; tested
  • float64: limited; not tested (3)
  • float128: no (2)
  • bool: yes; tested
    1. scikit-image converts internally to float64, which might affect the accuracy of large integers. In tests this seemed to not be an issue.
    1. results too inaccurate
    1. NaN around minimum and maximum of float64 value range

if (backend=”cv2”, order=0):

  • uint8: yes; tested
  • uint16: yes; tested
  • uint32: no (1)
  • uint64: no (2)
  • int8: yes; tested
  • int16: yes; tested
  • int32: yes; tested
  • int64: no (2)
  • float16: yes; tested (3)
  • float32: yes; tested
  • float64: yes; tested
  • float128: no (1)
  • bool: yes; tested (3)
    1. rejected by cv2
    1. changed to int32 by cv2
    1. mapped internally to float32

if (backend=”cv2”, order=1):

  • uint8: yes; fully tested
  • uint16: yes; tested
  • uint32: no (1)
  • uint64: no (2)
  • int8: yes; tested (3)
  • int16: yes; tested
  • int32: no (2)
  • int64: no (2)
  • float16: yes; tested (4)
  • float32: yes; tested
  • float64: yes; tested
  • float128: no (1)
  • bool: yes; tested (4)
    1. rejected by cv2
    1. causes cv2 error: cv2.error: OpenCV(3.4.4) (...)imgwarp.cpp:1805: error: (-215:Assertion failed) ifunc != 0 in function 'remap'
    1. mapped internally to int16
    1. mapped internally to float32

if (backend=”cv2”, order=3):

  • uint8: yes; tested
  • uint16: yes; tested
  • uint32: no (1)
  • uint64: no (2)
  • int8: yes; tested (3)
  • int16: yes; tested
  • int32: no (2)
  • int64: no (2)
  • float16: yes; tested (4)
  • float32: yes; tested
  • float64: yes; tested
  • float128: no (1)
  • bool: yes; tested (4)
    1. rejected by cv2
    1. causes cv2 error: cv2.error: OpenCV(3.4.4) (...)imgwarp.cpp:1805: error: (-215:Assertion failed) ifunc != 0 in function 'remap'
    1. mapped internally to int16
    1. mapped internally to float32
Parameters:
  • scale (number or tuple of number or list of number or imgaug.parameters.StochasticParameter or dict {“x”: number/tuple/list/StochasticParameter, “y”: number/tuple/list/StochasticParameter}, optional) – Scaling factor to use, where 1.0 denotes “no change” and 0.5 is zoomed out to 50 percent of the original size.

    • If a single number, then that value will be used for all images.
    • If a tuple (a, b), then a value will be uniformly sampled per image from the interval [a, b]. That value will be used identically for both x- and y-axis.
    • If a list, then a random value will be sampled from that list per image (again, used for both x- and y-axis).
    • If a StochasticParameter, then from that parameter a value will be sampled per image (again, used for both x- and y-axis).
    • If a dictionary, then it is expected to have the keys x and/or y. Each of these keys can have the same values as described above. Using a dictionary allows to set different values for the two axis and sampling will then happen independently per axis, resulting in samples that differ between the axes.
  • translate_percent (None or number or tuple of number or list of number or imgaug.parameters.StochasticParameter or dict {“x”: number/tuple/list/StochasticParameter, “y”: number/tuple/list/StochasticParameter}, optional) – Translation as a fraction of the image height/width (x-translation, y-translation), where 0 denotes “no change” and 0.5 denotes “half of the axis size”.

    • If None then equivalent to 0.0 unless translate_px has a value other than None.
    • If a single number, then that value will be used for all images.
    • If a tuple (a, b), then a value will be uniformly sampled per image from the interval [a, b]. That sampled fraction value will be used identically for both x- and y-axis.
    • If a list, then a random value will be sampled from that list per image (again, used for both x- and y-axis).
    • If a StochasticParameter, then from that parameter a value will be sampled per image (again, used for both x- and y-axis).
    • If a dictionary, then it is expected to have the keys x and/or y. Each of these keys can have the same values as described above. Using a dictionary allows to set different values for the two axis and sampling will then happen independently per axis, resulting in samples that differ between the axes.
  • translate_px (None or int or tuple of int or list of int or imgaug.parameters.StochasticParameter or dict {“x”: int/tuple/list/StochasticParameter, “y”: int/tuple/list/StochasticParameter}, optional) –

    Translation in pixels.

    • If None then equivalent to 0 unless translate_percent has a value other than None.
    • If a single int, then that value will be used for all images.
    • If a tuple (a, b), then a value will be uniformly sampled per image from the discrete interval [a..b]. That number will be used identically for both x- and y-axis.
    • If a list, then a random value will be sampled from that list per image (again, used for both x- and y-axis).
    • If a StochasticParameter, then from that parameter a value will be sampled per image (again, used for both x- and y-axis).
    • If a dictionary, then it is expected to have the keys x and/or y. Each of these keys can have the same values as described above. Using a dictionary allows to set different values for the two axis and sampling will then happen independently per axis, resulting in samples that differ between the axes.
  • rotate (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Rotation in degrees (NOT radians), i.e. expected value range is around [-360, 360]. Rotation happens around the center of the image, not the top left corner as in some other frameworks.

    • If a number, then that value will be used for all images.
    • If a tuple (a, b), then a value will be uniformly sampled per image from the interval [a, b] and used as the rotation value.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then this parameter will be used to sample the rotation value per image.
  • shear (number or tuple of number or list of number or imgaug.parameters.StochasticParameter or dict {“x”: int/tuple/list/StochasticParameter, “y”: int/tuple/list/StochasticParameter}, optional) – Shear in degrees (NOT radians), i.e. expected value range is around [-360, 360], with reasonable values being in the range of [-45, 45].

    • If a number, then that value will be used for all images as the shear on the x-axis (no shear on the y-axis will be done).
    • If a tuple (a, b), then two value will be uniformly sampled per image from the interval [a, b] and be used as the x- and y-shear value.
    • If a list, then two random values will be sampled from that list per image, denoting x- and y-shear.
    • If a StochasticParameter, then this parameter will be used to sample the x- and y-shear values per image.
    • If a dictionary, then similar to translate_percent, i.e. one x key and/or one y key are expected, denoting the shearing on the x- and y-axis respectively. The allowed datatypes are again number, tuple (a, b), list or StochasticParameter.
  • order (int or iterable of int or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) –

    Interpolation order to use. Same meaning as in skimage:

    • 0: Nearest-neighbor
    • 1: Bi-linear (default)
    • 2: Bi-quadratic (not recommended by skimage)
    • 3: Bi-cubic
    • 4: Bi-quartic
    • 5: Bi-quintic

    Method 0 and 1 are fast, 3 is a bit slower, 4 and 5 are very slow. If the backend is cv2, the mapping to OpenCV’s interpolation modes is as follows:

    • 0 -> cv2.INTER_NEAREST
    • 1 -> cv2.INTER_LINEAR
    • 2 -> cv2.INTER_CUBIC
    • 3 -> cv2.INTER_CUBIC
    • 4 -> cv2.INTER_CUBIC

    As datatypes this parameter accepts:

    • If a single int, then that order will be used for all images.
    • If a list, then a random value will be sampled from that list per image.
    • If imgaug.ALL, then equivalant to list [0, 1, 3, 4, 5] in case of backend=skimage and otherwise [0, 1, 3].
    • If StochasticParameter, then that parameter is queried per image to sample the order value to use.
  • cval (number or tuple of number or list of number or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – The constant value to use when filling in newly created pixels. (E.g. translating by 1px to the right will create a new 1px-wide column of pixels on the left of the image). The value is only used when mode=constant. The expected value range is [0, 255] for uint8 images. It may be a float value.

    • If this is a single number, then that value will be used (e.g. 0 results in black pixels).
    • If a tuple (a, b), then three values (for three image channels) will be uniformly sampled per image from the interval [a, b].
    • If a list, then a random value will be sampled from that list per image.
    • If imgaug.ALL then equivalent to tuple ``(0, 255)`.
    • If a StochasticParameter, a new value will be sampled from the parameter per image.
  • mode (str or list of str or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – Method to use when filling in newly created pixels. Same meaning as in skimage (and numpy.pad()):

    • constant: Pads with a constant value
    • edge: Pads with the edge values of array
    • symmetric: Pads with the reflection of the vector mirrored along the edge of the array.
    • reflect: Pads with the reflection of the vector mirrored on the first and last values of the vector along each axis.
    • wrap: Pads with the wrap of the vector along the axis. The first values are used to pad the end and the end values are used to pad the beginning.

    If cv2 is chosen as the backend the mapping is as follows:

    • constant -> cv2.BORDER_CONSTANT
    • edge -> cv2.BORDER_REPLICATE
    • symmetric -> cv2.BORDER_REFLECT
    • reflect -> cv2.BORDER_REFLECT_101
    • wrap -> cv2.BORDER_WRAP

    The datatype of the parameter may be:

    • If a single string, then that mode will be used for all images.
    • If a list of strings, then a random mode will be picked from that list per image.
    • If imgaug.ALL, then a random mode from all possible modes will be picked.
    • If StochasticParameter, then the mode will be sampled from that parameter per image, i.e. it must return only the above mentioned strings.
  • fit_output (bool, optional) – Whether to modify the affine transformation so that the whole output image is always contained in the image plane (True) or accept parts of the image being outside the image plane (False). This can be thought of as first applying the affine transformation and then applying a second transformation to “zoom in” on the new image so that it fits the image plane, This is useful to avoid corners of the image being outside of the image plane after applying rotations. It will however negate translation and scaling. Note also that activating this may lead to image sizes differing from the input image sizes. To avoid this, wrap Affine in KeepSizeByResize, e.g. KeepSizeByResize(Affine(...)).

  • backend (str, optional) – Framework to use as a backend. Valid values are auto, skimage (scikit-image’s warp) and cv2 (OpenCV’s warp). If auto is used, the augmenter will automatically try to use cv2 whenever possible (order must be in [0, 1, 3]). It will silently fall back to skimage if order/dtype is not supported by cv2. cv2 is generally faster than skimage. It also supports RGB cvals, while skimage will resort to intensity cvals (i.e. 3x the same value as RGB). If cv2 is chosen and order is 2 or 4, it will automatically fall back to order 3.

  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().

  • name (None or str, optional) – See __init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.

  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.Affine(scale=2.0)

Zoom in on all images by a factor of 2.

>>> aug = iaa.Affine(translate_px=16)

Translate all images on the x- and y-axis by 16 pixels (towards the bottom right) and fill up any new pixels with zero (black values).

>>> aug = iaa.Affine(translate_percent=0.1)

Translate all images on the x- and y-axis by 10 percent of their width/height (towards the bottom right). The pixel values are computed per axis based on that axis’ size. Fill up any new pixels with zero (black values).

>>> aug = iaa.Affine(rotate=35)

Rotate all images by 35 degrees. Fill up any new pixels with zero (black values).

>>> aug = iaa.Affine(shear=15)

Shear all images by 15 degrees. Fill up any new pixels with zero (black values).

>>> aug = iaa.Affine(translate_px=(-16, 16))

Translate all images on the x- and y-axis by a random value between -16 and 16 pixels (to the bottom right) and fill up any new pixels with zero (black values). The translation value is sampled once per image and is the same for both axis.

>>> aug = iaa.Affine(translate_px={"x": (-16, 16), "y": (-4, 4)})

Translate all images on the x-axis by a random value between -16 and 16 pixels (to the right) and on the y-axis by a random value between -4 and 4 pixels to the bottom. The sampling happens independently per axis, so even if both intervals were identical, the sampled axis-wise values would likely be different. This also fills up any new pixels with zero (black values).

>>> aug = iaa.Affine(scale=2.0, order=[0, 1])

Same as in the above scale example, but uses (randomly) either nearest neighbour interpolation or linear interpolation. If order is not specified, order=1 would be used by default.

>>> aug = iaa.Affine(translate_px=16, cval=(0, 255))

Same as in the translate_px example above, but newly created pixels are now filled with a random color (sampled once per image and the same for all newly created pixels within that image).

>>> aug = iaa.Affine(translate_px=16, mode=["constant", "edge"])

Similar to the previous example, but the newly created pixels are filled with black pixels in half of all images (mode constant with default cval being 0) and in the other half of all images using edge mode, which repeats the color of the spatially closest pixel of the corresponding image edge.

>>> aug = iaa.Affine(shear={"y": (-45, 45)})

Shear images only on the y-axis. Set shear to shear=(-45, 45) to shear randomly on both axes, using for each image the same sample for both the x- and y-axis. Use shear={"x": (-45, 45), "y": (-45, 45)} to get independent samples per axis.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
get_parameters(self)[source]

See get_parameters().

class imgaug.augmenters.geometric.AffineCv2(scale=1.0, translate_percent=None, translate_px=None, rotate=0.0, shear=0.0, order=<MagicMock id='140303150344792'>, cval=0, mode=<MagicMock id='140303153818424'>, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Deprecated. Augmenter to apply affine transformations to images using cv2 (i.e. opencv) backend.

Warning

This augmenter is deprecated since 0.4.0. Use Affine(..., backend='cv2') instead.

Affine transformations involve:

  • Translation (“move” image on the x-/y-axis)
  • Rotation
  • Scaling (“zoom” in/out)
  • Shear (move one side of the image, turning a square into a trapezoid)

All such transformations can create “new” pixels in the image without a defined content, e.g. if the image is translated to the left, pixels are created on the right. A method has to be defined to deal with these pixel values. The parameters cval and mode of this class deal with this.

Some transformations involve interpolations between several pixels of the input image to generate output pixel values. The parameter order deals with the method of interpolation used for this.

Deprecated since 0.4.0.

Supported dtypes:

  • uint8: yes; fully tested
  • uint16: ?
  • uint32: ?
  • uint64: ?
  • int8: ?
  • int16: ?
  • int32: ?
  • int64: ?
  • float16: ?
  • float32: ?
  • float64: ?
  • float128: ?
  • bool: ?
Parameters:
  • scale (number or tuple of number or list of number or imgaug.parameters.StochasticParameter or dict {“x”: number/tuple/list/StochasticParameter, “y”: number/tuple/list/StochasticParameter}, optional) – Scaling factor to use, where 1.0 denotes “no change” and 0.5 is zoomed out to 50 percent of the original size.

    • If a single number, then that value will be used for all images.
    • If a tuple (a, b), then a value will be uniformly sampled per image from the interval [a, b]. That value will be used identically for both x- and y-axis.
    • If a list, then a random value will be sampled from that list per image (again, used for both x- and y-axis).
    • If a StochasticParameter, then from that parameter a value will be sampled per image (again, used for both x- and y-axis).
    • If a dictionary, then it is expected to have the keys x and/or y. Each of these keys can have the same values as described above. Using a dictionary allows to set different values for the two axis and sampling will then happen independently per axis, resulting in samples that differ between the axes.
  • translate_percent (number or tuple of number or list of number or imgaug.parameters.StochasticParameter or dict {“x”: number/tuple/list/StochasticParameter, “y”: number/tuple/list/StochasticParameter}, optional) – Translation as a fraction of the image height/width (x-translation, y-translation), where 0 denotes “no change” and 0.5 denotes “half of the axis size”.

    • If None then equivalent to 0.0 unless translate_px has a value other than None.
    • If a single number, then that value will be used for all images.
    • If a tuple (a, b), then a value will be uniformly sampled per image from the interval [a, b]. That sampled fraction value will be used identically for both x- and y-axis.
    • If a list, then a random value will be sampled from that list per image (again, used for both x- and y-axis).
    • If a StochasticParameter, then from that parameter a value will be sampled per image (again, used for both x- and y-axis).
    • If a dictionary, then it is expected to have the keys x and/or y. Each of these keys can have the same values as described above. Using a dictionary allows to set different values for the two axis and sampling will then happen independently per axis, resulting in samples that differ between the axes.
  • translate_px (int or tuple of int or list of int or imgaug.parameters.StochasticParameter or dict {“x”: int/tuple/list/StochasticParameter, “y”: int/tuple/list/StochasticParameter}, optional) –

    Translation in pixels.

    • If None then equivalent to 0 unless translate_percent has a value other than None.
    • If a single int, then that value will be used for all images.
    • If a tuple (a, b), then a value will be uniformly sampled per image from the discrete interval [a..b]. That number will be used identically for both x- and y-axis.
    • If a list, then a random value will be sampled from that list per image (again, used for both x- and y-axis).
    • If a StochasticParameter, then from that parameter a value will be sampled per image (again, used for both x- and y-axis).
    • If a dictionary, then it is expected to have the keys x and/or y. Each of these keys can have the same values as described above. Using a dictionary allows to set different values for the two axis and sampling will then happen independently per axis, resulting in samples that differ between the axes.
  • rotate (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Rotation in degrees (NOT radians), i.e. expected value range is around [-360, 360]. Rotation happens around the center of the image, not the top left corner as in some other frameworks.

    • If a number, then that value will be used for all images.
    • If a tuple (a, b), then a value will be uniformly sampled per image from the interval [a, b] and used as the rotation value.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then this parameter will be used to sample the rotation value per image.
  • shear (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Shear in degrees (NOT radians), i.e. expected value range is around [-360, 360].

    • If a number, then that value will be used for all images.
    • If a tuple (a, b), then a value will be uniformly sampled per image from the interval [a, b] and be used as the rotation value.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then this parameter will be used to sample the shear value per image.
  • order (int or list of int or str or list of str or imaug.ALL or imgaug.parameters.StochasticParameter, optional) –

    Interpolation order to use. Allowed are:

    • cv2.INTER_NEAREST (nearest-neighbor interpolation)
    • cv2.INTER_LINEAR (bilinear interpolation, used by default)
    • cv2.INTER_CUBIC (bicubic interpolation over 4x4 pixel
      neighborhood)
    • cv2.INTER_LANCZOS4
    • string nearest (same as cv2.INTER_NEAREST)
    • string linear (same as cv2.INTER_LINEAR)
    • string cubic (same as cv2.INTER_CUBIC)
    • string lanczos4 (same as cv2.INTER_LANCZOS)

    INTER_NEAREST (nearest neighbour interpolation) and INTER_NEAREST (linear interpolation) are the fastest.

    • If a single int, then that order will be used for all images.
    • If a string, then it must be one of: nearest, linear, cubic, lanczos4.
    • If an iterable of int/str, then for each image a random value will be sampled from that iterable (i.e. list of allowed order values).
    • If imgaug.ALL, then equivalant to list [cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_LANCZOS4].
    • If StochasticParameter, then that parameter is queried per image to sample the order value to use.
  • cval (number or tuple of number or list of number or imaug.ALL or imgaug.parameters.StochasticParameter, optional) – The constant value to use when filling in newly created pixels. (E.g. translating by 1px to the right will create a new 1px-wide column of pixels on the left of the image). The value is only used when mode=constant. The expected value range is [0, 255] for uint8 images. It may be a float value.

    • If this is a single number, then that value will be used (e.g. 0 results in black pixels).
    • If a tuple (a, b), then three values (for three image channels) will be uniformly sampled per image from the interval [a, b].
    • If a list, then a random value will be sampled from that list per image.
    • If imgaug.ALL then equivalent to tuple ``(0, 255)`.
    • If a StochasticParameter, a new value will be sampled from the parameter per image.
  • mode (int or str or list of str or list of int or imgaug.ALL or imgaug.parameters.StochasticParameter,) – optional Method to use when filling in newly created pixels. Same meaning as in OpenCV’s border mode. Let abcdefgh be an image’s content and | be an image boundary after which new pixels are filled in, then the valid modes and their behaviour are the following:

    • cv2.BORDER_REPLICATE: aaaaaa|abcdefgh|hhhhhhh
    • cv2.BORDER_REFLECT: fedcba|abcdefgh|hgfedcb
    • cv2.BORDER_REFLECT_101: gfedcb|abcdefgh|gfedcba
    • cv2.BORDER_WRAP: cdefgh|abcdefgh|abcdefg
    • cv2.BORDER_CONSTANT: iiiiii|abcdefgh|iiiiiii,
      where i is the defined cval.
    • replicate: Same as cv2.BORDER_REPLICATE.
    • reflect: Same as cv2.BORDER_REFLECT.
    • reflect_101: Same as cv2.BORDER_REFLECT_101.
    • wrap: Same as cv2.BORDER_WRAP.
    • constant: Same as cv2.BORDER_CONSTANT.

    The datatype of the parameter may be:

    • If a single int, then it must be one of the cv2.BORDER_* constants.
    • If a single string, then it must be one of: replicate, reflect, reflect_101, wrap, constant.
    • If a list of int/str, then per image a random mode will be picked from that list.
    • If imgaug.ALL, then a random mode from all possible modes will be picked.
    • If StochasticParameter, then the mode will be sampled from that parameter per image, i.e. it must return only the above mentioned strings.
  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().

  • name (None or str, optional) – See __init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.

  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.AffineCv2(scale=2.0)

Zoom in on all images by a factor of 2.

>>> aug = iaa.AffineCv2(translate_px=16)

Translate all images on the x- and y-axis by 16 pixels (towards the bottom right) and fill up any new pixels with zero (black values).

>>> aug = iaa.AffineCv2(translate_percent=0.1)

Translate all images on the x- and y-axis by 10 percent of their width/height (towards the bottom right). The pixel values are computed per axis based on that axis’ size. Fill up any new pixels with zero (black values).

>>> aug = iaa.AffineCv2(rotate=35)

Rotate all images by 35 degrees. Fill up any new pixels with zero (black values).

>>> aug = iaa.AffineCv2(shear=15)

Shear all images by 15 degrees. Fill up any new pixels with zero (black values).

>>> aug = iaa.AffineCv2(translate_px=(-16, 16))

Translate all images on the x- and y-axis by a random value between -16 and 16 pixels (to the bottom right) and fill up any new pixels with zero (black values). The translation value is sampled once per image and is the same for both axis.

>>> aug = iaa.AffineCv2(translate_px={"x": (-16, 16), "y": (-4, 4)})

Translate all images on the x-axis by a random value between -16 and 16 pixels (to the right) and on the y-axis by a random value between -4 and 4 pixels to the bottom. The sampling happens independently per axis, so even if both intervals were identical, the sampled axis-wise values would likely be different. This also fills up any new pixels with zero (black values).

>>> aug = iaa.AffineCv2(scale=2.0, order=[0, 1])

Same as in the above scale example, but uses (randomly) either nearest neighbour interpolation or linear interpolation. If order is not specified, order=1 would be used by default.

>>> aug = iaa.AffineCv2(translate_px=16, cval=(0, 255))

Same as in the translate_px example above, but newly created pixels are now filled with a random color (sampled once per image and the same for all newly created pixels within that image).

>>> aug = iaa.AffineCv2(translate_px=16, mode=["constant", "replicate"])

Similar to the previous example, but the newly created pixels are filled with black pixels in half of all images (mode constant with default cval being 0) and in the other half of all images using replicate mode, which repeats the color of the spatially closest pixel of the corresponding image edge.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
get_parameters(self)[source]

See get_parameters().

class imgaug.augmenters.geometric.ElasticTransformation(alpha=(0.0, 40.0), sigma=(4.0, 8.0), order=3, cval=0, mode='constant', polygon_recoverer='auto', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Transform images by moving pixels locally around using displacement fields.

The augmenter has the parameters alpha and sigma. alpha controls the strength of the displacement: higher values mean that pixels are moved further. sigma controls the smoothness of the displacement: higher values lead to smoother patterns – as if the image was below water – while low values will cause indivdual pixels to be moved very differently from their neighbours, leading to noisy and pixelated images.

A relation of 10:1 seems to be good for alpha and sigma, e.g. alpha=10 and sigma=1 or alpha=50, sigma=5. For 128x128 a setting of alpha=(0, 70.0), sigma=(4.0, 6.0) may be a good choice and will lead to a water-like effect.

Code here was initially inspired by https://gist.github.com/chsasank/4d8f68caf01f041a6453e67fb30f8f5a

For a detailed explanation, see

Simard, Steinkraus and Platt
Best Practices for Convolutional Neural Networks applied to Visual
Document Analysis
in Proc. of the International Conference on Document Analysis and
Recognition, 2003

Note

For coordinate-based inputs (keypoints, bounding boxes, polygons, …), this augmenter still has to perform an image-based augmentation, which will make it significantly slower for such inputs than other augmenters. See Performance.

Supported dtypes:

  • uint8: yes; fully tested (1)
  • uint16: yes; tested (1)
  • uint32: yes; tested (2)
  • uint64: limited; tested (3)
  • int8: yes; tested (1) (4) (5)
  • int16: yes; tested (4) (6)
  • int32: yes; tested (4) (6)
  • int64: limited; tested (3)
  • float16: yes; tested (1)
  • float32: yes; tested (1)
  • float64: yes; tested (1)
  • float128: no
  • bool: yes; tested (1) (7)
    1. Always handled by cv2.
    1. Always handled by scipy.
    1. Only supported for order != 0. Will fail for order=0.
    1. Mapped internally to float64 when order=1.
    1. Mapped internally to int16 when order>=2.
    1. Handled by cv2 when order=0 or order=1, otherwise by scipy.
    1. Mapped internally to float32.
Parameters:
  • alpha (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Strength of the distortion field. Higher values mean that pixels are moved further with respect to the distortion field’s direction. Set this to around 10 times the value of sigma for visible effects.

    • If number, then that value will be used for all images.
    • If tuple (a, b), then a random value will be uniformly sampled per image from the interval [a, b].
    • If a list, then for each image a random value will be sampled from that list.
    • If StochasticParameter, then that parameter will be used to sample a value per image.
  • sigma (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Standard deviation of the gaussian kernel used to smooth the distortion fields. Higher values (for 128x128 images around 5.0) lead to more water-like effects, while lower values (for 128x128 images around 1.0 and lower) lead to more noisy, pixelated images. Set this to around 1/10th of alpha for visible effects.

    • If number, then that value will be used for all images.
    • If tuple (a, b), then a random value will be uniformly sampled per image from the interval [a, b].
    • If a list, then for each image a random value will be sampled from that list.
    • If StochasticParameter, then that parameter will be used to sample a value per image.
  • order (int or list of int or imaug.ALL or imgaug.parameters.StochasticParameter, optional) – Interpolation order to use. Same meaning as in scipy.ndimage.map_coordinates() and may take any integer value in the range 0 to 5, where orders close to 0 are faster.

    • If a single int, then that order will be used for all images.
    • If a tuple (a, b), then a random value will be uniformly sampled per image from the interval [a, b].
    • If a list, then for each image a random value will be sampled from that list.
    • If imgaug.ALL, then equivalant to list [0, 1, 2, 3, 4, 5].
    • If StochasticParameter, then that parameter is queried per image to sample the order value to use.
  • cval (number or tuple of number or list of number or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – The constant intensity value used to fill in new pixels. This value is only used if mode is set to constant. For standard uint8 images (value range 0 to 255), this value may also should also be in the range 0 to 255. It may be a float value, even for images with integer dtypes.

    • If this is a single number, then that value will be used (e.g. 0 results in black pixels).
    • If a tuple (a, b), then a random value will be uniformly sampled per image from the interval [a, b].
    • If a list, then a random value will be picked from that list per image.
    • If imgaug.ALL, a value from the discrete range [0..255] will be sampled per image.
    • If a StochasticParameter, a new value will be sampled from the parameter per image.
  • mode (str or list of str or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – Parameter that defines the handling of newly created pixels. May take the same values as in scipy.ndimage.map_coordinates(), i.e. constant, nearest, reflect or wrap.

    • If a single string, then that mode will be used for all images.
    • If a list of strings, then per image a random mode will be picked from that list.
    • If imgaug.ALL, then a random mode from all possible modes will be picked.
    • If StochasticParameter, then the mode will be sampled from that parameter per image, i.e. it must return only the above mentioned strings.
  • polygon_recoverer (‘auto’ or None or imgaug.augmentables.polygons._ConcavePolygonRecoverer, optional) – The class to use to repair invalid polygons. If "auto", a new instance of :class`imgaug.augmentables.polygons._ConcavePolygonRecoverer` will be created. If None, no polygon recoverer will be used. If an object, then that object will be used and must provide a recover_from() method, similar to _ConcavePolygonRecoverer.

  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().

  • name (None or str, optional) – See __init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.

  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.ElasticTransformation(alpha=50.0, sigma=5.0)

Apply elastic transformations with a strength/alpha of 50.0 and smoothness of 5.0 to all images.

>>> aug = iaa.ElasticTransformation(alpha=(0.0, 70.0), sigma=5.0)

Apply elastic transformations with a strength/alpha that comes from the interval [0.0, 70.0] (randomly picked per image) and with a smoothness of 5.0.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
KEYPOINT_AUG_ALPHA_THRESH = 0.05
KEYPOINT_AUG_SIGMA_THRESH = 1.0
NB_NEIGHBOURING_KEYPOINTS = 3
NEIGHBOURING_KEYPOINTS_DISTANCE = 1.0
get_parameters(self)[source]

See get_parameters().

class imgaug.augmenters.geometric.Jigsaw(nb_rows=(3, 10), nb_cols=(3, 10), max_steps=1, allow_pad=True, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Move cells within images similar to jigsaw patterns.

Note

This augmenter will by default pad images until their height is a multiple of nb_rows. Analogous for nb_cols.

Note

This augmenter will resize heatmaps and segmentation maps to the image size, then apply similar padding as for the corresponding images and resize back to the original map size. That also means that images may change in shape (due to padding), but heatmaps/segmaps will not change. For heatmaps/segmaps, this deviates from pad augmenters that will change images and heatmaps/segmaps in corresponding ways and then keep the heatmaps/segmaps at the new size.

Warning

This augmenter currently only supports augmentation of images, heatmaps, segmentation maps and keypoints. Other augmentables, i.e. bounding boxes, polygons and line strings, will result in errors.

Added in 0.4.0.

Supported dtypes:

See apply_jigsaw().

Parameters:
  • nb_rows (int or list of int or tuple of int or imgaug.parameters.StochasticParameter, optional) –

    How many rows the jigsaw pattern should have.

    • If a single int, then that value will be used for all images.
    • If a tuple (a, b), then a random value will be uniformly sampled per image from the discrete interval [a..b].
    • If a list, then for each image a random value will be sampled from that list.
    • If StochasticParameter, then that parameter is queried per image to sample the value to use.
  • nb_cols (int or list of int or tuple of int or imgaug.parameters.StochasticParameter, optional) –

    How many cols the jigsaw pattern should have.

    • If a single int, then that value will be used for all images.
    • If a tuple (a, b), then a random value will be uniformly sampled per image from the discrete interval [a..b].
    • If a list, then for each image a random value will be sampled from that list.
    • If StochasticParameter, then that parameter is queried per image to sample the value to use.
  • max_steps (int or list of int or tuple of int or imgaug.parameters.StochasticParameter, optional) –

    How many steps each jigsaw cell may be moved.

    • If a single int, then that value will be used for all images.
    • If a tuple (a, b), then a random value will be uniformly sampled per image from the discrete interval [a..b].
    • If a list, then for each image a random value will be sampled from that list.
    • If StochasticParameter, then that parameter is queried per image to sample the value to use.
  • allow_pad (bool, optional) – Whether to allow automatically padding images until they are evenly divisible by nb_rows and nb_cols.

  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().

  • name (None or str, optional) – See __init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.

  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.Jigsaw(nb_rows=10, nb_cols=10)

Create a jigsaw augmenter that splits images into 10x10 cells and shifts them around by 0 to 2 steps (default setting).

>>> aug = iaa.Jigsaw(nb_rows=(1, 4), nb_cols=(1, 4))

Create a jigsaw augmenter that splits each image into 1 to 4 cells along each axis.

>>> aug = iaa.Jigsaw(nb_rows=10, nb_cols=10, max_steps=(1, 5))

Create a jigsaw augmenter that moves the cells in each image by a random amount between 1 and 5 times (decided per image). Some images will be barely changed, some will be fairly distorted.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
get_parameters(self) Get the parameters of this augmenter.
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
get_parameters(self)[source]

Get the parameters of this augmenter.

Returns:List of parameters of arbitrary types (usually child class of StochasticParameter, but not guaranteed to be).
Return type:list
class imgaug.augmenters.geometric.PerspectiveTransform(scale=(0.0, 0.06), cval=0, mode='constant', keep_size=True, fit_output=False, polygon_recoverer='auto', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Apply random four point perspective transformations to images.

Each of the four points is placed on the image using a random distance from its respective corner. The distance is sampled from a normal distribution. As a result, most transformations don’t change the image very much, while some “focus” on polygons far inside the image.

The results of this augmenter have some similarity with Crop.

Code partially from http://www.pyimagesearch.com/2014/08/25/4-point-opencv-getperspective-transform-example/

Supported dtypes:

if (keep_size=False):

  • uint8: yes; fully tested
  • uint16: yes; tested
  • uint32: no (1)
  • uint64: no (2)
  • int8: yes; tested (3)
  • int16: yes; tested
  • int32: no (2)
  • int64: no (2)
  • float16: yes; tested (4)
  • float32: yes; tested
  • float64: yes; tested
  • float128: no (1)
  • bool: yes; tested (4)
    1. rejected by opencv
    1. leads to opencv error: cv2.error: OpenCV(3.4.4) (...)imgwarp.cpp:1805: error: (-215:Assertion failed) ifunc != 0 in function 'remap'.
    1. mapped internally to int16.
    1. mapped intenally to float32.

if (keep_size=True):

minimum of (
imgaug.augmenters.geometric.PerspectiveTransform(keep_size=False), imresize_many_images()

)

Parameters:
  • scale (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Standard deviation of the normal distributions. These are used to sample the random distances of the subimage’s corners from the full image’s corners. The sampled values reflect percentage values (with respect to image height/width). Recommended values are in the range 0.0 to 0.1.

    • If a single number, then that value will always be used as the scale.
    • If a tuple (a, b) of numbers, then a random value will be uniformly sampled per image from the interval (a, b).
    • If a list of values, a random value will be picked from the list per image.
    • If a StochasticParameter, then that parameter will be queried to draw one value per image.
  • keep_size (bool, optional) – Whether to resize image’s back to their original size after applying the perspective transform. If set to False, the resulting images may end up having different shapes and will always be a list, never an array.

  • cval (number or tuple of number or list of number or imaug.ALL or imgaug.parameters.StochasticParameter, optional) – The constant value used to fill up pixels in the result image that didn’t exist in the input image (e.g. when translating to the left, some new pixels are created at the right). Such a fill-up with a constant value only happens, when mode is constant. The expected value range is [0, 255] for uint8 images. It may be a float value.

    • If this is a single int or float, then that value will be used (e.g. 0 results in black pixels).
    • If a tuple (a, b), then a random value is uniformly sampled per image from the interval [a, b].
    • If a list, then a random value will be sampled from that list per image.
    • If imgaug.ALL, then equivalent to tuple (0, 255).
    • If a StochasticParameter, a new value will be sampled from the parameter per image.
  • mode (int or str or list of str or list of int or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – Parameter that defines the handling of newly created pixels. Same meaning as in OpenCV’s border mode. Let abcdefgh be an image’s content and | be an image boundary, then:

    • cv2.BORDER_REPLICATE: aaaaaa|abcdefgh|hhhhhhh
    • cv2.BORDER_CONSTANT: iiiiii|abcdefgh|iiiiiii, where i is the defined cval.
    • replicate: Same as cv2.BORDER_REPLICATE.
    • constant: Same as cv2.BORDER_CONSTANT.

    The datatype of the parameter may be:

    • If a single int, then it must be one of cv2.BORDER_*.
    • If a single string, then it must be one of: replicate, reflect, reflect_101, wrap, constant.
    • If a list of ints/strings, then per image a random mode will be picked from that list.
    • If imgaug.ALL, then a random mode from all possible modes will be picked per image.
    • If StochasticParameter, then the mode will be sampled from that parameter per image, i.e. it must return only the above mentioned strings.
  • fit_output (bool, optional) – If True, the image plane size and position will be adjusted to still capture the whole image after perspective transformation. (Followed by image resizing if keep_size is set to True.) Otherwise, parts of the transformed image may be outside of the image plane. This setting should not be set to True when using large scale values as it could lead to very large images.

    Added in 0.4.0.

  • polygon_recoverer (‘auto’ or None or imgaug.augmentables.polygons._ConcavePolygonRecoverer, optional) – The class to use to repair invalid polygons. If "auto", a new instance of :class`imgaug.augmentables.polygons._ConcavePolygonRecoverer` will be created. If None, no polygon recoverer will be used. If an object, then that object will be used and must provide a recover_from() method, similar to _ConcavePolygonRecoverer.

  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().

  • name (None or str, optional) – See __init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.

  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.PerspectiveTransform(scale=(0.01, 0.15))

Apply perspective transformations using a random scale between 0.01 and 0.15 per image, where the scale is roughly a measure of how far the perspective transformation’s corner points may be distanced from the image’s corner points. Higher scale values lead to stronger “zoom-in” effects (and thereby stronger distortions).

>>> aug = iaa.PerspectiveTransform(scale=(0.01, 0.15), keep_size=False)

Same as in the previous example, but images are not resized back to the input image size after augmentation. This will lead to smaller output images.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
get_parameters(self)[source]

See get_parameters().

class imgaug.augmenters.geometric.PiecewiseAffine(scale=(0.0, 0.04), nb_rows=(2, 4), nb_cols=(2, 4), order=1, cval=0, mode='constant', absolute_scale=False, polygon_recoverer=None, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Apply affine transformations that differ between local neighbourhoods.

This augmenter places a regular grid of points on an image and randomly moves the neighbourhood of these point around via affine transformations. This leads to local distortions.

This is mostly a wrapper around scikit-image’s PiecewiseAffine. See also Affine for a similar technique.

Note

This augmenter is very slow. See Performance. Try to use ElasticTransformation instead, which is at least 10x faster.

Note

For coordinate-based inputs (keypoints, bounding boxes, polygons, …), this augmenter still has to perform an image-based augmentation, which will make it significantly slower for such inputs than other augmenters. See Performance.

Supported dtypes:

  • uint8: yes; fully tested
  • uint16: yes; tested (1)
  • uint32: yes; tested (1) (2)
  • uint64: no (3)
  • int8: yes; tested (1)
  • int16: yes; tested (1)
  • int32: yes; tested (1) (2)
  • int64: no (3)
  • float16: yes; tested (1)
  • float32: yes; tested (1)
  • float64: yes; tested (1)
  • float128: no (3)
  • bool: yes; tested (1) (4)
    1. Only tested with order set to 0.
    1. scikit-image converts internally to float64, which might introduce inaccuracies. Tests showed that these inaccuracies seemed to not be an issue.
    1. Results too inaccurate.
    1. Mapped internally to float64.
Parameters:
  • scale (float or tuple of float or imgaug.parameters.StochasticParameter, optional) – Each point on the regular grid is moved around via a normal distribution. This scale factor is equivalent to the normal distribution’s sigma. Note that the jitter (how far each point is moved in which direction) is multiplied by the height/width of the image if absolute_scale=False (default), so this scale can be the same for different sized images. Recommended values are in the range 0.01 to 0.05 (weak to strong augmentations).

    • If a single float, then that value will always be used as the scale.
    • If a tuple (a, b) of float s, then a random value will be uniformly sampled per image from the interval [a, b].
    • If a list, then a random value will be picked from that list per image.
    • If a StochasticParameter, then that parameter will be queried to draw one value per image.
  • nb_rows (int or tuple of int or imgaug.parameters.StochasticParameter, optional) – Number of rows of points that the regular grid should have. Must be at least 2. For large images, you might want to pick a higher value than 4. You might have to then adjust scale to lower values.

    • If a single int, then that value will always be used as the number of rows.
    • If a tuple (a, b), then a value from the discrete interval [a..b] will be uniformly sampled per image.
    • If a list, then a random value will be picked from that list per image.
    • If a StochasticParameter, then that parameter will be queried to draw one value per image.
  • nb_cols (int or tuple of int or imgaug.parameters.StochasticParameter, optional) – Number of columns. Analogous to nb_rows.

  • order (int or list of int or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – See __init__().

  • cval (int or float or tuple of float or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – See __init__().

  • mode (str or list of str or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – See __init__().

  • absolute_scale (bool, optional) – Take scale as an absolute value rather than a relative value.

  • polygon_recoverer (‘auto’ or None or imgaug.augmentables.polygons._ConcavePolygonRecoverer, optional) – The class to use to repair invalid polygons. If "auto", a new instance of :class`imgaug.augmentables.polygons._ConcavePolygonRecoverer` will be created. If None, no polygon recoverer will be used. If an object, then that object will be used and must provide a recover_from() method, similar to _ConcavePolygonRecoverer.

  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().

  • name (None or str, optional) – See __init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.

  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.PiecewiseAffine(scale=(0.01, 0.05))

Place a regular grid of points on each image and then randomly move each point around by 1 to 5 percent (with respect to the image height/width). Pixels between these points will be moved accordingly.

>>> aug = iaa.PiecewiseAffine(scale=(0.01, 0.05), nb_rows=8, nb_cols=8)

Same as the previous example, but uses a denser grid of 8x8 points (default is 4x4). This can be useful for large images.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
get_parameters(self)[source]

See get_parameters().

class imgaug.augmenters.geometric.Rot90(k=1, keep_size=True, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Rotate images clockwise by multiples of 90 degrees.

This could also be achieved using Affine, but Rot90 is significantly more efficient.

Supported dtypes:

if (keep_size=False):

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

if (keep_size=True):

minimum of (
imgaug.augmenters.geometric.Rot90(keep_size=False), imresize_many_images()

)

Parameters:
  • k (int or list of int or tuple of int or imaug.ALL or imgaug.parameters.StochasticParameter, optional) –

    How often to rotate clockwise by 90 degrees.

    • If a single int, then that value will be used for all images.
    • If a tuple (a, b), then a random value will be uniformly sampled per image from the discrete interval [a..b].
    • If a list, then for each image a random value will be sampled from that list.
    • If imgaug.ALL, then equivalant to list [0, 1, 2, 3].
    • If StochasticParameter, then that parameter is queried per image to sample the value to use.
  • keep_size (bool, optional) – After rotation by an odd-valued k (e.g. 1 or 3), the resulting image may have a different height/width than the original image. If this parameter is set to True, then the rotated image will be resized to the input image’s size. Note that this might also cause the augmented image to look distorted.

  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().

  • name (None or str, optional) – See __init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.

  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.Rot90(1)

Rotate all images by 90 degrees. Resize these images afterwards to keep the size that they had before augmentation. This may cause the images to look distorted.

>>> aug = iaa.Rot90([1, 3])

Rotate all images by 90 or 270 degrees. Resize these images afterwards to keep the size that they had before augmentation. This may cause the images to look distorted.

>>> aug = iaa.Rot90((1, 3))

Rotate all images by 90, 180 or 270 degrees. Resize these images afterwards to keep the size that they had before augmentation. This may cause the images to look distorted.

>>> aug = iaa.Rot90((1, 3), keep_size=False)

Rotate all images by 90, 180 or 270 degrees. Does not resize to the original image size afterwards, i.e. each image’s size may change.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
get_parameters(self)[source]

See get_parameters().

class imgaug.augmenters.geometric.Rotate(rotate=(-30, 30), order=1, cval=0, mode='constant', fit_output=False, backend='auto', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.geometric.Affine

Apply affine rotation on the y-axis to input data.

This is a wrapper around Affine. It is the same as Affine(rotate=<value>).

Added in 0.4.0.

Supported dtypes:

See Affine.

Parameters:
  • rotate (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See Affine.
  • order (int or iterable of int or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – See Affine.
  • cval (number or tuple of number or list of number or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – See Affine.
  • mode (str or list of str or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – See Affine.
  • fit_output (bool, optional) – See Affine.
  • backend (str, optional) – See Affine.
  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().
  • name (None or str, optional) – See __init__().
  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.Rotate((-45, 45))

Create an augmenter that rotates images by a random value between -45 and 45 degress.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
class imgaug.augmenters.geometric.ScaleX(scale=(0.5, 1.5), order=1, cval=0, mode='constant', fit_output=False, backend='auto', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.geometric.Affine

Apply affine scaling on the x-axis to input data.

This is a wrapper around Affine.

Added in 0.4.0.

Supported dtypes:

See Affine.

Parameters:
  • scale (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Analogous to scale in Affine, except that this scale value only affects the x-axis. No dictionary input is allowed.
  • order (int or iterable of int or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – See Affine.
  • cval (number or tuple of number or list of number or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – See Affine.
  • mode (str or list of str or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – See Affine.
  • fit_output (bool, optional) – See Affine.
  • backend (str, optional) – See Affine.
  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().
  • name (None or str, optional) – See __init__().
  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.ScaleX((0.5, 1.5))

Create an augmenter that scales images along the width to sizes between 50% and 150%. This does not change the image shape (i.e. height and width), only the pixels within the image are remapped and potentially new ones are filled in.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
class imgaug.augmenters.geometric.ScaleY(scale=(0.5, 1.5), order=1, cval=0, mode='constant', fit_output=False, backend='auto', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.geometric.Affine

Apply affine scaling on the y-axis to input data.

This is a wrapper around Affine.

Added in 0.4.0.

Supported dtypes:

See Affine.

Parameters:
  • scale (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Analogous to scale in Affine, except that this scale value only affects the y-axis. No dictionary input is allowed.
  • order (int or iterable of int or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – See Affine.
  • cval (number or tuple of number or list of number or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – See Affine.
  • mode (str or list of str or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – See Affine.
  • fit_output (bool, optional) – See Affine.
  • backend (str, optional) – See Affine.
  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().
  • name (None or str, optional) – See __init__().
  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.ScaleY((0.5, 1.5))

Create an augmenter that scales images along the height to sizes between 50% and 150%. This does not change the image shape (i.e. height and width), only the pixels within the image are remapped and potentially new ones are filled in.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
class imgaug.augmenters.geometric.ShearX(shear=(-30, 30), order=1, cval=0, mode='constant', fit_output=False, backend='auto', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.geometric.Affine

Apply affine shear on the x-axis to input data.

This is a wrapper around Affine.

Added in 0.4.0.

Supported dtypes:

See Affine.

Parameters:
  • shear (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Analogous to shear in Affine, except that this shear value only affects the x-axis. No dictionary input is allowed.
  • order (int or iterable of int or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – See Affine.
  • cval (number or tuple of number or list of number or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – See Affine.
  • mode (str or list of str or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – See Affine.
  • fit_output (bool, optional) – See Affine.
  • backend (str, optional) – See Affine.
  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().
  • name (None or str, optional) – See __init__().
  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.ShearX((-20, 20))

Create an augmenter that shears images along the x-axis by random amounts between -20 and 20 degrees.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
class imgaug.augmenters.geometric.ShearY(shear=(-30, 30), order=1, cval=0, mode='constant', fit_output=False, backend='auto', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.geometric.Affine

Apply affine shear on the y-axis to input data.

This is a wrapper around Affine.

Added in 0.4.0.

Supported dtypes:

See Affine.

Parameters:
  • shear (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Analogous to shear in Affine, except that this shear value only affects the y-axis. No dictionary input is allowed.
  • order (int or iterable of int or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – See Affine.
  • cval (number or tuple of number or list of number or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – See Affine.
  • mode (str or list of str or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – See Affine.
  • fit_output (bool, optional) – See Affine.
  • backend (str, optional) – See Affine.
  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().
  • name (None or str, optional) – See __init__().
  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.ShearY((-20, 20))

Create an augmenter that shears images along the y-axis by random amounts between -20 and 20 degrees.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
class imgaug.augmenters.geometric.TranslateX(percent=None, px=None, order=1, cval=0, mode='constant', fit_output=False, backend='auto', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.geometric.Affine

Apply affine translation on the x-axis to input data.

This is a wrapper around Affine.

Added in 0.4.0.

Supported dtypes:

See Affine.

Parameters:
  • percent (None or number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Analogous to translate_percent in Affine, except that this translation value only affects the x-axis. No dictionary input is allowed.
  • px (None or int or tuple of int or list of int or imgaug.parameters.StochasticParameter or dict {“x”: int/tuple/list/StochasticParameter, “y”: int/tuple/list/StochasticParameter}, optional) – Analogous to translate_px in Affine, except that this translation value only affects the x-axis. No dictionary input is allowed.
  • order (int or iterable of int or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – See Affine.
  • cval (number or tuple of number or list of number or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – See Affine.
  • mode (str or list of str or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – See Affine.
  • fit_output (bool, optional) – See Affine.
  • backend (str, optional) – See Affine.
  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().
  • name (None or str, optional) – See __init__().
  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.TranslateX(px=(-20, 20))

Create an augmenter that translates images along the x-axis by -20 to 20 pixels.

>>> aug = iaa.TranslateX(percent=(-0.1, 0.1))

Create an augmenter that translates images along the x-axis by -10% to 10% (relative to the x-axis size).

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
class imgaug.augmenters.geometric.TranslateY(percent=None, px=None, order=1, cval=0, mode='constant', fit_output=False, backend='auto', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.geometric.Affine

Apply affine translation on the y-axis to input data.

This is a wrapper around Affine.

Added in 0.4.0.

Supported dtypes:

See Affine.

Parameters:
  • percent (None or number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Analogous to translate_percent in Affine, except that this translation value only affects the y-axis. No dictionary input is allowed.
  • px (None or int or tuple of int or list of int or imgaug.parameters.StochasticParameter or dict {“x”: int/tuple/list/StochasticParameter, “y”: int/tuple/list/StochasticParameter}, optional) – Analogous to translate_px in Affine, except that this translation value only affects the y-axis. No dictionary input is allowed.
  • order (int or iterable of int or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – See Affine.
  • cval (number or tuple of number or list of number or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – See Affine.
  • mode (str or list of str or imgaug.ALL or imgaug.parameters.StochasticParameter, optional) – See Affine.
  • fit_output (bool, optional) – See Affine.
  • backend (str, optional) – See Affine.
  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().
  • name (None or str, optional) – See __init__().
  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.TranslateY(px=(-20, 20))

Create an augmenter that translates images along the y-axis by -20 to 20 pixels.

>>> aug = iaa.TranslateY(percent=(-0.1, 0.1))

Create an augmenter that translates images along the y-axis by -10% to 10% (relative to the y-axis size).

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
class imgaug.augmenters.geometric.WithPolarWarping(children, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Augmenter that applies other augmenters in a polar-transformed space.

This augmenter first transforms an image into a polar representation, then applies its child augmenter, then transforms back to cartesian space. The polar representation is still in the image’s input dtype (i.e. uint8 stays uint8) and can be visualized. It can be thought of as an “unrolled” version of the image, where previously circular lines appear straight. Hence, applying child augmenters in that space can lead to circular effects. E.g. replacing rectangular pixel areas in the polar representation with black pixels will lead to curved black areas in the cartesian result.

This augmenter can create new pixels in the image. It will fill these with black pixels. For segmentation maps it will fill with class id 0. For heatmaps it will fill with 0.0.

This augmenter is limited to arrays with a height and/or width of 32767 or less.

Warning

When augmenting coordinates in polar representation, it is possible that these are shifted outside of the polar image, but are inside the image plane after transforming back to cartesian representation, usually on newly created pixels (i.e. black backgrounds). These coordinates are currently not removed. It is recommended to not use very strong child transformations when also augmenting coordinate-based augmentables.

Warning

For bounding boxes, this augmenter suffers from the same problem as affine rotations applied to bounding boxes, i.e. the resulting bounding boxes can have unintuitive (seemingly wrong) appearance. This is due to coordinates being “rotated” that are inside the bounding box, but do not fall on the object and actually are background. It is recommended to use this augmenter with caution when augmenting bounding boxes.

Warning

For polygons, this augmenter should not be combined with augmenters that perform automatic polygon recovery for invalid polygons, as the polygons will frequently appear broken in polar representation and their “fixed” version will be very broken in cartesian representation. Augmenters that perform such polygon recovery are currently PerspectiveTransform, PiecewiseAffine and ElasticTransformation.

Added in 0.4.0.

Supported dtypes:

  • uint8: yes; fully tested
  • uint16: yes; tested
  • uint32: no (1)
  • uint64: no (2)
  • int8: yes; tested
  • int16: yes; tested
  • int32: yes; tested
  • int64: no (2)
  • float16: yes; tested (3)
  • float32: yes; tested
  • float64: yes; tested
  • float128: no (1)
  • bool: yes; tested (4)
  • (1) OpenCV produces error TypeError: Expected cv::UMat for argument 'src'
    1. OpenCV produces array of nothing but zeros.
    1. Mapepd to float32.
    1. Mapped to uint8.
Parameters:
  • children (imgaug.augmenters.meta.Augmenter or list of imgaug.augmenters.meta.Augmenter or None, optional) – One or more augmenters to apply to images after they were transformed to polar representation.
  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().
  • name (None or str, optional) – See __init__().
  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.
  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.WithPolarWarping(iaa.CropAndPad(percent=(-0.1, 0.1)))

Apply cropping and padding in polar representation, then warp back to cartesian representation.

>>> aug = iaa.WithPolarWarping(
>>>     iaa.Affine(
>>>         translate_percent={"x": (-0.2, 0.2), "y": (-0.2, 0.2)},
>>>         rotate=(-35, 35),
>>>         scale=(0.8, 1.2),
>>>         shear={"x": (-15, 15), "y": (-15, 15)}
>>>     )
>>> )

Apply affine transformations in polar representation.

>>> aug = iaa.WithPolarWarping(iaa.AveragePooling((2, 8)))

Apply average pooling in polar representation. This leads to circular bins.

Methods

__call__(self, *args, **kwargs) Alias for augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Deprecated.
augment_batch_(self, batch[, parents, hooks]) Augment a single batch in-place.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, parents, …]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) See get_children_lists().
get_parameters(self) See get_parameters().
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
remove_augmenters_inplace(self, func[, parents]) Deprecated.
reseed(self[, random_state, deterministic_too]) Deprecated.
seed_(self[, entropy, deterministic_too]) Seed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
warpPolarCoords(src, dsize, center, …)
get_children_lists(self)[source]

See get_children_lists().

get_parameters(self)[source]

See get_parameters().

classmethod warpPolarCoords(src, dsize, center, maxRadius, flags)[source]
imgaug.augmenters.geometric.apply_jigsaw(arr, destinations)[source]

Move cells of an image similar to a jigsaw puzzle.

This function will split the image into rows x cols cells and move each cell to the target index given in destinations.

Added in 0.4.0.

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:
  • arr (ndarray) – Array with at least two dimensions denoting height and width.
  • destinations (ndarray) – 2-dimensional array containing for each cell the id of the destination cell. The order is expected to a flattened c-order, i.e. row by row. The height of the image must be evenly divisible by the number of rows in this array. Analogous for the width and columns.
Returns:

Modified image with cells moved according to destinations.

Return type:

ndarray

imgaug.augmenters.geometric.apply_jigsaw_to_coords(coords, destinations, image_shape)[source]

Move coordinates on an image similar to a jigsaw puzzle.

This is the same as apply_jigsaw(), but moves coordinates within the cells.

Added in 0.4.0.

Parameters:
  • coords (ndarray) – (N, 2) array denoting xy-coordinates.
  • destinations (ndarray) – See apply_jigsaw().
  • image_shape (tuple of int) – (height, width, ...) shape of the image on which the coordinates are placed. Only height and width are required.
Returns:

Moved coordinates.

Return type:

ndarray

imgaug.augmenters.geometric.generate_jigsaw_destinations(nb_rows, nb_cols, max_steps, seed, connectivity=4)[source]

Generate a destination pattern for apply_jigsaw().

Added in 0.4.0.

Parameters:
  • nb_rows (int) – Number of rows to split the image into.
  • nb_cols (int) – Number of columns to split the image into.
  • max_steps (int) – Maximum number of cells that each cell may be moved.
  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState) – Seed value or alternatively RNG to use. If None the global RNG will be used.
  • connectivity (int, optional) – Whether a diagonal move of a cell counts as one step (connectivity=8) or two steps (connectivity=4).
Returns:

2-dimensional array containing for each cell the id of the target cell.

Return type:

ndarray