imgaug.augmenters.segmentation¶
Augmenters that apply changes to images based on segmentation methods.
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.Superpixels(...)
])
List of augmenters:
- Superpixels
- Voronoi
- UniformVoronoi
- RegularGridVoronoi
- RelativeRegularGridVoronoi
-
class
imgaug.augmenters.segmentation.DropoutPointsSampler(other_points_sampler, p_drop)[source]¶ Bases:
imgaug.augmenters.segmentation.IPointsSamplerRemove 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.0would mean that (on average)100percent of all coordinates will be dropped, while0.0denotes0percent. Note that this sampler will always ensure that at least one coordinate is left after the dropout operation, i.e. even1.0will 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 valuepwill 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 doimgaug.parameters.Binomial(1-p)to convert parameter p to a 0/1 representation.
- If a
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
10rows and20columns, then randomly drops20percent 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
listof 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. ForRGBimages 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.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState) – A random state to use for any probabilistic function required
during the point sampling.
See
imgaug.random.RNG()for details.
Returns: An
(N,2)float32array containing(x,y)subpixel coordinates, all of which being within the intervals[0.0, width]and[0.0, height].Return type: ndarray
- images (ndarray or list of ndarray) – One or more images for which to generate points.
If this is a
-
class
imgaug.augmenters.segmentation.IPointsSampler[source]¶ Bases:
objectInterface for all point samplers.
Point samplers return coordinate arrays of shape
Nx2. These coordinates can be used in other augmenters, see e.g.imgaug.augmenters.segmentation.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
listof 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. ForRGBimages 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.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState) – A random state to use for any probabilistic function required
during the point sampling.
See
imgaug.random.RNG()for details.
Returns: An
(N,2)float32array containing(x,y)subpixel coordinates, all of which being within the intervals[0.0, width]and[0.0, height].Return type: ndarray
- images (ndarray or list of ndarray) – One or more images for which to generate points.
If this is a
-
-
class
imgaug.augmenters.segmentation.RegularGridPointsSampler(n_rows, n_cols)[source]¶ Bases:
imgaug.augmenters.segmentation.IPointsSamplerSampler 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], whereHis 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 thatlistper image. - If a
StochasticParameter, then that parameter will be queried to draw one value per image.
- If a single
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], whereWis 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 thatlistper image. - If a
StochasticParameter, then that parameter will be queried to draw one value per image.
- If a single
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
rpoints on the y-axis, whereris sampled uniformly from the discrete interval[5..20]per image. On the x-axis, the grids always contain50points.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
listof 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. ForRGBimages 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.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState) – A random state to use for any probabilistic function required
during the point sampling.
See
imgaug.random.RNG()for details.
Returns: An
(N,2)float32array containing(x,y)subpixel coordinates, all of which being within the intervals[0.0, width]and[0.0, height].Return type: ndarray
- images (ndarray or list of ndarray) – One or more images for which to generate points.
If this is a
-
class
imgaug.augmenters.segmentation.RegularGridVoronoi(n_rows, n_cols, p_drop_points=0.4, p_replace=1.0, max_size=128, interpolation='linear', name=None, deterministic=False, random_state=None)[source]¶ Bases:
imgaug.augmenters.segmentation.VoronoiSample Voronoi cells from regular grids and color-average them.
This augmenter is a shortcut for the combination of
imgaug.augmenters.segmentation.Voronoi,imgaug.augmenters.segmentation.RegularGridPointsSamplerandimgaug.augmenters.segmentation.DropoutPointsSampler. Hence, it generates a regular grid withRrows andCcolumns of coordinates on each image. Then, it dropsppercent of theR*Ccoordinates to randomize the grid. Each image pixel then belongs to the voronoi cell with the closest coordinate.dtype support:
See ``imgaug.augmenters.segmentation.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], whereHis 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 thatlistper image. - If a
StochasticParameter, then that parameter will be queried to draw one value per image.
- If a single
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], whereWis 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 thatlistper image. - If a
StochasticParameter, then that parameter will be queried to draw one value per image.
- If a single
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.0would mean that (on average)100percent of all coordinates will be dropped, while0.0denotes0percent. Note that this sampler will always ensure that at least one coordinate is left after the dropout operation, i.e. even1.0will 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 valuepwill 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 doimgaug.parameters.Binomial(1-p)to convert parameter p to a 0/1 representation.
- If a
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.0would mean, that the pixels in no segment are replaced by their average color (image is not changed at all). - A probability of
0.5would mean, that around half of all segments are replaced by their average color. - A probability of
1.0would 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 thatlistper image. - If a
StochasticParameter, it is expected to return values between0.0and1.0and 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 ofBinomial(...).
- A probability of
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. UseNoneto 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
imgaug.imgaug.imresize_single_image().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.RegularGridVoronoi(10, 20)
Place a regular grid of
10x20(height x width) coordinates on each image. Randomly drop on average20percent 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 exceeding128px on any side (default). If necessary, the downscaling is performed usinglinearinterpolation (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
10to30rows, drops none of the generates points, replaces only90percent of the voronoi cells with their average color (the pixels of the remaining10percent are not changed) and performs the transformation at the original image size (max_size=None).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.segmentation.RelativeRegularGridPointsSampler(n_rows_frac, n_cols_frac)[source]¶ Bases:
imgaug.augmenters.segmentation.IPointsSamplerRegular 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
yand image heightHthe number of actually placed coordinates (i.e. computed rows) is given byint(round(y*H)). Note that for each image, the number of coordinates is clipped to the interval[1,H], whereHis 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 thatlistper image. - If a
StochasticParameter, then that parameter will be queried to draw one value per image.
- If a single
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
xand image heightWthe number of actually placed coordinates (i.e. computed columns) is given byint(round(x*W)). Note that for each image, the number of coordinates is clipped to the interval[1,W], whereWis 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 thatlistper image. - If a
StochasticParameter, then that parameter will be queried to draw one value per image.
- If a single
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, whereyis sampled uniformly from the interval[0.01, 0.1]per image andHis the image height. On the x-axis, the grids always contain0.2*Wpoints, whereWis 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
listof 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. ForRGBimages 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.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState) – A random state to use for any probabilistic function required
during the point sampling.
See
imgaug.random.RNG()for details.
Returns: An
(N,2)float32array containing(x,y)subpixel coordinates, all of which being within the intervals[0.0, width]and[0.0, height].Return type: ndarray
- images (ndarray or list of ndarray) – One or more images for which to generate points.
If this is a
-
class
imgaug.augmenters.segmentation.RelativeRegularGridVoronoi(n_rows_frac, n_cols_frac, p_drop_points=0.4, p_replace=1.0, max_size=None, interpolation='linear', name=None, deterministic=False, random_state=None)[source]¶ Bases:
imgaug.augmenters.segmentation.VoronoiSample Voronoi cells from image-dependent grids and color-average them.
This augmenter is a shortcut for the combination of
imgaug.augmenters.segmentation.Voronoi,imgaug.augmenters.segmentation.RegularGridPointsSamplerandimgaug.augmenters.segmentation.DropoutPointsSampler. Hence, it generates a regular grid withRrows andCcolumns of coordinates on each image. Then, it dropsppercent of theR*Ccoordinates 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
Noneas the default value for max_size, i.e. the color averaging is always performed at full resolution. This enables the augmenter to make most use of the added points for larger images. It does however slow down the augmentation process.dtype support:
See ``imgaug.augmenters.segmentation.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
yand image heightHthe number of actually placed coordinates (i.e. computed rows) is given byint(round(y*H)). Note that for each image, the number of coordinates is clipped to the interval[1,H], whereHis 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 thatlistper image. - If a
StochasticParameter, then that parameter will be queried to draw one value per image.
- If a single
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
xand image heightWthe number of actually placed coordinates (i.e. computed columns) is given byint(round(x*W)). Note that for each image, the number of coordinates is clipped to the interval[1,W], whereWis 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 thatlistper image. - If a
StochasticParameter, then that parameter will be queried to draw one value per image.
- If a single
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.0would mean that (on average)100percent of all coordinates will be dropped, while0.0denotes0percent. Note that this sampler will always ensure that at least one coordinate is left after the dropout operation, i.e. even1.0will 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 valuepwill 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 doimgaug.parameters.Binomial(1-p)to convert parameter p to a 0/1 representation.
- If a
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.0would mean, that the pixels in no segment are replaced by their average color (image is not changed at all). - A probability of
0.5would mean, that around half of all segments are replaced by their average color. - A probability of
1.0would 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 thatnumberwill 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 thatlistper image. - If a
StochasticParameter, it is expected to return values between0.0and1.0and 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 ofBinomial(...).
- A probability of
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. UseNoneto 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
imgaug.imgaug.imresize_single_image().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.RelativeRegularGridVoronoi(0.1, 0.25)
Place a regular grid of
R x Ccoordinates on each image, whereRis the number of rows and computed asR=0.1*HwithHbeing the height of the input image.Cis the number of columns and analogously estimated from the image widthWasC=0.25*W. Larger images will lead to largerRandCvalues. On average,20percent 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*Hrows, whereris sampled uniformly from the interval[0.03, 0.1]andC=0.1*Wrows. No points are dropped. The augmenter replaces only90percent of the voronoi cells with their average color (the pixels of the remaining10percent are not changed). Images larger than512px are temporarily downscaled (before sampling the grid points) so that no side exceeds512px. This improves performance, but degrades the quality of the resulting image.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.segmentation.SubsamplingPointsSampler(other_points_sampler, n_points_max)[source]¶ Bases:
imgaug.augmenters.segmentation.IPointsSamplerEnsure 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
listof points. The dropout operation will be applied to thatlist. - 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*Hpoints on the y-axis (withybeing0.1andHbeing an image’s height) andx*Won the x-axis (analogous). Then, if that number of placed points exceeds50(can easily happen for larger images), a random subset of50points 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
listof 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. ForRGBimages 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.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState) – A random state to use for any probabilistic function required
during the point sampling.
See
imgaug.random.RNG()for details.
Returns: An
(N,2)float32array containing(x,y)subpixel coordinates, all of which being within the intervals[0.0, width]and[0.0, height].Return type: ndarray
- images (ndarray or list of ndarray) – One or more images for which to generate points.
If this is a
- other_points_sampler (IPointsSampler) – Another point sampler that is queried to generate a
-
class
imgaug.augmenters.segmentation.Superpixels(p_replace=0, n_segments=100, max_size=128, interpolation='linear', name=None, deterministic=False, random_state=None)[source]¶ Bases:
imgaug.augmenters.meta.AugmenterTransform 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.
dtype support:
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 float64s. This can cause inaccuracies for large integer values. - (2) Error in scikit-image. - (3) Loss of resolution in scikit-image. if (image size > max_size):: minimum of ( ``imgaug.augmenters.segmentation.Superpixels(image size <= max_size)``, :func:`imgaug.augmenters.segmentation._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.0would mean, that the pixels in no segment are replaced by their average color (image is not changed at all). - A probability of
0.5would mean, that around half of all segments are replaced by their average color. - A probability of
1.0would 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 thatnumberwill 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 thatlistper image. - If a
StochasticParameter, it is expected to return values between0.0and1.0and 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 ofBinomial(...).
- A probability of
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 thatlistper image. - If a
StochasticParameter, then that parameter will be queried to draw one value per image.
- If a single
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. UseNoneto 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
imgaug.imgaug.imresize_single_image().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.Superpixels(p_replace=1.0, n_segments=64)
Generate around
64superpixels 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
64superpixels 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
16and128superpixels per image and replace25to100percent of them with their average color.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.segmentation.UniformPointsSampler(n_points)[source]¶ Bases:
imgaug.augmenters.segmentation.IPointsSamplerSample 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 thatlistper 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
500random 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
listof 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. ForRGBimages 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.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState) – A random state to use for any probabilistic function required
during the point sampling.
See
imgaug.random.RNG()for details.
Returns: An
(N,2)float32array containing(x,y)subpixel coordinates, all of which being within the intervals[0.0, width]and[0.0, height].Return type: ndarray
- images (ndarray or list of ndarray) – One or more images for which to generate points.
If this is a
- If a single
-
class
imgaug.augmenters.segmentation.UniformVoronoi(n_points, p_replace=1.0, max_size=128, interpolation='linear', name=None, deterministic=False, random_state=None)[source]¶ Bases:
imgaug.augmenters.segmentation.VoronoiUniformly sample Voronoi cells on images and average colors within them.
This augmenter is a shortcut for the combination of
imgaug.augmenters.segmentation.Voronoiwithimgaug.augmenters.segmentation.UniformPointsSampler. Hence, it generates a fixed amount ofNrandom coordinates of voronoi cells on each image. The cell coordinates are sampled uniformly using the image height and width as maxima.dtype support:
See ``imgaug.augmenters.segmentation.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 thatlistper image. - If a
StochasticParameter, then that parameter will be queried to draw one value per image.
- If a single
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.0would mean, that the pixels in no segment are replaced by their average color (image is not changed at all). - A probability of
0.5would mean, that around half of all segments are replaced by their average color. - A probability of
1.0would 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 thatnumberwill 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 thatlistper image. - If a
StochasticParameter, it is expected to return values between0.0and1.0and 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 ofBinomial(...).
- A probability of
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. UseNoneto 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
imgaug.imgaug.imresize_single_image().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.UniformVoronoi((100, 500))
Sample for each image uniformly the number of voronoi cells
Nfrom the interval[100, 500]. Then generateNcoordinates by sampling uniformly the x-coordinates from[0, W]and the y-coordinates from[0, H], whereHis the image height andWthe 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 exceeding128px on any side (default). If necessary, the downscaling is performed usinglinearinterpolation (default).>>> aug = iaa.UniformVoronoi(250, p_replace=0.9, max_size=None)
Same as above, but always samples
N=250cells, replaces only90percent of them with their average color (the pixels of the remaining10percent are not changed) and performs the transformation at the original image size (max_size=None).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.segmentation.Voronoi(points_sampler, p_replace=1.0, max_size=128, interpolation='linear', name=None, deterministic=False, random_state=None)[source]¶ Bases:
imgaug.augmenters.meta.AugmenterAverage colors of an image within Voronoi cells.
This augmenter performs the following steps:
- Query points_sampler to sample random coordinates of cell centers. On the image.
- 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).
- Compute for each cell the average color of the pixels within it.
- 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
dtype support:
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)``, :func:`imgaug.augmenters.segmentation._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.0would mean, that the pixels in no segment are replaced by their average color (image is not changed at all). - A probability of
0.5would mean, that around half of all segments are replaced by their average color. - A probability of
1.0would 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 thatnumberwill 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 thatlistper image. - If a
StochasticParameter, it is expected to return values between0.0and1.0and 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 ofBinomial(...).
- A probability of
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. UseNoneto 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
imgaug.imgaug.imresize_single_image().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 >>> 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 exceeding128px on any side (default). If necessary, the downscaling is performed usinglinearinterpolation (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 * Wpixels, whereWis the width of the image andwis always0.1. On the y-axis, the distance between two cells ish * Hpixels, whereHis the height of the image andhis sampled uniformly from the interval[0.05, 0.2]. To make the voronoi pattern less regular, about20percent 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 affectWandH). Not all voronoi cells are replaced by their average color, only around90percent of them. The remaining10percent’s pixels remain unchanged.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
-
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
HxWorHxWxC. Note that forRGBAimages the alpha channel will currently also by averaged. - cell_coordinates (ndarray) – A
Nx2float 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 toNone, all cells will be replaced.
Returns: Voronoi image.
Return type: ndarray
- image (ndarray) – The image to convert to a voronoi image. May be