imgaug.augmenters.segmentation

Augmenters that apply changes to images based on segmentation methods.

List of augmenters:

class imgaug.augmenters.segmentation.DropoutPointsSampler(other_points_sampler, p_drop)[source]

Bases: imgaug.augmenters.segmentation.IPointsSampler

Remove a defined fraction of sampled points.

Parameters:
  • other_points_sampler (IPointsSampler) – Another point sampler that is queried to generate a list of points. The dropout operation will be applied to that list.

  • p_drop (number or tuple of number or imgaug.parameters.StochasticParameter) – The probability that a coordinate will be removed from the list of all sampled coordinates. A value of 1.0 would mean that (on average) 100 percent of all coordinates will be dropped, while 0.0 denotes 0 percent. Note that this sampler will always ensure that at least one coordinate is left after the dropout operation, i.e. even 1.0 will only drop all except one coordinate.

    • If a float, then that value will be used for all images.
    • If a tuple (a, b), then a value p will be sampled from the interval [a, b] per image.
    • If a StochasticParameter, then this parameter will be used to determine per coordinate whether it should be kept (sampled value of >0.5) or shouldn’t be kept (sampled value of <=0.5). If you instead want to provide the probability as a stochastic parameter, you can usually do imgaug.parameters.Binomial(1-p) to convert parameter p to a 0/1 representation.

Examples

>>> import imgaug.augmenters as iaa
>>> sampler = iaa.DropoutPointsSampler(
>>>     iaa.RegularGridPointsSampler(10, 20),
>>>     0.2)

Create a point sampler that first generates points following a regular grid of 10 rows and 20 columns, then randomly drops 20 percent of these points.

Methods

sample_points(self, images, random_state) Generate coordinates of points on images.
sample_points(self, images, random_state)[source]

Generate coordinates of points on images.

Parameters:
  • images (ndarray or list of ndarray) – One or more images for which to generate points. If this is a list of arrays, each one of them is expected to have three dimensions. If this is an array, it must be four-dimensional and the first axis is expected to denote the image index. For RGB images the array would hence have to be of shape (N, H, W, 3).
  • 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) – A random state to use for any probabilistic function required during the point sampling. See RNG() for details.
Returns:

An (N,2) float32 array containing (x,y) subpixel coordinates, all of which being within the intervals [0.0, width] and [0.0, height].

Return type:

ndarray

class imgaug.augmenters.segmentation.IPointsSampler[source]

Bases: object

Interface for all point samplers.

Point samplers return coordinate arrays of shape Nx2. These coordinates can be used in other augmenters, see e.g. Voronoi.

Methods

sample_points(self, images, random_state) Generate coordinates of points on images.
sample_points(self, images, random_state)[source]

Generate coordinates of points on images.

Parameters:
  • images (ndarray or list of ndarray) – One or more images for which to generate points. If this is a list of arrays, each one of them is expected to have three dimensions. If this is an array, it must be four-dimensional and the first axis is expected to denote the image index. For RGB images the array would hence have to be of shape (N, H, W, 3).
  • 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) – A random state to use for any probabilistic function required during the point sampling. See RNG() for details.
Returns:

An (N,2) float32 array containing (x,y) subpixel coordinates, all of which being within the intervals [0.0, width] and [0.0, height].

Return type:

ndarray

class imgaug.augmenters.segmentation.RegularGridPointsSampler(n_rows, n_cols)[source]

Bases: imgaug.augmenters.segmentation.IPointsSampler

Sampler that generates a regular grid of coordinates on an image.

‘Regular grid’ here means that on each axis all coordinates have the same distance from each other. Note that the distance may change between axis.

Parameters:
  • n_rows (int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – Number of rows of coordinates to place on each image, i.e. the number of coordinates on the y-axis. Note that for each image, the sampled value is clipped to the interval [1..H], where H is the image height.

    • If a single int, then that value will always be used.
    • If a tuple (a, b), then a value from the discrete interval [a..b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then that parameter will be queried to draw one value per image.
  • n_cols (int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – Number of columns of coordinates to place on each image, i.e. the number of coordinates on the x-axis. Note that for each image, the sampled value is clipped to the interval [1..W], where W is the image width.

    • If a single int, then that value will always be used.
    • If a tuple (a, b), then a value from the discrete interval [a..b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then that parameter will be queried to draw one value per image.

Examples

>>> import imgaug.augmenters as iaa
>>> sampler = iaa.RegularGridPointsSampler(
>>>     n_rows=(5, 20),
>>>     n_cols=50)

Create a point sampler that generates regular grids of points. These grids contain r points on the y-axis, where r is sampled uniformly from the discrete interval [5..20] per image. On the x-axis, the grids always contain 50 points.

Methods

sample_points(self, images, random_state) Generate coordinates of points on images.
sample_points(self, images, random_state)[source]

Generate coordinates of points on images.

Parameters:
  • images (ndarray or list of ndarray) – One or more images for which to generate points. If this is a list of arrays, each one of them is expected to have three dimensions. If this is an array, it must be four-dimensional and the first axis is expected to denote the image index. For RGB images the array would hence have to be of shape (N, H, W, 3).
  • 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) – A random state to use for any probabilistic function required during the point sampling. See RNG() for details.
Returns:

An (N,2) float32 array containing (x,y) subpixel coordinates, all of which being within the intervals [0.0, width] and [0.0, height].

Return type:

ndarray

class imgaug.augmenters.segmentation.RegularGridVoronoi(n_rows=(10, 30), n_cols=(10, 30), p_drop_points=(0.0, 0.5), p_replace=(0.5, 1.0), max_size=128, interpolation='linear', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.segmentation.Voronoi

Sample Voronoi cells from regular grids and color-average them.

This augmenter is a shortcut for the combination of Voronoi, RegularGridPointsSampler and DropoutPointsSampler. Hence, it generates a regular grid with R rows and C columns of coordinates on each image. Then, it drops p percent of the R*C coordinates to randomize the grid. Each image pixel then belongs to the voronoi cell with the closest coordinate.

Supported dtypes:

See Voronoi.

Parameters:
  • n_rows (int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – Number of rows of coordinates to place on each image, i.e. the number of coordinates on the y-axis. Note that for each image, the sampled value is clipped to the interval [1..H], where H is the image height.

    • If a single int, then that value will always be used.
    • If a tuple (a, b), then a value from the discrete interval [a..b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then that parameter will be queried to draw one value per image.
  • n_cols (int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – Number of columns of coordinates to place on each image, i.e. the number of coordinates on the x-axis. Note that for each image, the sampled value is clipped to the interval [1..W], where W is the image width.

    • If a single int, then that value will always be used.
    • If a tuple (a, b), then a value from the discrete interval [a..b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then that parameter will be queried to draw one value per image.
  • p_drop_points (number or tuple of number or imgaug.parameters.StochasticParameter, optional) – The probability that a coordinate will be removed from the list of all sampled coordinates. A value of 1.0 would mean that (on average) 100 percent of all coordinates will be dropped, while 0.0 denotes 0 percent. Note that this sampler will always ensure that at least one coordinate is left after the dropout operation, i.e. even 1.0 will only drop all except one coordinate.

    • If a float, then that value will be used for all images.
    • If a tuple (a, b), then a value p will be sampled from the interval [a, b] per image.
    • If a StochasticParameter, then this parameter will be used to determine per coordinate whether it should be kept (sampled value of >0.5) or shouldn’t be kept (sampled value of <=0.5). If you instead want to provide the probability as a stochastic parameter, you can usually do imgaug.parameters.Binomial(1-p) to convert parameter p to a 0/1 representation.
  • p_replace (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Defines for any segment the probability that the pixels within that segment are replaced by their average color (otherwise, the pixels are not changed). Examples:

    • A probability of 0.0 would mean, that the pixels in no segment are replaced by their average color (image is not changed at all).
    • A probability of 0.5 would mean, that around half of all segments are replaced by their average color.
    • A probability of 1.0 would mean, that all segments are replaced by their average color (resulting in a voronoi image).

    Behaviour based on chosen datatypes for this parameter:

    • If a number, then that number will always be used.
    • If tuple (a, b), then a random probability will be sampled from the interval [a, b] per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, it is expected to return values between 0.0 and 1.0 and will be queried for each individual segment to determine whether it is supposed to be averaged (>0.5) or not (<=0.5). Recommended to be some form of Binomial(...).
  • max_size (int or None, optional) – Maximum image size at which the augmentation is performed. If the width or height of an image exceeds this value, it will be downscaled before the augmentation so that the longest side matches max_size. This is done to speed up the process. The final output image has the same size as the input image. Note that in case p_replace is below 1.0, the down-/upscaling will affect the not-replaced pixels too. Use None to apply no down-/upscaling.

  • interpolation (int or str, optional) – Interpolation method to use during downscaling when max_size is exceeded. Valid methods are the same as in imresize_single_image().

  • 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.RegularGridVoronoi(10, 20)

Place a regular grid of 10x20 (height x width) coordinates on each image. Randomly drop on average 20 percent of these points to create a less regular pattern. Then use the remaining coordinates to group the image pixels into voronoi cells and average the colors within them. The process is performed at an image size not exceeding 128 px on any side (default). If necessary, the downscaling is performed using linear interpolation (default).

>>> aug = iaa.RegularGridVoronoi(
>>>     (10, 30), 20, p_drop_points=0.0, p_replace=0.9, max_size=None)

Same as above, generates a grid with randomly 10 to 30 rows, drops none of the generates points, replaces only 90 percent of the voronoi cells with their average color (the pixels of the remaining 10 percent are not changed) and performs the transformation at the original image size (max_size=None).

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.segmentation.RelativeRegularGridPointsSampler(n_rows_frac, n_cols_frac)[source]

Bases: imgaug.augmenters.segmentation.IPointsSampler

Regular grid coordinate sampler; places more points on larger images.

This is similar to RegularGridPointsSampler, but the number of rows and columns is given as fractions of each image’s height and width. Hence, more coordinates are generated for larger images.

Parameters:
  • n_rows_frac (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Relative number of coordinates to place on the y-axis. For a value y and image height H the number of actually placed coordinates (i.e. computed rows) is given by int(round(y*H)). Note that for each image, the number of coordinates is clipped to the interval [1,H], where H is the image height.

    • If a single number, then that value will always be used.
    • If a tuple (a, b), then a value from the interval [a, b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then that parameter will be queried to draw one value per image.
  • n_cols_frac (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Relative number of coordinates to place on the x-axis. For a value x and image height W the number of actually placed coordinates (i.e. computed columns) is given by int(round(x*W)). Note that for each image, the number of coordinates is clipped to the interval [1,W], where W is the image width.

    • If a single number, then that value will always be used.
    • If a tuple (a, b), then a value from the interval [a, b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then that parameter will be queried to draw one value per image.

Examples

>>> import imgaug.augmenters as iaa
>>> sampler = iaa.RelativeRegularGridPointsSampler(
>>>     n_rows_frac=(0.01, 0.1),
>>>     n_cols_frac=0.2)

Create a point sampler that generates regular grids of points. These grids contain round(y*H) points on the y-axis, where y is sampled uniformly from the interval [0.01, 0.1] per image and H is the image height. On the x-axis, the grids always contain 0.2*W points, where W is the image width.

Methods

sample_points(self, images, random_state) Generate coordinates of points on images.
sample_points(self, images, random_state)[source]

Generate coordinates of points on images.

Parameters:
  • images (ndarray or list of ndarray) – One or more images for which to generate points. If this is a list of arrays, each one of them is expected to have three dimensions. If this is an array, it must be four-dimensional and the first axis is expected to denote the image index. For RGB images the array would hence have to be of shape (N, H, W, 3).
  • 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) – A random state to use for any probabilistic function required during the point sampling. See RNG() for details.
Returns:

An (N,2) float32 array containing (x,y) subpixel coordinates, all of which being within the intervals [0.0, width] and [0.0, height].

Return type:

ndarray

class imgaug.augmenters.segmentation.RelativeRegularGridVoronoi(n_rows_frac=(0.05, 0.15), n_cols_frac=(0.05, 0.15), p_drop_points=(0.0, 0.5), p_replace=(0.5, 1.0), max_size=None, interpolation='linear', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.segmentation.Voronoi

Sample Voronoi cells from image-dependent grids and color-average them.

This augmenter is a shortcut for the combination of Voronoi, RegularGridPointsSampler and DropoutPointsSampler. Hence, it generates a regular grid with R rows and C columns of coordinates on each image. Then, it drops p percent of the R*C coordinates to randomize the grid. Each image pixel then belongs to the voronoi cell with the closest coordinate.

Note

In contrast to the other voronoi augmenters, this one uses None as the default value for max_size, i.e. the color averaging is always performed at full resolution. This enables the augmenter to make use of the additional points on larger images. It does however slow down the augmentation process.

Supported dtypes:

See Voronoi.

Parameters:
  • n_rows_frac (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Relative number of coordinates to place on the y-axis. For a value y and image height H the number of actually placed coordinates (i.e. computed rows) is given by int(round(y*H)). Note that for each image, the number of coordinates is clipped to the interval [1,H], where H is the image height.

    • If a single number, then that value will always be used.
    • If a tuple (a, b), then a value from the interval [a, b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then that parameter will be queried to draw one value per image.
  • n_cols_frac (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Relative number of coordinates to place on the x-axis. For a value x and image height W the number of actually placed coordinates (i.e. computed columns) is given by int(round(x*W)). Note that for each image, the number of coordinates is clipped to the interval [1,W], where W is the image width.

    • If a single number, then that value will always be used.
    • If a tuple (a, b), then a value from the interval [a, b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then that parameter will be queried to draw one value per image.
  • p_drop_points (number or tuple of number or imgaug.parameters.StochasticParameter, optional) – The probability that a coordinate will be removed from the list of all sampled coordinates. A value of 1.0 would mean that (on average) 100 percent of all coordinates will be dropped, while 0.0 denotes 0 percent. Note that this sampler will always ensure that at least one coordinate is left after the dropout operation, i.e. even 1.0 will only drop all except one coordinate.

    • If a float, then that value will be used for all images.
    • If a tuple (a, b), then a value p will be sampled from the interval [a, b] per image.
    • If a StochasticParameter, then this parameter will be used to determine per coordinate whether it should be kept (sampled value of >0.5) or shouldn’t be kept (sampled value of <=0.5). If you instead want to provide the probability as a stochastic parameter, you can usually do imgaug.parameters.Binomial(1-p) to convert parameter p to a 0/1 representation.
  • p_replace (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Defines for any segment the probability that the pixels within that segment are replaced by their average color (otherwise, the pixels are not changed). Examples:

    • A probability of 0.0 would mean, that the pixels in no segment are replaced by their average color (image is not changed at all).
    • A probability of 0.5 would mean, that around half of all segments are replaced by their average color.
    • A probability of 1.0 would mean, that all segments are replaced by their average color (resulting in a voronoi image).

    Behaviour based on chosen datatypes for this parameter:

    • If a number, then that number will always be used.
    • If tuple (a, b), then a random probability will be sampled from the interval [a, b] per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, it is expected to return values between 0.0 and 1.0 and will be queried for each individual segment to determine whether it is supposed to be averaged (>0.5) or not (<=0.5). Recommended to be some form of Binomial(...).
  • max_size (int or None, optional) – Maximum image size at which the augmentation is performed. If the width or height of an image exceeds this value, it will be downscaled before the augmentation so that the longest side matches max_size. This is done to speed up the process. The final output image has the same size as the input image. Note that in case p_replace is below 1.0, the down-/upscaling will affect the not-replaced pixels too. Use None to apply no down-/upscaling.

  • interpolation (int or str, optional) – Interpolation method to use during downscaling when max_size is exceeded. Valid methods are the same as in imresize_single_image().

  • 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.RelativeRegularGridVoronoi(0.1, 0.25)

Place a regular grid of R x C coordinates on each image, where R is the number of rows and computed as R=0.1*H with H being the height of the input image. C is the number of columns and analogously estimated from the image width W as C=0.25*W. Larger images will lead to larger R and C values. On average, 20 percent of these grid coordinates are randomly dropped to create a less regular pattern. Then, the remaining coordinates are used to group the image pixels into voronoi cells and the colors within them are averaged.

>>> aug = iaa.RelativeRegularGridVoronoi(
>>>     (0.03, 0.1), 0.1, p_drop_points=0.0, p_replace=0.9, max_size=512)

Same as above, generates a grid with randomly R=r*H rows, where r is sampled uniformly from the interval [0.03, 0.1] and C=0.1*W rows. No points are dropped. The augmenter replaces only 90 percent of the voronoi cells with their average color (the pixels of the remaining 10 percent are not changed). Images larger than 512 px are temporarily downscaled (before sampling the grid points) so that no side exceeds 512 px. This improves performance, but degrades the quality of the resulting 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.segmentation.SubsamplingPointsSampler(other_points_sampler, n_points_max)[source]

Bases: imgaug.augmenters.segmentation.IPointsSampler

Ensure that the number of sampled points is below a maximum.

This point sampler will sample points from another sampler and then – in case more points were generated than an allowed maximum – will randomly pick n_points_max of these.

Parameters:
  • other_points_sampler (IPointsSampler) – Another point sampler that is queried to generate a list of points. The dropout operation will be applied to that list.
  • n_points_max (int) – Maximum number of allowed points. If other_points_sampler generates more points than this maximum, a random subset of size n_points_max will be selected.

Examples

>>> import imgaug.augmenters as iaa
>>> sampler = iaa.SubsamplingPointsSampler(
>>>     iaa.RelativeRegularGridPointsSampler(0.1, 0.2),
>>>     50
>>> )

Create a points sampler that places y*H points on the y-axis (with y being 0.1 and H being an image’s height) and x*W on the x-axis (analogous). Then, if that number of placed points exceeds 50 (can easily happen for larger images), a random subset of 50 points will be picked and returned.

Methods

sample_points(self, images, random_state) Generate coordinates of points on images.
sample_points(self, images, random_state)[source]

Generate coordinates of points on images.

Parameters:
  • images (ndarray or list of ndarray) – One or more images for which to generate points. If this is a list of arrays, each one of them is expected to have three dimensions. If this is an array, it must be four-dimensional and the first axis is expected to denote the image index. For RGB images the array would hence have to be of shape (N, H, W, 3).
  • 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) – A random state to use for any probabilistic function required during the point sampling. See RNG() for details.
Returns:

An (N,2) float32 array containing (x,y) subpixel coordinates, all of which being within the intervals [0.0, width] and [0.0, height].

Return type:

ndarray

class imgaug.augmenters.segmentation.Superpixels(p_replace=(0.5, 1.0), n_segments=(50, 120), max_size=128, interpolation='linear', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Transform images parially/completely to their superpixel representation.

This implementation uses skimage’s version of the SLIC algorithm.

Note

This augmenter is fairly slow. See Performance.

Supported dtypes:

if (image size <= max_size):

  • uint8: yes; fully tested
  • uint16: yes; tested
  • uint32: yes; tested
  • uint64: limited (1)
  • int8: yes; tested
  • int16: yes; tested
  • int32: yes; tested
  • int64: limited (1)
  • float16: no (2)
  • float32: no (2)
  • float64: no (3)
  • float128: no (2)
  • bool: yes; tested
    1. Superpixel mean intensity replacement requires computing these means as float64 s. This can cause inaccuracies for large integer values.
    1. Error in scikit-image.
    1. Loss of resolution in scikit-image.

if (image size > max_size):

minimum of (
imgaug.augmenters.segmentation.Superpixels(image size <= max_size), _ensure_image_max_size()

)

Parameters:
  • p_replace (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Defines for any segment the probability that the pixels within that segment are replaced by their average color (otherwise, the pixels are not changed). Examples:

    • A probability of 0.0 would mean, that the pixels in no segment are replaced by their average color (image is not changed at all).
    • A probability of 0.5 would mean, that around half of all segments are replaced by their average color.
    • A probability of 1.0 would mean, that all segments are replaced by their average color (resulting in a voronoi image).

    Behaviour based on chosen datatypes for this parameter:

    • If a number, then that number will always be used.
    • If tuple (a, b), then a random probability will be sampled from the interval [a, b] per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, it is expected to return values between 0.0 and 1.0 and will be queried for each individual segment to determine whether it is supposed to be averaged (>0.5) or not (<=0.5). Recommended to be some form of Binomial(...).
  • n_segments (int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – Rough target number of how many superpixels to generate (the algorithm may deviate from this number). Lower value will lead to coarser superpixels. Higher values are computationally more intensive and will hence lead to a slowdown.

    • If a single int, then that value will always be used as the number of segments.
    • If a tuple (a, b), then a value from the discrete interval [a..b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then that parameter will be queried to draw one value per image.
  • max_size (int or None, optional) – Maximum image size at which the augmentation is performed. If the width or height of an image exceeds this value, it will be downscaled before the augmentation so that the longest side matches max_size. This is done to speed up the process. The final output image has the same size as the input image. Note that in case p_replace is below 1.0, the down-/upscaling will affect the not-replaced pixels too. Use None to apply no down-/upscaling.

  • interpolation (int or str, optional) – Interpolation method to use during downscaling when max_size is exceeded. Valid methods are the same as in imresize_single_image().

  • 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.Superpixels(p_replace=1.0, n_segments=64)

Generate around 64 superpixels per image and replace all of them with their average color (standard superpixel image).

>>> aug = iaa.Superpixels(p_replace=0.5, n_segments=64)

Generate around 64 superpixels per image and replace half of them with their average color, while the other half are left unchanged (i.e. they still show the input image’s content).

>>> aug = iaa.Superpixels(p_replace=(0.25, 1.0), n_segments=(16, 128))

Generate between 16 and 128 superpixels per image and replace 25 to 100 percent of them with their average color.

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.segmentation.UniformPointsSampler(n_points)[source]

Bases: imgaug.augmenters.segmentation.IPointsSampler

Sample points uniformly on images.

This point sampler generates n_points points per image. The x- and y-coordinates are both sampled from uniform distributions matching the respective image width and height.

Parameters:

n_points (int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) –

Number of points to sample on each image.

  • If a single int, then that value will always be used.
  • If a tuple (a, b), then a value from the discrete interval [a..b] will be sampled per image.
  • If a list, then a random value will be sampled from that list per image.
  • If a StochasticParameter, then that parameter will be queried to draw one value per image.

Examples

>>> import imgaug.augmenters as iaa
>>> sampler = iaa.UniformPointsSampler(500)

Create a point sampler that generates an array of 500 random points for each input image. The x- and y-coordinates of each point are sampled from uniform distributions.

Methods

sample_points(self, images, random_state) Generate coordinates of points on images.
sample_points(self, images, random_state)[source]

Generate coordinates of points on images.

Parameters:
  • images (ndarray or list of ndarray) – One or more images for which to generate points. If this is a list of arrays, each one of them is expected to have three dimensions. If this is an array, it must be four-dimensional and the first axis is expected to denote the image index. For RGB images the array would hence have to be of shape (N, H, W, 3).
  • 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) – A random state to use for any probabilistic function required during the point sampling. See RNG() for details.
Returns:

An (N,2) float32 array containing (x,y) subpixel coordinates, all of which being within the intervals [0.0, width] and [0.0, height].

Return type:

ndarray

class imgaug.augmenters.segmentation.UniformVoronoi(n_points=(50, 500), p_replace=(0.5, 1.0), max_size=128, interpolation='linear', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.segmentation.Voronoi

Uniformly sample Voronoi cells on images and average colors within them.

This augmenter is a shortcut for the combination of Voronoi with UniformPointsSampler. Hence, it generates a fixed amount of N random coordinates of voronoi cells on each image. The cell coordinates are sampled uniformly using the image height and width as maxima.

Supported dtypes:

See Voronoi.

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

    Number of points to sample on each image.

    • If a single int, then that value will always be used.
    • If a tuple (a, b), then a value from the discrete interval [a..b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then that parameter will be queried to draw one value per image.
  • p_replace (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Defines for any segment the probability that the pixels within that segment are replaced by their average color (otherwise, the pixels are not changed). Examples:

    • A probability of 0.0 would mean, that the pixels in no segment are replaced by their average color (image is not changed at all).
    • A probability of 0.5 would mean, that around half of all segments are replaced by their average color.
    • A probability of 1.0 would mean, that all segments are replaced by their average color (resulting in a voronoi image).

    Behaviour based on chosen datatypes for this parameter:

    • If a number, then that number will always be used.
    • If tuple (a, b), then a random probability will be sampled from the interval [a, b] per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, it is expected to return values between 0.0 and 1.0 and will be queried for each individual segment to determine whether it is supposed to be averaged (>0.5) or not (<=0.5). Recommended to be some form of Binomial(...).
  • max_size (int or None, optional) – Maximum image size at which the augmentation is performed. If the width or height of an image exceeds this value, it will be downscaled before the augmentation so that the longest side matches max_size. This is done to speed up the process. The final output image has the same size as the input image. Note that in case p_replace is below 1.0, the down-/upscaling will affect the not-replaced pixels too. Use None to apply no down-/upscaling.

  • interpolation (int or str, optional) – Interpolation method to use during downscaling when max_size is exceeded. Valid methods are the same as in imresize_single_image().

  • 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.UniformVoronoi((100, 500))

Sample for each image uniformly the number of voronoi cells N from the interval [100, 500]. Then generate N coordinates by sampling uniformly the x-coordinates from [0, W] and the y-coordinates from [0, H], where H is the image height and W the image width. Then use these coordinates to group the image pixels into voronoi cells and average the colors within them. The process is performed at an image size not exceeding 128 px on any side (default). If necessary, the downscaling is performed using linear interpolation (default).

>>> aug = iaa.UniformVoronoi(250, p_replace=0.9, max_size=None)

Same as above, but always samples N=250 cells, replaces only 90 percent of them with their average color (the pixels of the remaining 10 percent are not changed) and performs the transformation at the original image size (max_size=None).

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.segmentation.Voronoi(points_sampler, p_replace=1.0, max_size=128, interpolation='linear', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Average colors of an image within Voronoi cells.

This augmenter performs the following steps:

  1. Query points_sampler to sample random coordinates of cell centers. On the image.
  2. Estimate for each pixel to which voronoi cell (i.e. segment) it belongs. Each pixel belongs to the cell with the closest center coordinate (euclidean distance).
  3. Compute for each cell the average color of the pixels within it.
  4. Replace the pixels of p_replace percent of all cells by their average color. Do not change the pixels of (1 - p_replace) percent of all cells. (The percentages are average values over many images. Some images may get more/less cells replaced by their average color.)

This code is very loosely based on https://codegolf.stackexchange.com/questions/50299/draw-an-image-as-a-voronoi-map/50345#50345

Supported dtypes:

if (image size <= max_size):

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

if (image size > max_size):

minimum of (
imgaug.augmenters.segmentation.Voronoi(image size <= max_size), _ensure_image_max_size()

)

Parameters:
  • points_sampler (IPointsSampler) – A points sampler which will be queried per image to generate the coordinates of the centers of voronoi cells.

  • p_replace (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Defines for any segment the probability that the pixels within that segment are replaced by their average color (otherwise, the pixels are not changed). Examples:

    • A probability of 0.0 would mean, that the pixels in no segment are replaced by their average color (image is not changed at all).
    • A probability of 0.5 would mean, that around half of all segments are replaced by their average color.
    • A probability of 1.0 would mean, that all segments are replaced by their average color (resulting in a voronoi image).

    Behaviour based on chosen datatypes for this parameter:

    • If a number, then that number will always be used.
    • If tuple (a, b), then a random probability will be sampled from the interval [a, b] per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, it is expected to return values between 0.0 and 1.0 and will be queried for each individual segment to determine whether it is supposed to be averaged (>0.5) or not (<=0.5). Recommended to be some form of Binomial(...).
  • max_size (int or None, optional) – Maximum image size at which the augmentation is performed. If the width or height of an image exceeds this value, it will be downscaled before the augmentation so that the longest side matches max_size. This is done to speed up the process. The final output image has the same size as the input image. Note that in case p_replace is below 1.0, the down-/upscaling will affect the not-replaced pixels too. Use None to apply no down-/upscaling.

  • interpolation (int or str, optional) – Interpolation method to use during downscaling when max_size is exceeded. Valid methods are the same as in imresize_single_image().

  • 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
>>> points_sampler = iaa.RegularGridPointsSampler(n_cols=20, n_rows=40)
>>> aug = iaa.Voronoi(points_sampler)

Create an augmenter that places a 20x40 (HxW) grid of cells on the image and replaces all pixels within each cell by the cell’s average color. The process is performed at an image size not exceeding 128 px on any side (default). If necessary, the downscaling is performed using linear interpolation (default).

>>> points_sampler = iaa.DropoutPointsSampler(
>>>     iaa.RelativeRegularGridPointsSampler(
>>>         n_cols_frac=(0.05, 0.2),
>>>         n_rows_frac=0.1),
>>>     0.2)
>>> aug = iaa.Voronoi(points_sampler, p_replace=0.9, max_size=None)

Create a voronoi augmenter that generates a grid of cells dynamically adapted to the image size. Larger images get more cells. On the x-axis, the distance between two cells is w * W pixels, where W is the width of the image and w is always 0.1. On the y-axis, the distance between two cells is h * H pixels, where H is the height of the image and h is sampled uniformly from the interval [0.05, 0.2]. To make the voronoi pattern less regular, about 20 percent of the cell coordinates are randomly dropped (i.e. the remaining cells grow in size). In contrast to the first example, the image is not resized (if it was, the sampling would happen after the resizing, which would affect W and H). Not all voronoi cells are replaced by their average color, only around 90 percent of them. The remaining 10 percent’s pixels remain unchanged.

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.segmentation.segment_voronoi(image, cell_coordinates, replace_mask=None)[source]

Average colors within voronoi cells of an image.

Parameters:
  • image (ndarray) – The image to convert to a voronoi image. May be HxW or HxWxC. Note that for RGBA images the alpha channel will currently also by averaged.
  • cell_coordinates (ndarray) – A Nx2 float array containing the center coordinates of voronoi cells on the image. Values are expected to be in the interval [0.0, height-1.0] for the y-axis (x-axis analogous). If this array contains no coordinate, the image will not be changed.
  • replace_mask (None or ndarray, optional) – Boolean mask of the same length as cell_coordinates, denoting for each cell whether its pixels are supposed to be replaced by the cell’s average color (True) or left untouched (False). If this is set to None, all cells will be replaced.
Returns:

Voronoi image.

Return type:

ndarray