imgaug.augmenters.size

Augmenters that somehow change the size of the images.

List of augmenters:

class imgaug.augmenters.size.CenterCropToAspectRatio(aspect_ratio, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.size.CropToAspectRatio

Crop images equally on all sides until they reach an aspect ratio.

This is the same as CropToAspectRatio, but uses position="center" by default, which spreads the crop amounts equally over all image sides, while CropToAspectRatio by default spreads them randomly.

Added in 0.4.0.

Supported dtypes:

See CropToFixedSize.

Parameters:
  • aspect_ratio (number) – See CropToAspectRatio.__init__().
  • 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.CenterCropToAspectRatio(2.0)

Create an augmenter that crops each image until its aspect ratio is as close as possible to 2.0 (i.e. two times as many pixels along the x-axis than the y-axis). The rows to be cropped will be spread equally over the top and bottom sides (analogous for the left/right sides).

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.size.CenterCropToFixedSize(width, height, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.size.CropToFixedSize

Take a crop from the center of each image.

This is an alias for CropToFixedSize with position="center".

Note

If images already have a width and/or height below the provided width and/or height then this augmenter will do nothing for the respective axis. Hence, resulting images can be smaller than the provided axis sizes.

Added in 0.4.0.

Supported dtypes:

See CropToFixedSize.

Parameters:
  • width (int or None) – See CropToFixedSize.__init__().
  • height (int or None) – See CropToFixedSize.__init__().
  • 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
>>> crop = iaa.CenterCropToFixedSize(height=20, width=10)

Create an augmenter that takes 20x10 sized crops from the center of 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.
class imgaug.augmenters.size.CenterCropToMultiplesOf(width_multiple, height_multiple, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.size.CropToMultiplesOf

Crop images equally on all sides until H/W are multiples of given values.

This is the same as CropToMultiplesOf, but uses position="center" by default, which spreads the crop amounts equally over all image sides, while CropToMultiplesOf by default spreads them randomly.

Added in 0.4.0.

Supported dtypes:

See CropToFixedSize.

Parameters:
  • width_multiple (int or None) – See CropToMultiplesOf.__init__().
  • height_multiple (int or None) – See CropToMultiplesOf.__init__().
  • 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.CenterCropToMultiplesOf(height_multiple=10, width_multiple=6)

Create an augmenter that crops images to multiples of 10 along the y-axis (i.e. 10, 20, 30, …) and to multiples of 6 along the x-axis (i.e. 6, 12, 18, …). The rows to be cropped will be spread equally over the top and bottom sides (analogous for the left/right sides).

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.size.CenterCropToPowersOf(width_base, height_base, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.size.CropToPowersOf

Crop images equally on all sides until H/W is a power of a base.

This is the same as CropToPowersOf, but uses position="center" by default, which spreads the crop amounts equally over all image sides, while CropToPowersOf by default spreads them randomly.

Added in 0.4.0.

Supported dtypes:

See CropToFixedSize.

Parameters:
  • width_base (int or None) – See CropToPowersOf.__init__().
  • height_base (int or None) – See CropToPowersOf.__init__().
  • 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.CropToPowersOf(height_base=3, width_base=2)

Create an augmenter that crops each image down to powers of 3 along the y-axis (i.e. 3, 9, 27, …) and powers of 2 along the x-axis (i.e. 2, 4, 8, 16, …). The rows to be cropped will be spread equally over the top and bottom sides (analogous for the left/right sides).

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.size.CenterCropToSquare(seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.size.CropToSquare

Crop images equally on all sides until their height/width are identical.

In contrast to CropToSquare, this augmenter always tries to spread the columns/rows to remove equally over both sides of the respective axis to be cropped. CropToAspectRatio by default spreads the croppings randomly.

This augmenter is identical to CropToSquare with position="center", and thereby the same as CropToAspectRatio with aspect_ratio=1.0, position="center".

Images with axis sizes of 0 will not be altered.

Added in 0.4.0.

Supported dtypes:

See CropToFixedSize.

Parameters:
  • 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.CenterCropToSquare()

Create an augmenter that crops each image until its square, i.e. height and width match. The rows to be cropped will be spread equally over the top and bottom sides (analogous for the left/right sides).

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.size.CenterPadToAspectRatio(aspect_ratio, pad_mode='constant', pad_cval=0, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.size.PadToAspectRatio

Pad images equally on all sides until H/W matches an aspect ratio.

This is the same as PadToAspectRatio, but uses position="center" by default, which spreads the pad amounts equally over all image sides, while PadToAspectRatio by default spreads them randomly.

Added in 0.4.0.

Supported dtypes:

See PadToFixedSize.

Parameters:
  • aspect_ratio (number) – See PadToAspectRatio.__init__().
  • name (None or str, optional) – See __init__().
  • pad_mode (imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional) – See __init__().
  • pad_cval (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See __init__().
  • deterministic (bool, 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) – See __init__().

Examples

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

Create am augmenter that pads each image until its aspect ratio is as close as possible to 2.0 (i.e. two times as many pixels along the x-axis than the y-axis). The rows to be padded will be spread equally over the top and bottom sides (analogous for the left/right sides).

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.size.CenterPadToFixedSize(width, height, pad_mode='constant', pad_cval=0, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.size.PadToFixedSize

Pad images equally on all sides up to given minimum heights/widths.

This is an alias for PadToFixedSize with position="center". It spreads the pad amounts equally over all image sides, while PadToFixedSize by defaults spreads them randomly.

Added in 0.4.0.

Supported dtypes:

See PadToFixedSize.

Parameters:
  • width (int or None) – See PadToFixedSize.__init__().
  • height (int or None) – See PadToFixedSize.__init__().
  • pad_mode (imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional) – See PadToFixedSize.__init__().
  • pad_cval (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See PadToFixedSize.__init__().
  • 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.CenterPadToFixedSize(height=20, width=30)

Create an augmenter that pads images up to 20x30, with the padded rows added equally on the top and bottom (analogous for the padded columns).

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.size.CenterPadToMultiplesOf(width_multiple, height_multiple, pad_mode='constant', pad_cval=0, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.size.PadToMultiplesOf

Pad images equally on all sides until H/W are multiples of given values.

This is the same as PadToMultiplesOf, but uses position="center" by default, which spreads the pad amounts equally over all image sides, while PadToMultiplesOf by default spreads them randomly.

Added in 0.4.0.

Supported dtypes:

See PadToFixedSize.

Parameters:
  • width_multiple (int or None) – See PadToMultiplesOf.__init__().
  • height_multiple (int or None) – See PadToMultiplesOf.__init__().
  • pad_mode (imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional) – See __init__().
  • pad_cval (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See __init__().
  • 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.CenterPadToMultiplesOf(height_multiple=10, width_multiple=6)

Create an augmenter that pads images to multiples of 10 along the y-axis (i.e. 10, 20, 30, …) and to multiples of 6 along the x-axis (i.e. 6, 12, 18, …). The rows to be padded will be spread equally over the top and bottom sides (analogous for the left/right sides).

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.size.CenterPadToPowersOf(width_base, height_base, pad_mode='constant', pad_cval=0, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.size.PadToPowersOf

Pad images equally on all sides until H/W is a power of a base.

This is the same as PadToPowersOf, but uses position="center" by default, which spreads the pad amounts equally over all image sides, while PadToPowersOf by default spreads them randomly.

Added in 0.4.0.

Supported dtypes:

See PadToFixedSize.

Parameters:
  • width_base (int or None) – See PadToPowersOf.__init__().
  • height_base (int or None) – See PadToPowersOf.__init__().
  • pad_mode (imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional) – See __init__().
  • pad_cval (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See __init__().
  • 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.CenterPadToPowersOf(height_base=5, width_base=2)

Create an augmenter that pads each image to powers of 3 along the y-axis (i.e. 3, 9, 27, …) and powers of 2 along the x-axis (i.e. 2, 4, 8, 16, …). The rows to be padded will be spread equally over the top and bottom sides (analogous for the left/right sides).

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.size.CenterPadToSquare(pad_mode='constant', pad_cval=0, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.size.PadToSquare

Pad images equally on all sides until their height & width are identical.

This is the same as PadToSquare, but uses position="center" by default, which spreads the pad amounts equally over all image sides, while PadToSquare by default spreads them randomly. This augmenter is thus also identical to PadToAspectRatio with aspect_ratio=1.0, position="center".

Added in 0.4.0.

Supported dtypes:

See PadToFixedSize.

Parameters:
  • name (None or str, optional) – See __init__().
  • pad_mode (imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional) – See __init__().
  • pad_cval (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See __init__().
  • deterministic (bool, 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) – See __init__().

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.CenterPadToSquare()

Create an augmenter that pads each image until its square, i.e. height and width match. The rows to be padded will be spread equally over the top and bottom sides (analogous for the left/right sides).

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.size.Crop(px=None, percent=None, keep_size=True, sample_independently=True, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.size.CropAndPad

Crop images, i.e. remove columns/rows of pixels at the sides of images.

This augmenter allows to extract smaller-sized subimages from given full-sized input images. The number of pixels to cut off may be defined in absolute values or as fractions of the image sizes.

This augmenter will never crop images below a height or width of 1.

Supported dtypes:

See CropAndPad.

Parameters:
  • px (None or int or imgaug.parameters.StochasticParameter or tuple, optional) – The number of pixels to crop on each side of the image. Expected value range is [0, inf). Either this or the parameter percent may be set, not both at the same time.

    • If None, then pixel-based cropping will not be used.
    • If int, then that exact number of pixels will always be cropped.
    • If StochasticParameter, then that parameter will be used for each image. Four samples will be drawn per image (top, right, bottom, left), unless sample_independently is set to False, as then only one value will be sampled per image and used for all sides.
    • If a tuple of two int s with values a and b, then each side will be cropped by a random amount sampled uniformly per image and side from the inteval [a, b]. If however sample_independently is set to False, only one value will be sampled per image and used for all sides.
    • If a tuple of four entries, then the entries represent top, right, bottom, left. Each entry may be a single int (always crop by exactly that value), a tuple of two int s a and b (crop by an amount within [a, b]), a list of int s (crop by a random value that is contained in the list) or a StochasticParameter (sample the amount to crop from that parameter).
  • percent (None or int or float or imgaug.parameters.StochasticParameter or tuple, optional) – The number of pixels to crop on each side of the image given as a fraction of the image height/width. E.g. if this is set to 0.1, the augmenter will always crop 10% of the image’s height at both the top and the bottom (both 10% each), as well as 10% of the width at the right and left. Expected value range is [0.0, 1.0). Either this or the parameter px may be set, not both at the same time.

    • If None, then fraction-based cropping will not be used.
    • If number, then that fraction will always be cropped.
    • If StochasticParameter, then that parameter will be used for each image. Four samples will be drawn per image (top, right, bottom, left). If however sample_independently is set to False, only one value will be sampled per image and used for all sides.
    • If a tuple of two float s with values a and b, then each side will be cropped by a random fraction sampled uniformly per image and side from the interval [a, b]. If however sample_independently is set to False, only one value will be sampled per image and used for all sides.
    • If a tuple of four entries, then the entries represent top, right, bottom, left. Each entry may be a single float (always crop by exactly that fraction), a tuple of two float s a and b (crop by a fraction from [a, b]), a list of float s (crop by a random value that is contained in the list) or a StochasticParameter (sample the percentage to crop from that parameter).
  • keep_size (bool, optional) – After cropping, the result image will usually have a different height/width compared to the original input image. If this parameter is set to True, then the cropped image will be resized to the input image’s size, i.e. the augmenter’s output shape is always identical to the input shape.

  • sample_independently (bool, optional) – If False and the values for px/percent result in exactly one probability distribution for all image sides, only one single value will be sampled from that probability distribution and used for all sides. I.e. the crop amount then is the same for all sides. If True, four values will be sampled independently, one per side.

  • 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.Crop(px=(0, 10))

Crop each side by a random pixel value sampled uniformly per image and side from the discrete interval [0..10].

>>> aug = iaa.Crop(px=(0, 10), sample_independently=False)

Crop each side by a random pixel value sampled uniformly once per image from the discrete interval [0..10]. Each sampled value is used for all sides of the corresponding image.

>>> aug = iaa.Crop(px=(0, 10), keep_size=False)

Crop each side by a random pixel value sampled uniformly per image and side from the discrete interval [0..10]. Afterwards, do not resize the cropped image back to the input image’s size. This will decrease the image’s height and width by a maximum of 20 pixels.

>>> aug = iaa.Crop(px=((0, 10), (0, 5), (0, 10), (0, 5)))

Crop the top and bottom by a random pixel value sampled uniformly from the discrete interval [0..10]. Crop the left and right analogously by a random value sampled from [0..5]. Each value is always sampled independently.

>>> aug = iaa.Crop(percent=(0, 0.1))

Crop each side by a random fraction sampled uniformly from the continuous interval [0.0, 0.10]. The fraction is sampled once per image and side. E.g. a sampled fraction of 0.1 for the top side would crop by 0.1*H, where H is the height of the input image.

>>> aug = iaa.Crop(
>>>     percent=([0.05, 0.1], [0.05, 0.1], [0.05, 0.1], [0.05, 0.1]))

Crops each side by either 5% or 10%. The values are sampled once per side and image.

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.size.CropAndPad(px=None, percent=None, pad_mode='constant', pad_cval=0, keep_size=True, sample_independently=True, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Crop/pad images by pixel amounts or fractions of image sizes.

Cropping removes pixels at the sides (i.e. extracts a subimage from a given full image). Padding adds pixels to the sides (e.g. black pixels).

This augmenter will never crop images below a height or width of 1.

Note

This augmenter automatically resizes images back to their original size after it has augmented them. To deactivate this, add the parameter keep_size=False.

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.size.CropAndPad(keep_size=False), imresize_many_images()

)

Parameters:
  • px (None or int or imgaug.parameters.StochasticParameter or tuple, optional) – The number of pixels to crop (negative values) or pad (positive values) on each side of the image. Either this or the parameter percent may be set, not both at the same time.

    • If None, then pixel-based cropping/padding will not be used.
    • If int, then that exact number of pixels will always be cropped/padded.
    • If StochasticParameter, then that parameter will be used for each image. Four samples will be drawn per image (top, right, bottom, left), unless sample_independently is set to False, as then only one value will be sampled per image and used for all sides.
    • If a tuple of two int s with values a and b, then each side will be cropped/padded by a random amount sampled uniformly per image and side from the inteval [a, b]. If however sample_independently is set to False, only one value will be sampled per image and used for all sides.
    • If a tuple of four entries, then the entries represent top, right, bottom, left. Each entry may be a single int (always crop/pad by exactly that value), a tuple of two int s a and b (crop/pad by an amount within [a, b]), a list of int s (crop/pad by a random value that is contained in the list) or a StochasticParameter (sample the amount to crop/pad from that parameter).
  • percent (None or number or imgaug.parameters.StochasticParameter or tuple, optional) – The number of pixels to crop (negative values) or pad (positive values) on each side of the image given as a fraction of the image height/width. E.g. if this is set to -0.1, the augmenter will always crop away 10% of the image’s height at both the top and the bottom (both 10% each), as well as 10% of the width at the right and left. Expected value range is (-1.0, inf). Either this or the parameter px may be set, not both at the same time.

    • If None, then fraction-based cropping/padding will not be used.
    • If number, then that fraction will always be cropped/padded.
    • If StochasticParameter, then that parameter will be used for each image. Four samples will be drawn per image (top, right, bottom, left). If however sample_independently is set to False, only one value will be sampled per image and used for all sides.
    • If a tuple of two float s with values a and b, then each side will be cropped/padded by a random fraction sampled uniformly per image and side from the interval [a, b]. If however sample_independently is set to False, only one value will be sampled per image and used for all sides.
    • If a tuple of four entries, then the entries represent top, right, bottom, left. Each entry may be a single float (always crop/pad by exactly that percent value), a tuple of two float s a and b (crop/pad by a fraction from [a, b]), a list of float s (crop/pad by a random value that is contained in the list) or a StochasticParameter (sample the percentage to crop/pad from that parameter).
  • pad_mode (imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional) – Padding mode to use. The available modes match the numpy padding modes, i.e. constant, edge, linear_ramp, maximum, median, minimum, reflect, symmetric, wrap. The modes constant and linear_ramp use extra values, which are provided by pad_cval when necessary. See pad() for more details.

    • If imgaug.ALL, then a random mode from all available modes will be sampled per image.
    • If a str, it will be used as the pad mode for all images.
    • If a list of str, a random one of these will be sampled per image and used as the mode.
    • If StochasticParameter, a random mode will be sampled from this parameter per image.
  • pad_cval (number or tuple of number list of number or imgaug.parameters.StochasticParameter, optional) – The constant value to use if the pad mode is constant or the end value to use if the mode is linear_ramp. See pad() for more details.

    • If number, then that value will be used.
    • If a tuple of two number s and at least one of them is a float, then a random number will be uniformly sampled per image from the continuous interval [a, b] and used as the value. If both number s are int s, the interval is discrete.
    • If a list of number, then a random value will be chosen from the elements of the list and used as the value.
    • If StochasticParameter, a random value will be sampled from that parameter per image.
  • keep_size (bool, optional) – After cropping and padding, the result image will usually have a different height/width compared to the original input image. If this parameter is set to True, then the cropped/padded image will be resized to the input image’s size, i.e. the augmenter’s output shape is always identical to the input shape.

  • sample_independently (bool, optional) – If False and the values for px/percent result in exactly one probability distribution for all image sides, only one single value will be sampled from that probability distribution and used for all sides. I.e. the crop/pad amount then is the same for all sides. If True, four values will be sampled independently, one per side.

  • 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.CropAndPad(px=(-10, 0))

Crop each side by a random pixel value sampled uniformly per image and side from the discrete interval [-10..0].

>>> aug = iaa.CropAndPad(px=(0, 10))

Pad each side by a random pixel value sampled uniformly per image and side from the discrete interval [0..10]. The padding happens by zero-padding, i.e. it adds black pixels (default setting).

>>> aug = iaa.CropAndPad(px=(0, 10), pad_mode="edge")

Pad each side by a random pixel value sampled uniformly per image and side from the discrete interval [0..10]. The padding uses the edge mode from numpy’s pad function, i.e. the pixel colors around the image sides are repeated.

>>> aug = iaa.CropAndPad(px=(0, 10), pad_mode=["constant", "edge"])

Similar to the previous example, but uses zero-padding (constant) for half of the images and edge padding for the other half.

>>> aug = iaa.CropAndPad(px=(0, 10), pad_mode=ia.ALL, pad_cval=(0, 255))

Similar to the previous example, but uses any available padding mode. In case the padding mode ends up being constant or linear_ramp, and random intensity is uniformly sampled (once per image) from the discrete interval [0..255] and used as the intensity of the new pixels.

>>> aug = iaa.CropAndPad(px=(0, 10), sample_independently=False)

Pad each side by a random pixel value sampled uniformly once per image from the discrete interval [0..10]. Each sampled value is used for all sides of the corresponding image.

>>> aug = iaa.CropAndPad(px=(0, 10), keep_size=False)

Pad each side by a random pixel value sampled uniformly per image and side from the discrete interval [0..10]. Afterwards, do not resize the padded image back to the input image’s size. This will increase the image’s height and width by a maximum of 20 pixels.

>>> aug = iaa.CropAndPad(px=((0, 10), (0, 5), (0, 10), (0, 5)))

Pad the top and bottom by a random pixel value sampled uniformly from the discrete interval [0..10]. Pad the left and right analogously by a random value sampled from [0..5]. Each value is always sampled independently.

>>> aug = iaa.CropAndPad(percent=(0, 0.1))

Pad each side by a random fraction sampled uniformly from the continuous interval [0.0, 0.10]. The fraction is sampled once per image and side. E.g. a sampled fraction of 0.1 for the top side would pad by 0.1*H, where H is the height of the input image.

>>> aug = iaa.CropAndPad(
>>>     percent=([0.05, 0.1], [0.05, 0.1], [0.05, 0.1], [0.05, 0.1]))

Pads each side by either 5% or 10%. The values are sampled once per side and image.

>>> aug = iaa.CropAndPad(px=(-10, 10))

Sample uniformly per image and side a value v from the discrete range [-10..10]. Then either crop (negative sample) or pad (positive sample) the side by v pixels.

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.size.CropToAspectRatio(aspect_ratio, position='uniform', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.size.CropToFixedSize

Crop images until their width/height matches an aspect ratio.

This augmenter removes either rows or columns until the image reaches the desired aspect ratio given in width / height. The cropping operation is stopped once the desired aspect ratio is reached or the image side to crop reaches a size of 1. If any side of the image starts with a size of 0, the image will not be changed.

Added in 0.4.0.

Supported dtypes:

See CropToFixedSize.

Parameters:
  • aspect_ratio (number) – The desired aspect ratio, given as width/height. E.g. a ratio of 2.0 denotes an image that is twice as wide as it is high.
  • position ({‘uniform’, ‘normal’, ‘center’, ‘left-top’, ‘left-center’, ‘left-bottom’, ‘center-top’, ‘center-center’, ‘center-bottom’, ‘right-top’, ‘right-center’, ‘right-bottom’} or tuple of float or StochasticParameter or tuple of StochasticParameter, optional) – See CropToFixedSize.__init__().
  • 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.CropToAspectRatio(2.0)

Create an augmenter that crops each image until its aspect ratio is as close as possible to 2.0 (i.e. two times as many pixels along the x-axis than the y-axis). The rows to be cropped will be spread randomly over the top and bottom sides (analogous for the left/right sides).

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.size.CropToFixedSize(width, height, position='uniform', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Crop images down to a predefined maximum width and/or height.

If images are already at the maximum width/height or are smaller, they will not be cropped. Note that this also means that images will not be padded if they are below the required width/height.

The augmenter randomly decides per image how to distribute the required cropping amounts over the image axis. E.g. if 2px have to be cropped on the left or right to reach the required width, the augmenter will sometimes remove 2px from the left and 0px from the right, sometimes remove 2px from the right and 0px from the left and sometimes remove 1px from both sides. Set position to center to prevent that.

Supported dtypes:

  • 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
Parameters:
  • width (int or None) – Crop images down to this maximum width. If None, image widths will not be altered.

  • height (int or None) – Crop images down to this maximum height. If None, image heights will not be altered.

  • position ({‘uniform’, ‘normal’, ‘center’, ‘left-top’, ‘left-center’, ‘left-bottom’, ‘center-top’, ‘center-center’, ‘center-bottom’, ‘right-top’, ‘right-center’, ‘right-bottom’} or tuple of float or StochasticParameter or tuple of StochasticParameter, optional) – Sets the center point of the cropping, which determines how the required cropping amounts are distributed to each side. For a tuple (a, b), both a and b are expected to be in range [0.0, 1.0] and describe the fraction of cropping applied to the left/right (low/high values for a) and the fraction of cropping applied to the top/bottom (low/high values for b). A cropping position at (0.5, 0.5) would be the center of the image and distribute the cropping equally over all sides. A cropping position at (1.0, 0.0) would be the right-top and would apply 100% of the required cropping to the right and top sides of the image.

    • If string uniform then the share of cropping is randomly and uniformly distributed over each side. Equivalent to (Uniform(0.0, 1.0), Uniform(0.0, 1.0)).
    • If string normal then the share of cropping is distributed based on a normal distribution, leading to a focus on the center of the images. Equivalent to (Clip(Normal(0.5, 0.45/2), 0, 1), Clip(Normal(0.5, 0.45/2), 0, 1)).
    • If string center then center point of the cropping is identical to the image center. Equivalent to (0.5, 0.5).
    • If a string matching regex ^(left|center|right)-(top|center|bottom)$, e.g. left-top or center-bottom then sets the center point of the cropping to the X-Y position matching that description.
    • If a tuple of float, then expected to have exactly two entries between 0.0 and 1.0, which will always be used as the combination the position matching (x, y) form.
    • If a StochasticParameter, then that parameter will be queried once per call to augment_*() to get Nx2 center positions in (x, y) form (with N the number of images).
    • If a tuple of StochasticParameter, then expected to have exactly two entries that will both be queried per call to augment_*(), each for (N,) values, to get the center positions. First parameter is used for x coordinates, second for y coordinates.
  • 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.CropToFixedSize(width=100, height=100)

For image sides larger than 100 pixels, crop to 100 pixels. Do nothing for the other sides. The cropping amounts are randomly (and uniformly) distributed over the sides of the image.

>>> aug = iaa.CropToFixedSize(width=100, height=100, position="center")

For sides larger than 100 pixels, crop to 100 pixels. Do nothing for the other sides. The cropping amounts are always equally distributed over the left/right sides of the image (and analogously for top/bottom).

>>> aug = iaa.Sequential([
>>>     iaa.PadToFixedSize(width=100, height=100),
>>>     iaa.CropToFixedSize(width=100, height=100)
>>> ])

Pad images smaller than 100x100 until they reach 100x100. Analogously, crop images larger than 100x100 until they reach 100x100. The output images therefore have a fixed size of 100x100.

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.size.CropToMultiplesOf(width_multiple, height_multiple, position='uniform', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.size.CropToFixedSize

Crop images down until their height/width is a multiple of a value.

Note

For a given axis size A and multiple M, if A is in the interval [0 .. M], the axis will not be changed. As a result, this augmenter can still produce axis sizes that are not multiples of the given values.

Added in 0.4.0.

Supported dtypes:

See CropToFixedSize.

Parameters:
  • width_multiple (int or None) – Multiple for the width. Images will be cropped down until their width is a multiple of this value. If None, image widths will not be altered.
  • height_multiple (int or None) – Multiple for the height. Images will be cropped down until their height is a multiple of this value. If None, image heights will not be altered.
  • position ({‘uniform’, ‘normal’, ‘center’, ‘left-top’, ‘left-center’, ‘left-bottom’, ‘center-top’, ‘center-center’, ‘center-bottom’, ‘right-top’, ‘right-center’, ‘right-bottom’} or tuple of float or StochasticParameter or tuple of StochasticParameter, optional) – See CropToFixedSize.__init__().
  • 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.CropToMultiplesOf(height_multiple=10, width_multiple=6)

Create an augmenter that crops images to multiples of 10 along the y-axis (i.e. 10, 20, 30, …) and to multiples of 6 along the x-axis (i.e. 6, 12, 18, …). The rows to be cropped will be spread randomly over the top and bottom sides (analogous for the left/right sides).

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.size.CropToPowersOf(width_base, height_base, position='uniform', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.size.CropToFixedSize

Crop images until their height/width is a power of a base.

This augmenter removes pixels from an axis with size S leading to the new size S' until S' = B^E is fulfilled, where B is a provided base (e.g. 2) and E is an exponent from the discrete interval [1 .. inf).

Note

This augmenter does nothing for axes with size less than B^1 = B. If you have images with S < B^1, it is recommended to combine this augmenter with a padding augmenter that pads each axis up to B.

Added in 0.4.0.

Supported dtypes:

See CropToFixedSize.

Parameters:
  • width_base (int or None) – Base for the width. Images will be cropped down until their width fulfills width' = width_base ^ E with E being any natural number. If None, image widths will not be altered.
  • height_base (int or None) – Base for the height. Images will be cropped down until their height fulfills height' = height_base ^ E with E being any natural number. If None, image heights will not be altered.
  • position ({‘uniform’, ‘normal’, ‘center’, ‘left-top’, ‘left-center’, ‘left-bottom’, ‘center-top’, ‘center-center’, ‘center-bottom’, ‘right-top’, ‘right-center’, ‘right-bottom’} or tuple of float or StochasticParameter or tuple of StochasticParameter, optional) – See CropToFixedSize.__init__().
  • 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.CropToPowersOf(height_base=3, width_base=2)

Create an augmenter that crops each image down to powers of 3 along the y-axis (i.e. 3, 9, 27, …) and powers of 2 along the x-axis (i.e. 2, 4, 8, 16, …). The rows to be cropped will be spread randomly over the top and bottom sides (analogous for the left/right sides).

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.size.CropToSquare(position='uniform', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.size.CropToAspectRatio

Crop images until their width and height are identical.

This is identical to CropToAspectRatio with aspect_ratio=1.0.

Images with axis sizes of 0 will not be altered.

Added in 0.4.0.

Supported dtypes:

See CropToFixedSize.

Parameters:
  • position ({‘uniform’, ‘normal’, ‘center’, ‘left-top’, ‘left-center’, ‘left-bottom’, ‘center-top’, ‘center-center’, ‘center-bottom’, ‘right-top’, ‘right-center’, ‘right-bottom’} or tuple of float or StochasticParameter or tuple of StochasticParameter, optional) – See CropToFixedSize.__init__().
  • 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.CropToSquare()

Create an augmenter that crops each image until its square, i.e. height and width match. The rows to be cropped will be spread randomly over the top and bottom sides (analogous for the left/right sides).

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.size.KeepSizeByResize(children, interpolation='cubic', interpolation_heatmaps='SAME_AS_IMAGES', interpolation_segmaps='nearest', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Resize images back to their input sizes after applying child augmenters.

Combining this with e.g. a cropping augmenter as the child will lead to images being resized back to the input size after the crop operation was applied. Some augmenters have a keep_size argument that achieves the same goal (if set to True), though this augmenter offers control over the interpolation mode and which augmentables to resize (images, heatmaps, segmentation maps).

Supported dtypes:

See imresize_many_images().

Parameters:
  • children (Augmenter or list of imgaug.augmenters.meta.Augmenter or None, optional) – One or more augmenters to apply to images. These augmenters may change the image size.

  • interpolation (KeepSizeByResize.NO_RESIZE or {‘nearest’, ‘linear’, ‘area’, ‘cubic’} or {cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_AREA, cv2.INTER_CUBIC} or list of str or list of int or StochasticParameter, optional) – The interpolation mode to use when resizing images. Can take any value that imresize_single_image() accepts, e.g. cubic.

    • If this is KeepSizeByResize.NO_RESIZE then images will not be resized.
    • If this is a single str, it is expected to have one of the following values: nearest, linear, area, cubic.
    • If this is a single integer, it is expected to have a value identical to one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_AREA, cv2.INTER_CUBIC.
    • If this is a list of str or int, it is expected that each str/int is one of the above mentioned valid ones. A random one of these values will be sampled per image.
    • If this is a StochasticParameter, it will be queried once per call to _augment_images() and must return N str s or int s (matching the above mentioned ones) for N images.
  • interpolation_heatmaps (KeepSizeByResize.SAME_AS_IMAGES or KeepSizeByResize.NO_RESIZE or {‘nearest’, ‘linear’, ‘area’, ‘cubic’} or {cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_AREA, cv2.INTER_CUBIC} or list of str or list of int or StochasticParameter, optional) – The interpolation mode to use when resizing heatmaps. Meaning and valid values are similar to interpolation. This parameter may also take the value KeepSizeByResize.SAME_AS_IMAGES, which will lead to copying the interpolation modes used for the corresponding images. The value may also be returned on a per-image basis if interpolation_heatmaps is provided as a StochasticParameter or may be one possible value if it is provided as a list of str.

  • interpolation_segmaps (KeepSizeByResize.SAME_AS_IMAGES or KeepSizeByResize.NO_RESIZE or {‘nearest’, ‘linear’, ‘area’, ‘cubic’} or {cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_AREA, cv2.INTER_CUBIC} or list of str or list of int or StochasticParameter, optional) – The interpolation mode to use when resizing segmentation maps. Similar to interpolation_heatmaps. Note: For segmentation maps, only NO_RESIZE or nearest neighbour interpolation (i.e. nearest) make sense in the vast majority of all cases.

  • 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.KeepSizeByResize(
>>>     iaa.Crop((20, 40), keep_size=False)
>>> )

Apply random cropping to input images, then resize them back to their original input sizes. The resizing is done using this augmenter instead of the corresponding internal resizing operation in Crop.

>>> aug = iaa.KeepSizeByResize(
>>>     iaa.Crop((20, 40), keep_size=False),
>>>     interpolation="nearest"
>>> )

Same as in the previous example, but images are now always resized using nearest neighbour interpolation.

>>> aug = iaa.KeepSizeByResize(
>>>     iaa.Crop((20, 40), keep_size=False),
>>>     interpolation=["nearest", "cubic"],
>>>     interpolation_heatmaps=iaa.KeepSizeByResize.SAME_AS_IMAGES,
>>>     interpolation_segmaps=iaa.KeepSizeByResize.NO_RESIZE
>>> )

Similar to the previous example, but images are now sometimes resized using linear interpolation and sometimes using nearest neighbour interpolation. Heatmaps are resized using the same interpolation as was used for the corresponding image. Segmentation maps are not resized and will therefore remain at their size after cropping.

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.
NO_RESIZE = 'NO_RESIZE'
SAME_AS_IMAGES = 'SAME_AS_IMAGES'
get_children_lists(self)[source]

See get_children_lists().

get_parameters(self)[source]

See get_parameters().

class imgaug.augmenters.size.Pad(px=None, percent=None, pad_mode='constant', pad_cval=0, keep_size=True, sample_independently=True, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.size.CropAndPad

Pad images, i.e. adds columns/rows of pixels to them.

Supported dtypes:

See CropAndPad.

Parameters:
  • px (None or int or imgaug.parameters.StochasticParameter or tuple, optional) – The number of pixels to pad on each side of the image. Expected value range is [0, inf). Either this or the parameter percent may be set, not both at the same time.

    • If None, then pixel-based padding will not be used.
    • If int, then that exact number of pixels will always be padded.
    • If StochasticParameter, then that parameter will be used for each image. Four samples will be drawn per image (top, right, bottom, left), unless sample_independently is set to False, as then only one value will be sampled per image and used for all sides.
    • If a tuple of two int s with values a and b, then each side will be padded by a random amount sampled uniformly per image and side from the inteval [a, b]. If however sample_independently is set to False, only one value will be sampled per image and used for all sides.
    • If a tuple of four entries, then the entries represent top, right, bottom, left. Each entry may be a single int (always pad by exactly that value), a tuple of two int s a and b (pad by an amount within [a, b]), a list of int s (pad by a random value that is contained in the list) or a StochasticParameter (sample the amount to pad from that parameter).
  • percent (None or int or float or imgaug.parameters.StochasticParameter or tuple, optional) – The number of pixels to pad on each side of the image given as a fraction of the image height/width. E.g. if this is set to 0.1, the augmenter will always pad 10% of the image’s height at both the top and the bottom (both 10% each), as well as 10% of the width at the right and left. Expected value range is [0.0, inf). Either this or the parameter px may be set, not both at the same time.

    • If None, then fraction-based padding will not be used.
    • If number, then that fraction will always be padded.
    • If StochasticParameter, then that parameter will be used for each image. Four samples will be drawn per image (top, right, bottom, left). If however sample_independently is set to False, only one value will be sampled per image and used for all sides.
    • If a tuple of two float s with values a and b, then each side will be padded by a random fraction sampled uniformly per image and side from the interval [a, b]. If however sample_independently is set to False, only one value will be sampled per image and used for all sides.
    • If a tuple of four entries, then the entries represent top, right, bottom, left. Each entry may be a single float (always pad by exactly that fraction), a tuple of two float s a and b (pad by a fraction from [a, b]), a list of float s (pad by a random value that is contained in the list) or a StochasticParameter (sample the percentage to pad from that parameter).
  • pad_mode (imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional) – Padding mode to use. The available modes match the numpy padding modes, i.e. constant, edge, linear_ramp, maximum, median, minimum, reflect, symmetric, wrap. The modes constant and linear_ramp use extra values, which are provided by pad_cval when necessary. See pad() for more details.

    • If imgaug.ALL, then a random mode from all available modes will be sampled per image.
    • If a str, it will be used as the pad mode for all images.
    • If a list of str, a random one of these will be sampled per image and used as the mode.
    • If StochasticParameter, a random mode will be sampled from this parameter per image.
  • pad_cval (number or tuple of number list of number or imgaug.parameters.StochasticParameter, optional) – The constant value to use if the pad mode is constant or the end value to use if the mode is linear_ramp. See pad() for more details.

    • If number, then that value will be used.
    • If a tuple of two number s and at least one of them is a float, then a random number will be uniformly sampled per image from the continuous interval [a, b] and used as the value. If both number s are int s, the interval is discrete.
    • If a list of number, then a random value will be chosen from the elements of the list and used as the value.
    • If StochasticParameter, a random value will be sampled from that parameter per image.
  • keep_size (bool, optional) – After padding, the result image will usually have a different height/width compared to the original input image. If this parameter is set to True, then the padded image will be resized to the input image’s size, i.e. the augmenter’s output shape is always identical to the input shape.

  • sample_independently (bool, optional) – If False and the values for px/percent result in exactly one probability distribution for all image sides, only one single value will be sampled from that probability distribution and used for all sides. I.e. the pad amount then is the same for all sides. If True, four values will be sampled independently, one per side.

  • 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.Pad(px=(0, 10))

Pad each side by a random pixel value sampled uniformly per image and side from the discrete interval [0..10]. The padding happens by zero-padding, i.e. it adds black pixels (default setting).

>>> aug = iaa.Pad(px=(0, 10), pad_mode="edge")

Pad each side by a random pixel value sampled uniformly per image and side from the discrete interval [0..10]. The padding uses the edge mode from numpy’s pad function, i.e. the pixel colors around the image sides are repeated.

>>> aug = iaa.Pad(px=(0, 10), pad_mode=["constant", "edge"])

Similar to the previous example, but uses zero-padding (constant) for half of the images and edge padding for the other half.

>>> aug = iaa.Pad(px=(0, 10), pad_mode=ia.ALL, pad_cval=(0, 255))

Similar to the previous example, but uses any available padding mode. In case the padding mode ends up being constant or linear_ramp, and random intensity is uniformly sampled (once per image) from the discrete interval [0..255] and used as the intensity of the new pixels.

>>> aug = iaa.Pad(px=(0, 10), sample_independently=False)

Pad each side by a random pixel value sampled uniformly once per image from the discrete interval [0..10]. Each sampled value is used for all sides of the corresponding image.

>>> aug = iaa.Pad(px=(0, 10), keep_size=False)

Pad each side by a random pixel value sampled uniformly per image and side from the discrete interval [0..10]. Afterwards, do not resize the padded image back to the input image’s size. This will increase the image’s height and width by a maximum of 20 pixels.

>>> aug = iaa.Pad(px=((0, 10), (0, 5), (0, 10), (0, 5)))

Pad the top and bottom by a random pixel value sampled uniformly from the discrete interval [0..10]. Pad the left and right analogously by a random value sampled from [0..5]. Each value is always sampled independently.

>>> aug = iaa.Pad(percent=(0, 0.1))

Pad each side by a random fraction sampled uniformly from the continuous interval [0.0, 0.10]. The fraction is sampled once per image and side. E.g. a sampled fraction of 0.1 for the top side would pad by 0.1*H, where H is the height of the input image.

>>> aug = iaa.Pad(
>>>     percent=([0.05, 0.1], [0.05, 0.1], [0.05, 0.1], [0.05, 0.1]))

Pads each side by either 5% or 10%. The values are sampled once per side and image.

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.size.PadToAspectRatio(aspect_ratio, pad_mode='constant', pad_cval=0, position='uniform', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.size.PadToFixedSize

Pad images until their width/height matches an aspect ratio.

This augmenter adds either rows or columns until the image reaches the desired aspect ratio given in width / height.

Added in 0.4.0.

Supported dtypes:

See PadToFixedSize.

Parameters:
  • aspect_ratio (number) – The desired aspect ratio, given as width/height. E.g. a ratio of 2.0 denotes an image that is twice as wide as it is high.
  • position ({‘uniform’, ‘normal’, ‘center’, ‘left-top’, ‘left-center’, ‘left-bottom’, ‘center-top’, ‘center-center’, ‘center-bottom’, ‘right-top’, ‘right-center’, ‘right-bottom’} or tuple of float or StochasticParameter or tuple of StochasticParameter, optional) – See PadToFixedSize.__init__().
  • pad_mode (imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional) – See __init__().
  • pad_cval (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See __init__().
  • 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.PadToAspectRatio(2.0)

Create an augmenter that pads each image until its aspect ratio is as close as possible to 2.0 (i.e. two times as many pixels along the x-axis than the y-axis). The rows to be padded will be spread randomly over the top and bottom sides (analogous for the left/right sides).

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.size.PadToFixedSize(width, height, pad_mode='constant', pad_cval=0, position='uniform', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Pad images to a predefined minimum width and/or height.

If images are already at the minimum width/height or are larger, they will not be padded. Note that this also means that images will not be cropped if they exceed the required width/height.

The augmenter randomly decides per image how to distribute the required padding amounts over the image axis. E.g. if 2px have to be padded on the left or right to reach the required width, the augmenter will sometimes add 2px to the left and 0px to the right, sometimes add 2px to the right and 0px to the left and sometimes add 1px to both sides. Set position to center to prevent that.

Supported dtypes:

See pad().

Parameters:
  • width (int or None) – Pad images up to this minimum width. If None, image widths will not be altered.

  • height (int or None) – Pad images up to this minimum height. If None, image heights will not be altered.

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

  • pad_cval (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See __init__().

  • position ({‘uniform’, ‘normal’, ‘center’, ‘left-top’, ‘left-center’, ‘left-bottom’, ‘center-top’, ‘center-center’, ‘center-bottom’, ‘right-top’, ‘right-center’, ‘right-bottom’} or tuple of float or StochasticParameter or tuple of StochasticParameter, optional) – Sets the center point of the padding, which determines how the required padding amounts are distributed to each side. For a tuple (a, b), both a and b are expected to be in range [0.0, 1.0] and describe the fraction of padding applied to the left/right (low/high values for a) and the fraction of padding applied to the top/bottom (low/high values for b). A padding position at (0.5, 0.5) would be the center of the image and distribute the padding equally to all sides. A padding position at (0.0, 1.0) would be the left-bottom and would apply 100% of the required padding to the bottom and left sides of the image so that the bottom left corner becomes more and more the new image center (depending on how much is padded).

    • If string uniform then the share of padding is randomly and uniformly distributed over each side. Equivalent to (Uniform(0.0, 1.0), Uniform(0.0, 1.0)).
    • If string normal then the share of padding is distributed based on a normal distribution, leading to a focus on the center of the images. Equivalent to (Clip(Normal(0.5, 0.45/2), 0, 1), Clip(Normal(0.5, 0.45/2), 0, 1)).
    • If string center then center point of the padding is identical to the image center. Equivalent to (0.5, 0.5).
    • If a string matching regex ^(left|center|right)-(top|center|bottom)$, e.g. left-top or center-bottom then sets the center point of the padding to the X-Y position matching that description.
    • If a tuple of float, then expected to have exactly two entries between 0.0 and 1.0, which will always be used as the combination the position matching (x, y) form.
    • If a StochasticParameter, then that parameter will be queried once per call to augment_*() to get Nx2 center positions in (x, y) form (with N the number of images).
    • If a tuple of StochasticParameter, then expected to have exactly two entries that will both be queried per call to augment_*(), each for (N,) values, to get the center positions. First parameter is used for x coordinates, second for y coordinates.
  • 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.PadToFixedSize(width=100, height=100)

For image sides smaller than 100 pixels, pad to 100 pixels. Do nothing for the other edges. The padding is randomly (uniformly) distributed over the sides, so that e.g. sometimes most of the required padding is applied to the left, sometimes to the right (analogous top/bottom).

>>> aug = iaa.PadToFixedSize(width=100, height=100, position="center")

For image sides smaller than 100 pixels, pad to 100 pixels. Do nothing for the other image sides. The padding is always equally distributed over the left/right and top/bottom sides.

>>> aug = iaa.PadToFixedSize(width=100, height=100, pad_mode=ia.ALL)

For image sides smaller than 100 pixels, pad to 100 pixels and use any possible padding mode for that. Do nothing for the other image sides. The padding is always equally distributed over the left/right and top/bottom sides.

>>> aug = iaa.Sequential([
>>>     iaa.PadToFixedSize(width=100, height=100),
>>>     iaa.CropToFixedSize(width=100, height=100)
>>> ])

Pad images smaller than 100x100 until they reach 100x100. Analogously, crop images larger than 100x100 until they reach 100x100. The output images therefore have a fixed size of 100x100.

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.size.PadToMultiplesOf(width_multiple, height_multiple, pad_mode='constant', pad_cval=0, position='uniform', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.size.PadToFixedSize

Pad images until their height/width is a multiple of a value.

Added in 0.4.0.

Supported dtypes:

See PadToFixedSize.

Parameters:
  • width_multiple (int or None) – Multiple for the width. Images will be padded until their width is a multiple of this value. If None, image widths will not be altered.
  • height_multiple (int or None) – Multiple for the height. Images will be padded until their height is a multiple of this value. If None, image heights will not be altered.
  • pad_mode (imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional) – See __init__().
  • pad_cval (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See __init__().
  • position ({‘uniform’, ‘normal’, ‘center’, ‘left-top’, ‘left-center’, ‘left-bottom’, ‘center-top’, ‘center-center’, ‘center-bottom’, ‘right-top’, ‘right-center’, ‘right-bottom’} or tuple of float or StochasticParameter or tuple of StochasticParameter, optional) – See PadToFixedSize.__init__().
  • 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.PadToMultiplesOf(height_multiple=10, width_multiple=6)

Create an augmenter that pads images to multiples of 10 along the y-axis (i.e. 10, 20, 30, …) and to multiples of 6 along the x-axis (i.e. 6, 12, 18, …). The rows to be padded will be spread randomly over the top and bottom sides (analogous for the left/right sides).

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.size.PadToPowersOf(width_base, height_base, pad_mode='constant', pad_cval=0, position='uniform', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.size.PadToFixedSize

Pad images until their height/width is a power of a base.

This augmenter adds pixels to an axis with size S leading to the new size S' until S' = B^E is fulfilled, where B is a provided base (e.g. 2) and E is an exponent from the discrete interval [1 .. inf).

Added in 0.4.0.

Supported dtypes:

See PadToFixedSize.

Parameters:
  • width_base (int or None) – Base for the width. Images will be padded down until their width fulfills width' = width_base ^ E with E being any natural number. If None, image widths will not be altered.
  • height_base (int or None) – Base for the height. Images will be padded until their height fulfills height' = height_base ^ E with E being any natural number. If None, image heights will not be altered.
  • pad_mode (imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional) – See __init__().
  • pad_cval (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See __init__().
  • position ({‘uniform’, ‘normal’, ‘center’, ‘left-top’, ‘left-center’, ‘left-bottom’, ‘center-top’, ‘center-center’, ‘center-bottom’, ‘right-top’, ‘right-center’, ‘right-bottom’} or tuple of float or StochasticParameter or tuple of StochasticParameter, optional) – See PadToFixedSize.__init__().
  • 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.PadToPowersOf(height_base=3, width_base=2)

Create an augmenter that pads each image to powers of 3 along the y-axis (i.e. 3, 9, 27, …) and powers of 2 along the x-axis (i.e. 2, 4, 8, 16, …). The rows to be padded will be spread randomly over the top and bottom sides (analogous for the left/right sides).

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.size.PadToSquare(pad_mode='constant', pad_cval=0, position='uniform', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.size.PadToAspectRatio

Pad images until their height and width are identical.

This augmenter is identical to PadToAspectRatio with aspect_ratio=1.0.

Added in 0.4.0.

Supported dtypes:

See PadToFixedSize.

Parameters:
  • position ({‘uniform’, ‘normal’, ‘center’, ‘left-top’, ‘left-center’, ‘left-bottom’, ‘center-top’, ‘center-center’, ‘center-bottom’, ‘right-top’, ‘right-center’, ‘right-bottom’} or tuple of float or StochasticParameter or tuple of StochasticParameter, optional) – See PadToFixedSize.__init__().
  • pad_mode (imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional) – See __init__().
  • pad_cval (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See __init__().
  • 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.PadToSquare()

Create an augmenter that pads each image until its square, i.e. height and width match. The rows to be padded will be spread randomly over the top and bottom sides (analogous for the left/right sides).

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.size.Resize(size, interpolation='cubic', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Augmenter that resizes images to specified heights and widths.

Supported dtypes:

See imresize_many_images().

Parameters:
  • size (‘keep’ or int or float or tuple of int or tuple of float or list of int or list of float or imgaug.parameters.StochasticParameter or dict) –

    The new size of the images.

    • If this has the string value keep, the original height and width values will be kept (image is not resized).
    • If this is an int, this value will always be used as the new height and width of the images.
    • If this is a float v, then per image the image’s height H and width W will be changed to H*v and W*v.
    • If this is a tuple, it is expected to have two entries (a, b). If at least one of these are float s, a value will be sampled from range [a, b] and used as the float value to resize the image (see above). If both are int s, a value will be sampled from the discrete range [a..b] and used as the integer value to resize the image (see above).
    • If this is a list, a random value from the list will be picked to resize the image. All values in the list must be int s or float s (no mixture is possible).
    • If this is a StochasticParameter, then this parameter will first be queried once per image. The resulting value will be used for both height and width.
    • If this is a dict, it may contain the keys height and width or the keys shorter-side and longer-side. Each key may have the same datatypes as above and describes the scaling on x and y-axis or the shorter and longer axis, respectively. Both axis are sampled independently. Additionally, one of the keys may have the value keep-aspect-ratio, which means that the respective side of the image will be resized so that the original aspect ratio is kept. This is useful when only resizing one image size by a pixel value (e.g. resize images to a height of 64 pixels and resize the width so that the overall aspect ratio is maintained).
  • interpolation (imgaug.ALL or int or str or list of int or list of str or imgaug.parameters.StochasticParameter, optional) –

    Interpolation to use.

    • If imgaug.ALL, then a random interpolation from nearest, linear, area or cubic will be picked (per image).
    • If int, then this interpolation will always be used. Expected to be any of the following: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_AREA, cv2.INTER_CUBIC
    • If string, then this interpolation will always be used. Expected to be any of the following: nearest, linear, area, cubic
    • If list of int / str, then a random one of the values will be picked per image as the interpolation.
    • If a StochasticParameter, then this parameter will be queried per image and is expected to return an int or str.
  • 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.Resize(32)

Resize all images to 32x32 pixels.

>>> aug = iaa.Resize(0.5)

Resize all images to 50 percent of their original size.

>>> aug = iaa.Resize((16, 22))

Resize all images to a random height and width within the discrete interval [16..22] (uniformly sampled per image).

>>> aug = iaa.Resize((0.5, 0.75))

Resize all any input image so that its height (H) and width (W) become H*v and W*v, where v is uniformly sampled from the interval [0.5, 0.75].

>>> aug = iaa.Resize([16, 32, 64])

Resize all images either to 16x16, 32x32 or 64x64 pixels.

>>> aug = iaa.Resize({"height": 32})

Resize all images to a height of 32 pixels and keeps the original width.

>>> aug = iaa.Resize({"height": 32, "width": 48})

Resize all images to a height of 32 pixels and a width of 48.

>>> aug = iaa.Resize({"height": 32, "width": "keep-aspect-ratio"})

Resize all images to a height of 32 pixels and resizes the x-axis (width) so that the aspect ratio is maintained.

>>> aug = iaa.Resize(
>>>     {"shorter-side": 224, "longer-side": "keep-aspect-ratio"})

Resize all images to a height/width of 224 pixels, depending on which axis is shorter and resize the other axis so that the aspect ratio is maintained.

>>> aug = iaa.Resize({"height": (0.5, 0.75), "width": [16, 32, 64]})

Resize all images to a height of H*v, where H is the original height and v is a random value sampled from the interval [0.5, 0.75]. The width/x-axis of each image is resized to either 16 or 32 or 64 pixels.

>>> aug = iaa.Resize(32, interpolation=["linear", "cubic"])

Resize all images to 32x32 pixels. Randomly use either linear or cubic interpolation.

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().

imgaug.augmenters.size.Scale(*args, **kwargs)[source]

Deprecated. Use Resize instead. Resize has the exactly same interface as Scale.

Augmenter that resizes images to specified heights and widths.

imgaug.augmenters.size.compute_croppings_to_reach_aspect_ratio(arr, aspect_ratio)[source]

Compute crop amounts required to fulfill an aspect ratio.

“Crop amounts” here denotes the number of pixels that have to be removed from each side to fulfill the desired constraint.

The aspect ratio is given as ratio = width / height. Depending on which dimension is smaller (height or width), only the corresponding sides (top/bottom or left/right) will be cropped.

The axis-wise padding amounts are always distributed equally over the sides of the respective axis (i.e. left and right, top and bottom). For odd pixel amounts, one pixel will be left over after the equal distribution and could be added to either side of the axis. This function will always add such a left over pixel to the bottom (y-axis) or right (x-axis) side.

If an aspect ratio cannot be reached exactly, this function will return rather one pixel too few than one pixel too many.

Added in 0.4.0.

Parameters:
  • arr ((H,W) ndarray or (H,W,C) ndarray or tuple of int) – Image-like array or shape tuple for which to compute crop amounts.
  • aspect_ratio (float) – Target aspect ratio, given as width/height. E.g. 2.0 denotes the image having twice as much width as height.
Returns:

Required cropping amounts to reach the target aspect ratio, given as a tuple of the form (top, right, bottom, left).

Return type:

tuple of int

imgaug.augmenters.size.compute_croppings_to_reach_multiples_of(arr, height_multiple, width_multiple)[source]

Compute croppings to reach multiples of given heights/widths.

See compute_paddings_for_aspect_ratio() for an explanation of how the required cropping amounts are distributed per image axis.

Added in 0.4.0.

Parameters:
  • arr ((H,W) ndarray or (H,W,C) ndarray or tuple of int) – Image-like array or shape tuple for which to compute crop amounts.
  • height_multiple (None or int) – The desired multiple of the height. The computed croppings will reflect a crop operation that decreases the y axis size until it is a multiple of this value.
  • width_multiple (None or int) – The desired multiple of the width. The computed croppings amount will reflect a crop operation that decreases the x axis size until it is a multiple of this value.
Returns:

Required cropping amounts to reach multiples of the provided values, given as a tuple of the form (top, right, bottom, left).

Return type:

tuple of int

imgaug.augmenters.size.compute_croppings_to_reach_powers_of(arr, height_base, width_base, allow_zero_exponent=False)[source]

Compute croppings to reach powers of given base values.

For given axis size S, cropped size S' (S' <= S) and base B this function computes croppings that fulfill S' = B^E, where E is any exponent from the discrete interval [0 .. inf).

See compute_paddings_for_aspect_ratio() for an explanation of how the required cropping amounts are distributed per image axis.

Note

For axes where S == 0, this function alwayws returns zeros as croppings.

For axes where 1 <= S < B see parameter allow_zero_exponent.

Added in 0.4.0.

Parameters:
  • arr ((H,W) ndarray or (H,W,C) ndarray or tuple of int) – Image-like array or shape tuple for which to compute crop amounts.
  • height_base (None or int) – The desired base of the height.
  • width_base (None or int) – The desired base of the width.
  • allow_zero_exponent (bool) – Whether E=0 in S'=B^E is a valid value. If True, axes with size 1 <= S < B will be cropped to size B^0=1. If False, axes with sizes S < B will not be changed.
Returns:

Required cropping amounts to fulfill S' = B^E given as a tuple of the form (top, right, bottom, left).

Return type:

tuple of int

imgaug.augmenters.size.compute_paddings_to_reach_aspect_ratio(arr, aspect_ratio)[source]

Compute pad amounts required to fulfill an aspect ratio.

“Pad amounts” here denotes the number of pixels that have to be added to each side to fulfill the desired constraint.

The aspect ratio is given as ratio = width / height. Depending on which dimension is smaller (height or width), only the corresponding sides (top/bottom or left/right) will be padded.

The axis-wise padding amounts are always distributed equally over the sides of the respective axis (i.e. left and right, top and bottom). For odd pixel amounts, one pixel will be left over after the equal distribution and could be added to either side of the axis. This function will always add such a left over pixel to the bottom (y-axis) or right (x-axis) side.

Added in 0.4.0. (Previously named imgaug.imgaug.compute_paddings_to_reach_aspect_ratio().)

Parameters:
  • arr ((H,W) ndarray or (H,W,C) ndarray or tuple of int) – Image-like array or shape tuple for which to compute pad amounts.
  • aspect_ratio (float) – Target aspect ratio, given as width/height. E.g. 2.0 denotes the image having twice as much width as height.
Returns:

Required padding amounts to reach the target aspect ratio, given as a tuple of the form (top, right, bottom, left).

Return type:

tuple of int

imgaug.augmenters.size.compute_paddings_to_reach_multiples_of(arr, height_multiple, width_multiple)[source]

Compute pad amounts until img height/width are multiples of given values.

See compute_paddings_for_aspect_ratio() for an explanation of how the required padding amounts are distributed per image axis.

Added in 0.4.0. (Previously named imgaug.imgaug.compute_paddings_to_reach_multiples_of().)

Parameters:
  • arr ((H,W) ndarray or (H,W,C) ndarray or tuple of int) – Image-like array or shape tuple for which to compute pad amounts.
  • height_multiple (None or int) – The desired multiple of the height. The computed padding amount will reflect a padding that increases the y axis size until it is a multiple of this value.
  • width_multiple (None or int) – The desired multiple of the width. The computed padding amount will reflect a padding that increases the x axis size until it is a multiple of this value.
Returns:

Required padding amounts to reach multiples of the provided values, given as a tuple of the form (top, right, bottom, left).

Return type:

tuple of int

imgaug.augmenters.size.compute_paddings_to_reach_powers_of(arr, height_base, width_base, allow_zero_exponent=False)[source]

Compute paddings to reach powers of given base values.

For given axis size S, padded size S' (S' >= S) and base B this function computes paddings that fulfill S' = B^E, where E is any exponent from the discrete interval [0 .. inf).

See compute_paddings_for_aspect_ratio() for an explanation of how the required padding amounts are distributed per image axis.

Added in 0.4.0. (Previously named imgaug.imgaug.compute_paddings_to_reach_exponents_of().)

Parameters:
  • arr ((H,W) ndarray or (H,W,C) ndarray or tuple of int) – Image-like array or shape tuple for which to compute pad amounts.
  • height_base (None or int) – The desired base of the height.
  • width_base (None or int) – The desired base of the width.
  • allow_zero_exponent (bool, optional) – Whether E=0 in S'=B^E is a valid value. If True, axes with size 0 or 1 will be padded up to size B^0=1 and axes with size 1 < S <= B will be padded up to B^1=B. If False, the minimum output axis size is always at least B.
Returns:

Required padding amounts to fulfill S' = B^E given as a tuple of the form (top, right, bottom, left).

Return type:

tuple of int

imgaug.augmenters.size.pad(arr, top=0, right=0, bottom=0, left=0, mode='constant', cval=0)[source]

Pad an image-like array on its top/right/bottom/left side.

This function is a wrapper around numpy.pad().

Added in 0.4.0. (Previously named imgaug.imgaug.pad().)

Supported dtypes:

  • uint8: yes; fully tested (1)
  • uint16: yes; fully tested (1)
  • uint32: yes; fully tested (2) (3)
  • uint64: yes; fully tested (2) (3)
  • int8: yes; fully tested (1)
  • int16: yes; fully tested (1)
  • int32: yes; fully tested (1)
  • int64: yes; fully tested (2) (3)
  • float16: yes; fully tested (2) (3)
  • float32: yes; fully tested (1)
  • float64: yes; fully tested (1)
  • float128: yes; fully tested (2) (3)
  • bool: yes; tested (2) (3)
    1. Uses cv2 if mode is one of: "constant", "edge", "reflect", "symmetric". Otherwise uses numpy.
    1. Uses numpy.
    1. Rejected by cv2.
Parameters:
  • arr ((H,W) ndarray or (H,W,C) ndarray) – Image-like array to pad.
  • top (int, optional) – Amount of pixels to add to the top side of the image. Must be 0 or greater.
  • right (int, optional) – Amount of pixels to add to the right side of the image. Must be 0 or greater.
  • bottom (int, optional) – Amount of pixels to add to the bottom side of the image. Must be 0 or greater.
  • left (int, optional) – Amount of pixels to add to the left side of the image. Must be 0 or greater.
  • mode (str, optional) – Padding mode to use. See numpy.pad() for details. In case of mode constant, the parameter cval will be used as the constant_values parameter to numpy.pad(). In case of mode linear_ramp, the parameter cval will be used as the end_values parameter to numpy.pad().
  • cval (number or iterable of number, optional) – Value to use for padding if mode is constant. See numpy.pad() for details. The cval is expected to match the input array’s dtype and value range. If an iterable is used, it is expected to contain one value per channel. The number of values and number of channels are expected to match.
Returns:

Padded array with height H'=H+top+bottom and width W'=W+left+right.

Return type:

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

imgaug.augmenters.size.pad_to_aspect_ratio(arr, aspect_ratio, mode='constant', cval=0, return_pad_amounts=False)[source]

Pad an image array on its sides so that it matches a target aspect ratio.

See compute_paddings_for_aspect_ratio() for an explanation of how the required padding amounts are distributed per image axis.

Added in 0.4.0. (Previously named imgaug.imgaug.pad_to_aspect_ratio().)

Supported dtypes:

See pad().

Parameters:
  • arr ((H,W) ndarray or (H,W,C) ndarray) – Image-like array to pad.
  • aspect_ratio (float) – Target aspect ratio, given as width/height. E.g. 2.0 denotes the image having twice as much width as height.
  • mode (str, optional) – Padding mode to use. See pad() for details.
  • cval (number, optional) – Value to use for padding if mode is constant. See numpy.pad() for details.
  • return_pad_amounts (bool, optional) – If False, then only the padded image will be returned. If True, a tuple with two entries will be returned, where the first entry is the padded image and the second entry are the amounts by which each image side was padded. These amounts are again a tuple of the form (top, right, bottom, left), with each value being an int.
Returns:

  • (H’,W’) ndarray or (H’,W’,C) ndarray – Padded image as (H',W') or (H',W',C) ndarray, fulfilling the given aspect_ratio.
  • tuple of int – Amounts by which the image was padded on each side, given as a tuple (top, right, bottom, left). This tuple is only returned if return_pad_amounts was set to True.

imgaug.augmenters.size.pad_to_multiples_of(arr, height_multiple, width_multiple, mode='constant', cval=0, return_pad_amounts=False)[source]

Pad an image array until its side lengths are multiples of given values.

See compute_paddings_for_aspect_ratio() for an explanation of how the required padding amounts are distributed per image axis.

Added in 0.4.0. (Previously named imgaug.imgaug.pad_to_multiples_of().)

Supported dtypes:

See pad().

Parameters:
  • arr ((H,W) ndarray or (H,W,C) ndarray) – Image-like array to pad.
  • height_multiple (None or int) – The desired multiple of the height. The computed padding amount will reflect a padding that increases the y axis size until it is a multiple of this value.
  • width_multiple (None or int) – The desired multiple of the width. The computed padding amount will reflect a padding that increases the x axis size until it is a multiple of this value.
  • mode (str, optional) – Padding mode to use. See pad() for details.
  • cval (number, optional) – Value to use for padding if mode is constant. See numpy.pad() for details.
  • return_pad_amounts (bool, optional) – If False, then only the padded image will be returned. If True, a tuple with two entries will be returned, where the first entry is the padded image and the second entry are the amounts by which each image side was padded. These amounts are again a tuple of the form (top, right, bottom, left), with each value being an integer.
Returns:

  • (H’,W’) ndarray or (H’,W’,C) ndarray – Padded image as (H',W') or (H',W',C) ndarray.
  • tuple of int – Amounts by which the image was padded on each side, given as a tuple (top, right, bottom, left). This tuple is only returned if return_pad_amounts was set to True.