imgaug.augmenters.pooling

Augmenters that apply pooling operations to images.

Do not import directly from this file, as the categorization is not final. Use instead

from imgaug import augmenters as iaa

and then e.g.

seq = iaa.Sequential([
    iaa.AveragePooling((1, 3))
])

List of augmenters:

  • AveragePooling
  • MaxPooling
  • MinPooling
  • MedianPooling
class imgaug.augmenters.pooling.AveragePooling(kernel_size, keep_size=True, name=None, deterministic=False, random_state=None)[source]

Bases: imgaug.augmenters.pooling._AbstractPoolingBase

Apply average pooling to images.

This augmenter pools images with kernel sizes H x W by averaging the pixel values within these windows. For e.g. 2 x 2 this halves the image size. Optionally, the augmenter will automatically re-upscale the image to the input size (by default this is activated).

Note that this augmenter is very similar to AverageBlur. AverageBlur applies averaging within windows of given kernel size without striding, while AveragePooling applies striding corresponding to the kernel size, with optional upscaling afterwards. The upscaling is configured to create “pixelated”/”blocky” images by default.

Note

During heatmap or segmentation map augmentation, the respective arrays are not changed, only the shapes of the underlying images are updated. This is because imgaug can handle maps/maks that are larger/smaller than their corresponding image.

dtype support:

See :func:`imgaug.imgaug.avg_pool`.
Variables:
  • kernel_size (int or tuple of int or list of int or imgaug.parameters.StochasticParameter or tuple of tuple of int or tuple of list of int or tuple of imgaug.parameters.StochasticParameter, optional) –

    The kernel size of the pooling operation.

    • If an int, then that value will be used for all images for both kernel height and width.
    • If a tuple (a, b), then a value from the discrete range [a..b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image and used for both kernel height and width.
    • If a StochasticParameter, then a value will be sampled per image from that parameter per image and used for both kernel height and width.
    • If a tuple of tuple of int given as ((a, b), (c, d)), then two values will be sampled independently from the discrete ranges [a..b] and [c..d] per image and used as the kernel height and width.
    • If a tuple of lists of int, then two values will be sampled independently per image, one from the first list and one from the second, and used as the kernel height and width.
    • If a tuple of StochasticParameter, then two values will be sampled indepdently per image, one from the first parameter and one from the second, and used as the kernel height and width.
  • keep_size (bool, optional) – After pooling, 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 pooled image will be resized to the input image’s size, i.e. the augmenter’s output shape is always identical to the input shape.
  • name (None or str, optional) – See imgaug.augmenters.meta.Augmenter.__init__().
  • deterministic (bool, optional) – See imgaug.augmenters.meta.Augmenter.__init__().
  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.AveragePooling(2)

Create an augmenter that always pools with a kernel size of 2 x 2.

>>> aug = iaa.AveragePooling(2, keep_size=False)

Create an augmenter that always pools with a kernel size of 2 x 2 and does not resize back to the input image size, i.e. the resulting images have half the resolution.

>>> aug = iaa.AveragePooling([2, 8])

Create an augmenter that always pools either with a kernel size of 2 x 2 or 8 x 8.

>>> aug = iaa.AveragePooling((1, 7))

Create an augmenter that always pools with a kernel size of 1 x 1 (does nothing) to 7 x 7. The kernel sizes are always symmetric.

>>> aug = iaa.AveragePooling(((1, 7), (1, 7)))

Create an augmenter that always pools with a kernel size of H x W where H and W are both sampled independently from the range [1..7]. E.g. resulting kernel sizes could be 3 x 7 or 5 x 1.

Methods

__call__(self, \*args, \*\*kwargs) Alias for imgaug.augmenters.meta.Augmenter.augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Augment a single batch.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, hooks]) 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.
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_inplace(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
reseed(self[, random_state, deterministic_too]) Reseed 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  
class imgaug.augmenters.pooling.MaxPooling(kernel_size, keep_size=True, name=None, deterministic=False, random_state=None)[source]

Bases: imgaug.augmenters.pooling._AbstractPoolingBase

Apply max pooling to images.

This augmenter pools images with kernel sizes H x W by taking the maximum pixel value over windows. For e.g. 2 x 2 this halves the image size. Optionally, the augmenter will automatically re-upscale the image to the input size (by default this is activated).

The maximum within each pixel window is always taken channelwise..

Note

During heatmap or segmentation map augmentation, the respective arrays are not changed, only the shapes of the underlying images are updated. This is because imgaug can handle maps/maks that are larger/smaller than their corresponding image.

dtype support:

See :func:`imgaug.imgaug.max_pool`.
Variables:
  • kernel_size (int or tuple of int or list of int or imgaug.parameters.StochasticParameter or tuple of tuple of int or tuple of list of int or tuple of imgaug.parameters.StochasticParameter, optional) –

    The kernel size of the pooling operation.

    • If an int, then that value will be used for all images for both kernel height and width.
    • If a tuple (a, b), then a value from the discrete range [a..b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image and used for both kernel height and width.
    • If a StochasticParameter, then a value will be sampled per image from that parameter per image and used for both kernel height and width.
    • If a tuple of tuple of int given as ((a, b), (c, d)), then two values will be sampled independently from the discrete ranges [a..b] and [c..d] per image and used as the kernel height and width.
    • If a tuple of lists of int, then two values will be sampled independently per image, one from the first list and one from the second, and used as the kernel height and width.
    • If a tuple of StochasticParameter, then two values will be sampled indepdently per image, one from the first parameter and one from the second, and used as the kernel height and width.
  • keep_size (bool, optional) – After pooling, 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 pooled image will be resized to the input image’s size, i.e. the augmenter’s output shape is always identical to the input shape.
  • name (None or str, optional) – See imgaug.augmenters.meta.Augmenter.__init__().
  • deterministic (bool, optional) – See imgaug.augmenters.meta.Augmenter.__init__().
  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.MaxPooling(2)

Create an augmenter that always pools with a kernel size of 2 x 2.

>>> aug = iaa.MaxPooling(2, keep_size=False)

Create an augmenter that always pools with a kernel size of 2 x 2 and does not resize back to the input image size, i.e. the resulting images have half the resolution.

>>> aug = iaa.MaxPooling([2, 8])

Create an augmenter that always pools either with a kernel size of 2 x 2 or 8 x 8.

>>> aug = iaa.MaxPooling((1, 7))

Create an augmenter that always pools with a kernel size of 1 x 1 (does nothing) to 7 x 7. The kernel sizes are always symmetric.

>>> aug = iaa.MaxPooling(((1, 7), (1, 7)))

Create an augmenter that always pools with a kernel size of H x W where H and W are both sampled independently from the range [1..7]. E.g. resulting kernel sizes could be 3 x 7 or 5 x 1.

Methods

__call__(self, \*args, \*\*kwargs) Alias for imgaug.augmenters.meta.Augmenter.augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Augment a single batch.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, hooks]) 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.
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_inplace(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
reseed(self[, random_state, deterministic_too]) Reseed 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  
class imgaug.augmenters.pooling.MedianPooling(kernel_size, keep_size=True, name=None, deterministic=False, random_state=None)[source]

Bases: imgaug.augmenters.pooling._AbstractPoolingBase

Apply median pooling to images.

This augmenter pools images with kernel sizes H x W by taking the median pixel value over windows. For e.g. 2 x 2 this halves the image size. Optionally, the augmenter will automatically re-upscale the image to the input size (by default this is activated).

The median within each pixel window is always taken channelwise.

Note

During heatmap or segmentation map augmentation, the respective arrays are not changed, only the shapes of the underlying images are updated. This is because imgaug can handle maps/maks that are larger/smaller than their corresponding image.

dtype support:

See :func:`imgaug.imgaug.pool`.
Variables:
  • kernel_size (int or tuple of int or list of int or imgaug.parameters.StochasticParameter or tuple of tuple of int or tuple of list of int or tuple of imgaug.parameters.StochasticParameter, optional) –

    The kernel size of the pooling operation.

    • If an int, then that value will be used for all images for both kernel height and width.
    • If a tuple (a, b), then a value from the discrete range [a..b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image and used for both kernel height and width.
    • If a StochasticParameter, then a value will be sampled per image from that parameter per image and used for both kernel height and width.
    • If a tuple of tuple of int given as ((a, b), (c, d)), then two values will be sampled independently from the discrete ranges [a..b] and [c..d] per image and used as the kernel height and width.
    • If a tuple of lists of int, then two values will be sampled independently per image, one from the first list and one from the second, and used as the kernel height and width.
    • If a tuple of StochasticParameter, then two values will be sampled indepdently per image, one from the first parameter and one from the second, and used as the kernel height and width.
  • keep_size (bool, optional) – After pooling, 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 pooled image will be resized to the input image’s size, i.e. the augmenter’s output shape is always identical to the input shape.
  • name (None or str, optional) – See imgaug.augmenters.meta.Augmenter.__init__().
  • deterministic (bool, optional) – See imgaug.augmenters.meta.Augmenter.__init__().
  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.MedianPooling(2)

Create an augmenter that always pools with a kernel size of 2 x 2.

>>> aug = iaa.MedianPooling(2, keep_size=False)

Create an augmenter that always pools with a kernel size of 2 x 2 and does not resize back to the input image size, i.e. the resulting images have half the resolution.

>>> aug = iaa.MedianPooling([2, 8])

Create an augmenter that always pools either with a kernel size of 2 x 2 or 8 x 8.

>>> aug = iaa.MedianPooling((1, 7))

Create an augmenter that always pools with a kernel size of 1 x 1 (does nothing) to 7 x 7. The kernel sizes are always symmetric.

>>> aug = iaa.MedianPooling(((1, 7), (1, 7)))

Create an augmenter that always pools with a kernel size of H x W where H and W are both sampled independently from the range [1..7]. E.g. resulting kernel sizes could be 3 x 7 or 5 x 1.

Methods

__call__(self, \*args, \*\*kwargs) Alias for imgaug.augmenters.meta.Augmenter.augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Augment a single batch.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, hooks]) 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.
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_inplace(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
reseed(self[, random_state, deterministic_too]) Reseed 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  
class imgaug.augmenters.pooling.MinPooling(kernel_size, keep_size=True, name=None, deterministic=False, random_state=None)[source]

Bases: imgaug.augmenters.pooling._AbstractPoolingBase

Apply minimum pooling to images.

This augmenter pools images with kernel sizes H x W by taking the minimum pixel value over windows. For e.g. 2 x 2 this halves the image size. Optionally, the augmenter will automatically re-upscale the image to the input size (by default this is activated).

The minimum within each pixel window is always taken channelwise.

Note

During heatmap or segmentation map augmentation, the respective arrays are not changed, only the shapes of the underlying images are updated. This is because imgaug can handle maps/maks that are larger/smaller than their corresponding image.

dtype support:

See :func:`imgaug.imgaug.pool`.
Variables:
  • kernel_size (int or tuple of int or list of int or imgaug.parameters.StochasticParameter or tuple of tuple of int or tuple of list of int or tuple of imgaug.parameters.StochasticParameter, optional) –

    The kernel size of the pooling operation.

    • If an int, then that value will be used for all images for both kernel height and width.
    • If a tuple (a, b), then a value from the discrete range [a..b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image and used for both kernel height and width.
    • If a StochasticParameter, then a value will be sampled per image from that parameter per image and used for both kernel height and width.
    • If a tuple of tuple of int given as ((a, b), (c, d)), then two values will be sampled independently from the discrete ranges [a..b] and [c..d] per image and used as the kernel height and width.
    • If a tuple of lists of int, then two values will be sampled independently per image, one from the first list and one from the second, and used as the kernel height and width.
    • If a tuple of StochasticParameter, then two values will be sampled indepdently per image, one from the first parameter and one from the second, and used as the kernel height and width.
  • keep_size (bool, optional) – After pooling, 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 pooled image will be resized to the input image’s size, i.e. the augmenter’s output shape is always identical to the input shape.
  • name (None or str, optional) – See imgaug.augmenters.meta.Augmenter.__init__().
  • deterministic (bool, optional) – See imgaug.augmenters.meta.Augmenter.__init__().
  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.MinPooling(2)

Create an augmenter that always pools with a kernel size of 2 x 2.

>>> aug = iaa.MinPooling(2, keep_size=False)

Create an augmenter that always pools with a kernel size of 2 x 2 and does not resize back to the input image size, i.e. the resulting images have half the resolution.

>>> aug = iaa.MinPooling([2, 8])

Create an augmenter that always pools either with a kernel size of 2 x 2 or 8 x 8.

>>> aug = iaa.MinPooling((1, 7))

Create an augmenter that always pools with a kernel size of 1 x 1 (does nothing) to 7 x 7. The kernel sizes are always symmetric.

>>> aug = iaa.MinPooling(((1, 7), (1, 7)))

Create an augmenter that always pools with a kernel size of H x W where H and W are both sampled independently from the range [1..7]. E.g. resulting kernel sizes could be 3 x 7 or 5 x 1.

Methods

__call__(self, \*args, \*\*kwargs) Alias for imgaug.augmenters.meta.Augmenter.augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Augment a single batch.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, hooks]) 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.
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_inplace(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
reseed(self[, random_state, deterministic_too]) Reseed 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