imgaug.augmenters.blend¶
Augmenters that blend two images with each other.
List of augmenters:
-
imgaug.augmenters.blend.
Alpha
(factor=0, first=None, second=None, per_channel=False, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Deprecated. Use
Alpha
instead. Alpha is deprecated. Use BlendAlpha instead. The order of parameters is the same. Parameter ‘first’ was renamed to ‘foreground’. Parameter ‘second’ was renamed to ‘background’.See
BlendAlpha
.Deprecated since 0.4.0.
-
imgaug.augmenters.blend.
AlphaElementwise
(factor=0, first=None, second=None, per_channel=False, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Deprecated. Use
AlphaElementwise
instead. AlphaElementwise is deprecated. Use BlendAlphaElementwise instead. The order of parameters is the same. Parameter ‘first’ was renamed to ‘foreground’. Parameter ‘second’ was renamed to ‘background’.Deprecated since 0.4.0.
-
class
imgaug.augmenters.blend.
BlendAlpha
(factor=(0.0, 1.0), foreground=None, background=None, per_channel=False, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.meta.Augmenter
Alpha-blend two image sources using an alpha/opacity value.
The two image sources can be imagined as branches. If a source is not given, it is automatically the same as the input. Let
FG
be the foreground branch andBG
be the background branch. Then the result images are defined asfactor * FG + (1-factor) * BG
, wherefactor
is an overlay factor.Note
It is not recommended to use
BlendAlpha
with augmenters that change the geometry of images (e.g. horizontal flips, affine transformations) if you also want to augment coordinates (e.g. keypoints, polygons, …), as it is unclear which of the two coordinate results (foreground or background branch) should be used as the coordinates after augmentation.Currently, if
factor >= 0.5
(per image), the results of the foreground branch are used as the new coordinates, otherwise the results of the background branch.Added in 0.4.0. (Before that named Alpha.)
Supported dtypes:
See
blend_alpha()
.Parameters: factor (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Opacity of the results of the foreground branch. Values close to
0.0
mean that the results from the background branch (see parameter background) make up most of the final image.- If float, then that value will be used for all images.
- If tuple
(a, b)
, then a random value from the interval[a, b]
will be sampled per image. - If a list, then a random value will be picked from that list per image.
- If
StochasticParameter
, then that parameter will be used to sample a value per image.
foreground (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) that make up the foreground branch. High alpha values will show this branch’s results.
- If
None
, then the input images will be reused as the output of the foreground branch. - If
Augmenter
, then that augmenter will be used as the branch. - If iterable of
Augmenter
, then that iterable will be converted into aSequential
and used as the augmenter.
- If
background (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) that make up the background branch. Low alpha values will show this branch’s results.
- If
None
, then the input images will be reused as the output of the background branch. - If
Augmenter
, then that augmenter will be used as the branch. - If iterable of
Augmenter
, then that iterable will be converted into aSequential
and used as the augmenter.
- If
per_channel (bool or float or imgaug.parameters.StochasticParameter, optional) – Whether to use the same factor for all channels (
False
) or to sample a new value for each channel (True
). If this value is a floatp
, then forp
percent of all images per_channel will be treated as True, otherwise as False.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.BlendAlpha(0.5, iaa.Grayscale(1.0))
Convert each image to pure grayscale and alpha-blend the result with the original image using an alpha of
50%
, thereby removing about50%
of all color. This is equivalent toiaa.Grayscale(0.5)
.>>> aug = iaa.BlendAlpha((0.0, 1.0), iaa.Grayscale(1.0))
Same as in the previous example, but the alpha factor is sampled uniformly from the interval
[0.0, 1.0]
once per image, thereby removing a random fraction of all colors. This is equivalent toiaa.Grayscale((0.0, 1.0))
.>>> aug = iaa.BlendAlpha( >>> (0.0, 1.0), >>> iaa.Affine(rotate=(-20, 20)), >>> per_channel=0.5)
First, rotate each image by a random degree sampled uniformly from the interval
[-20, 20]
. Then, alpha-blend that new image with the original one using a random factor sampled uniformly from the interval[0.0, 1.0]
. For50%
of all images, the blending happens channel-wise and the factor is sampled independently per channel (per_channel=0.5
). As a result, e.g. the red channel may look visibly rotated (factor near1.0
), while the green and blue channels may not look rotated (factors near0.0
).>>> aug = iaa.BlendAlpha( >>> (0.0, 1.0), >>> foreground=iaa.Add(100), >>> background=iaa.Multiply(0.2))
Apply two branches of augmenters –
A
andB
– independently to input images and alpha-blend the results of these branches using a factorf
. BranchA
increases image pixel intensities by100
andB
multiplies the pixel intensities by0.2
.f
is sampled uniformly from the interval[0.0, 1.0]
per image. The resulting images contain a bit ofA
and a bit ofB
.>>> aug = iaa.BlendAlpha([0.25, 0.75], iaa.MedianBlur(13))
Apply median blur to each image and alpha-blend the result with the original image using an alpha factor of either exactly
0.25
or exactly0.75
(sampled once per 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)See get_children_lists()
.get_parameters
(self)See get_parameters()
.localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one. -
get_children_lists
(self)[source]¶ See
get_children_lists()
.
-
get_parameters
(self)[source]¶ See
get_parameters()
.
-
class
imgaug.augmenters.blend.
BlendAlphaBoundingBoxes
(labels, foreground=None, background=None, nb_sample_labels=None, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.blend.BlendAlphaMask
Blend images from two branches based on areas enclosed in bounding boxes.
This class generates masks that are
1.0
within bounding boxes of given labels. A mask pixel will be set to1.0
if at least one bounding box covers the area and has one of the requested labels.This class is a thin wrapper around
BlendAlphaMask
together withBoundingBoxesMaskGen
.Note
Avoid using augmenters as children that affect pixel locations (e.g. horizontal flips). See
BlendAlphaMask
for details.Note
This class will produce an
AssertionError
if there are no bounding boxes in a batch.Added in 0.4.0.
Supported dtypes:
See
BlendAlphaMask
.Parameters: labels (None or str or list of str or imgaug.parameters.StochasticParameter) – See
BoundingBoxesMaskGen
.foreground (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) that make up the foreground branch. High alpha values will show this branch’s results.
- If
None
, then the input images will be reused as the output of the foreground branch. - If
Augmenter
, then that augmenter will be used as the branch. - If iterable of
Augmenter
, then that iterable will be converted into aSequential
and used as the augmenter.
- If
background (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) that make up the background branch. Low alpha values will show this branch’s results.
- If
None
, then the input images will be reused as the output of the background branch. - If
Augmenter
, then that augmenter will be used as the branch. - If iterable of
Augmenter
, then that iterable will be converted into aSequential
and used as the augmenter.
- If
nb_sample_labels (None or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – See
BoundingBoxesMaskGen
.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.BlendAlphaBoundingBoxes("person", >>> foreground=iaa.Grayscale(1.0))
Create an augmenter that removes color within bounding boxes having the label
person
.>>> aug = iaa.BlendAlphaBoundingBoxes(["person", "car"], >>> foreground=iaa.AddToHue((-255, 255)))
Create an augmenter that randomizes the hue within bounding boxes that have the label
person
orcar
.>>> aug = iaa.BlendAlphaBoundingBoxes(["person", "car"], >>> foreground=iaa.AddToHue((-255, 255)), >>> nb_sample_labels=1)
Create an augmenter that randomizes the hue within bounding boxes that have either the label
person
orcar
. Only one label is picked per image. Note that the sampling happens with replacement, so ifnb_sample_classes
would be>1
, it could still lead to only one unique label being sampled.>>> aug = iaa.BlendAlphaBoundingBoxes(None, >>> background=iaa.Multiply(0.0))
Create an augmenter that zeros all pixels (
Multiply(0.0)
) that are not (background
branch) within bounding boxes of any (None
) label. In other words, all pixels outside of bounding boxes become black. Note that we don’t useTotalDropout
here, because by default it will also remove all coordinate-based augmentables, which will break the blending of such inputs.Methods
__call__
(self, \*args, \*\*kwargs)Alias for augment()
.augment
(self[, return_batch, hooks])Augment a batch. augment_batch
(self, batch[, hooks])Deprecated. augment_batch_
(self, batch[, parents, hooks])Augment a single batch in-place. augment_batches
(self, batches[, hooks, …])Augment multiple batches. augment_bounding_boxes
(self, …[, parents, …])Augment a batch of bounding boxes. augment_heatmaps
(self, heatmaps[, parents, …])Augment a batch of heatmaps. augment_image
(self, image[, hooks])Augment a single image. augment_images
(self, images[, parents, hooks])Augment a batch of images. augment_keypoints
(self, keypoints_on_images)Augment a batch of keypoints/landmarks. augment_line_strings
(self, …[, parents, hooks])Augment a batch of line strings. augment_polygons
(self, polygons_on_images[, …])Augment a batch of polygons. augment_segmentation_maps
(self, segmaps[, …])Augment a batch of segmentation maps. copy
(self)Create a shallow copy of this Augmenter instance. copy_random_state
(self, source[, recursive, …])Copy the RNGs from a source augmenter sequence. copy_random_state_
(self, source[, …])Copy the RNGs from a source augmenter sequence (in-place). deepcopy
(self)Create a deep copy of this Augmenter instance. draw_grid
(self, images, rows, cols)Augment images and draw the results as a single grid-like image. find_augmenters
(self, func[, parents, flat])Find augmenters that match a condition. find_augmenters_by_name
(self, name[, regex, …])Find augmenter(s) by name. find_augmenters_by_names
(self, names[, …])Find augmenter(s) by names. get_all_children
(self[, flat])Get all children of this augmenter as a list. get_children_lists
(self)See get_children_lists()
.get_parameters
(self)See get_parameters()
.localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one.
-
class
imgaug.augmenters.blend.
BlendAlphaCheckerboard
(nb_rows, nb_cols, foreground=None, background=None, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.blend.BlendAlphaMask
Blend images from two branches according to a checkerboard pattern.
This class generates for each image a mask following a checkboard layout of
H
rows andW
columns. Each cell is then filled with either1.0
or0.0
. The cell at the top-left is always1.0
. Its right and bottom neighbour cells are0.0
. The 4-neighbours of any cell always have a value opposite to the cell’s value (0.0
vs.1.0
).This class is a thin wrapper around
BlendAlphaMask
together withCheckerboardMaskGen
.Note
Avoid using augmenters as children that affect pixel locations (e.g. horizontal flips). See
BlendAlphaMask
for details.Added in 0.4.0.
Supported dtypes:
See
BlendAlphaMask
.Parameters: nb_rows (int or tuple of int or list of int or imgaug.parameters.StochasticParameter) – Number of rows of the checkerboard. See
CheckerboardMaskGen
for details.nb_cols (int or tuple of int or list of int or imgaug.parameters.StochasticParameter) – Number of columns of the checkerboard. Analogous to nb_rows. See
CheckerboardMaskGen
for details.foreground (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) that make up the foreground branch. High alpha values will show this branch’s results.
- If
None
, then the input images will be reused as the output of the foreground branch. - If
Augmenter
, then that augmenter will be used as the branch. - If iterable of
Augmenter
, then that iterable will be converted into aSequential
and used as the augmenter.
- If
background (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) that make up the background branch. Low alpha values will show this branch’s results.
- If
None
, then the input images will be reused as the output of the background branch. - If
Augmenter
, then that augmenter will be used as the branch. - If iterable of
Augmenter
, then that iterable will be converted into aSequential
and used as the augmenter.
- If
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.BlendAlphaCheckerboard(nb_rows=2, nb_cols=(1, 4), >>> foreground=iaa.AddToHue((-100, 100)))
Create an augmenter that places a
HxW
grid on each image, whereH
(rows) is always2
andW
is randomly and uniformly sampled from the interval[1, 4]
. For half of the cells in the grid the hue is randomly modified, the other half of the cells is unaltered.Methods
__call__
(self, \*args, \*\*kwargs)Alias for augment()
.augment
(self[, return_batch, hooks])Augment a batch. augment_batch
(self, batch[, hooks])Deprecated. augment_batch_
(self, batch[, parents, hooks])Augment a single batch in-place. augment_batches
(self, batches[, hooks, …])Augment multiple batches. augment_bounding_boxes
(self, …[, parents, …])Augment a batch of bounding boxes. augment_heatmaps
(self, heatmaps[, parents, …])Augment a batch of heatmaps. augment_image
(self, image[, hooks])Augment a single image. augment_images
(self, images[, parents, hooks])Augment a batch of images. augment_keypoints
(self, keypoints_on_images)Augment a batch of keypoints/landmarks. augment_line_strings
(self, …[, parents, hooks])Augment a batch of line strings. augment_polygons
(self, polygons_on_images[, …])Augment a batch of polygons. augment_segmentation_maps
(self, segmaps[, …])Augment a batch of segmentation maps. copy
(self)Create a shallow copy of this Augmenter instance. copy_random_state
(self, source[, recursive, …])Copy the RNGs from a source augmenter sequence. copy_random_state_
(self, source[, …])Copy the RNGs from a source augmenter sequence (in-place). deepcopy
(self)Create a deep copy of this Augmenter instance. draw_grid
(self, images, rows, cols)Augment images and draw the results as a single grid-like image. find_augmenters
(self, func[, parents, flat])Find augmenters that match a condition. find_augmenters_by_name
(self, name[, regex, …])Find augmenter(s) by name. find_augmenters_by_names
(self, names[, …])Find augmenter(s) by names. get_all_children
(self[, flat])Get all children of this augmenter as a list. get_children_lists
(self)See get_children_lists()
.get_parameters
(self)See get_parameters()
.localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one.
-
class
imgaug.augmenters.blend.
BlendAlphaElementwise
(factor=(0.0, 1.0), foreground=None, background=None, per_channel=False, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.blend.BlendAlphaMask
Alpha-blend two image sources using alpha/opacity values sampled per pixel.
This is the same as
BlendAlpha
, except that the opacity factor is sampled once per pixel instead of once per image (or a few times per image, ifBlendAlpha.per_channel
is set toTrue
).See
BlendAlpha
for more details.This class is a wrapper around
BlendAlphaMask
.Note
Avoid using augmenters as children that affect pixel locations (e.g. horizontal flips). See
BlendAlphaMask
for details.Added in 0.4.0. (Before that named AlphaElementwise.)
Supported dtypes:
See
BlendAlphaMask
.Parameters: factor (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Opacity of the results of the foreground branch. Values close to
0.0
mean that the results from the background branch (see parameter background) make up most of the final image.- If float, then that value will be used for all images.
- If tuple
(a, b)
, then a random value from the interval[a, b]
will be sampled per image. - If a list, then a random value will be picked from that list per image.
- If
StochasticParameter
, then that parameter will be used to sample a value per image.
foreground (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) that make up the foreground branch. High alpha values will show this branch’s results.
- If
None
, then the input images will be reused as the output of the foreground branch. - If
Augmenter
, then that augmenter will be used as the branch. - If iterable of
Augmenter
, then that iterable will be converted into aSequential
and used as the augmenter.
- If
background (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) that make up the background branch. Low alpha values will show this branch’s results.
- If
None
, then the input images will be reused as the output of the background branch. - If
Augmenter
, then that augmenter will be used as the branch. - If iterable of
Augmenter
, then that iterable will be converted into aSequential
and used as the augmenter.
- If
per_channel (bool or float, optional) – Whether to use the same factor for all channels (
False
) or to sample a new value for each channel (True
). If this value is a floatp
, then forp
percent of all images per_channel will be treated as True, otherwise as False.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.BlendAlphaElementwise(0.5, iaa.Grayscale(1.0))
Convert each image to pure grayscale and alpha-blend the result with the original image using an alpha of
50%
for all pixels, thereby removing about50%
of all color. This is equivalent toiaa.Grayscale(0.5)
. This is also equivalent toiaa.BlendAlpha(0.5, iaa.Grayscale(1.0))
, as the opacity has a fixed value of0.5
and is hence identical for all pixels.>>> aug = iaa.BlendAlphaElementwise((0, 1.0), iaa.AddToHue(100))
Same as in the previous example, but here with hue-shift instead of grayscaling and additionally the alpha factor is sampled uniformly from the interval
[0.0, 1.0]
once per pixel, thereby shifting the hue by a random fraction for each pixel.>>> aug = iaa.BlendAlphaElementwise( >>> (0.0, 1.0), >>> iaa.Affine(rotate=(-20, 20)), >>> per_channel=0.5)
First, rotate each image by a random degree sampled uniformly from the interval
[-20, 20]
. Then, alpha-blend that new image with the original one using a random factor sampled uniformly from the interval[0.0, 1.0]
per pixel. For50%
of all images, the blending happens channel-wise and the factor is sampled independently per pixel and channel (per_channel=0.5
). As a result, e.g. the red channel may look visibly rotated (factor near1.0
), while the green and blue channels may not look rotated (factors near0.0
).>>> aug = iaa.BlendAlphaElementwise( >>> (0.0, 1.0), >>> foreground=iaa.Add(100), >>> background=iaa.Multiply(0.2))
Apply two branches of augmenters –
A
andB
– independently to input images and alpha-blend the results of these branches using a factorf
. BranchA
increases image pixel intensities by100
andB
multiplies the pixel intensities by0.2
.f
is sampled uniformly from the interval[0.0, 1.0]
per pixel. The resulting images contain a bit ofA
and a bit ofB
.>>> aug = iaa.BlendAlphaElementwise([0.25, 0.75], iaa.MedianBlur(13))
Apply median blur to each image and alpha-blend the result with the original image using an alpha factor of either exactly
0.25
or exactly0.75
(sampled once per pixel).Attributes: - factor
Methods
__call__
(self, \*args, \*\*kwargs)Alias for augment()
.augment
(self[, return_batch, hooks])Augment a batch. augment_batch
(self, batch[, hooks])Deprecated. augment_batch_
(self, batch[, parents, hooks])Augment a single batch in-place. augment_batches
(self, batches[, hooks, …])Augment multiple batches. augment_bounding_boxes
(self, …[, parents, …])Augment a batch of bounding boxes. augment_heatmaps
(self, heatmaps[, parents, …])Augment a batch of heatmaps. augment_image
(self, image[, hooks])Augment a single image. augment_images
(self, images[, parents, hooks])Augment a batch of images. augment_keypoints
(self, keypoints_on_images)Augment a batch of keypoints/landmarks. augment_line_strings
(self, …[, parents, hooks])Augment a batch of line strings. augment_polygons
(self, polygons_on_images[, …])Augment a batch of polygons. augment_segmentation_maps
(self, segmaps[, …])Augment a batch of segmentation maps. copy
(self)Create a shallow copy of this Augmenter instance. copy_random_state
(self, source[, recursive, …])Copy the RNGs from a source augmenter sequence. copy_random_state_
(self, source[, …])Copy the RNGs from a source augmenter sequence (in-place). deepcopy
(self)Create a deep copy of this Augmenter instance. draw_grid
(self, images, rows, cols)Augment images and draw the results as a single grid-like image. find_augmenters
(self, func[, parents, flat])Find augmenters that match a condition. find_augmenters_by_name
(self, name[, regex, …])Find augmenter(s) by name. find_augmenters_by_names
(self, names[, …])Find augmenter(s) by names. get_all_children
(self[, flat])Get all children of this augmenter as a list. get_children_lists
(self)See get_children_lists()
.get_parameters
(self)See get_parameters()
.localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one. -
factor
¶
-
class
imgaug.augmenters.blend.
BlendAlphaFrequencyNoise
(exponent=(-4, 4), foreground=None, background=None, per_channel=False, size_px_max=(4, 16), upscale_method=None, iterations=(1, 3), aggregation_method=['avg', 'max'], sigmoid=0.5, sigmoid_thresh=None, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.blend.BlendAlphaElementwise
Alpha-blend two image sources using frequency noise masks.
The alpha masks are sampled using frequency noise of varying scales, which can sometimes create large connected blobs of
1
s surrounded by0
s and other times results in smaller patterns. If nearest neighbour upsampling is used, these blobs can be rectangular with sharp edges.Added in 0.4.0. (Before that named FrequencyNoiseAlpha.)
Supported dtypes:
Parameters: exponent (number or tuple of number of list of number or imgaug.parameters.StochasticParameter, optional) – Exponent to use when scaling in the frequency domain. Sane values are in the range
-4
(large blobs) to4
(small patterns). To generate cloud-like structures, use roughly-2
.- If number, then that number will be used as the exponent for all iterations.
- If tuple of two numbers
(a, b)
, then a value will be sampled per iteration from the interval[a, b]
. - If a list of numbers, then a value will be picked per iteration at random from that list.
- If a
StochasticParameter
, then a value will be sampled from that parameter per iteration.
foreground (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) that make up the foreground branch. High alpha values will show this branch’s results.
- If
None
, then the input images will be reused as the output of the foreground branch. - If
Augmenter
, then that augmenter will be used as the branch. - If iterable of
Augmenter
, then that iterable will be converted into aSequential
and used as the augmenter.
- If
background (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) that make up the background branch. Low alpha values will show this branch’s results.
- If
None
, then the input images will be reused as the output of the background branch. - If
Augmenter
, then that augmenter will be used as the branch. - If iterable of
Augmenter
, then that iterable will be converted into aSequential
and used as the augmenter.
- If
per_channel (bool or float, optional) – Whether to use the same factor for all channels (
False
) or to sample a new value for each channel (True
). If this value is a floatp
, then forp
percent of all images per_channel will be treated asTrue
, otherwise asFalse
.size_px_max (int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – The noise is generated in a low resolution environment. This parameter defines the maximum size of that environment (in pixels). The environment is initialized at the same size as the input image and then downscaled, so that no side exceeds size_px_max (aspect ratio is kept).
- If
int
, then that number will be used as the size for all iterations. - If tuple of two
int
s(a, b)
, then a value will be sampled per iteration from the discrete interval[a..b]
. - If a list of
int
s, then a value will be picked per iteration at random from that list. - If a
StochasticParameter
, then a value will be sampled from that parameter per iteration.
- If
upscale_method (None or imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional) – After generating the noise maps in low resolution environments, they have to be upscaled to the input image size. This parameter controls the upscaling method.
- If
None
, then eithernearest
orlinear
orcubic
is picked. Most weight is put onlinear
, followed bycubic
. - If
imgaug.ALL
, then eithernearest
orlinear
orarea
orcubic
is picked per iteration (all same probability). - If string, then that value will be used as the method (must be
nearest
orlinear
orarea
orcubic
). - If list of string, then a random value will be picked from that list per iteration.
- If
StochasticParameter
, then a random value will be sampled from that parameter per iteration.
- If
iterations (int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – How often to repeat the simplex noise generation process per image.
- If
int
, then that number will be used as the iterations for all images. - If tuple of two
int
s(a, b)
, then a value will be sampled per image from the discrete interval[a..b]
. - If a list of
int
s, then a value will be picked per image at random from that list. - If a
StochasticParameter
, then a value will be sampled from that parameter per image.
- If
aggregation_method (imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional) – The noise maps (from each iteration) are combined to one noise map using an aggregation process. This parameter defines the method used for that process. Valid methods are
min
,max
oravg
, where ‘min’ combines the noise maps by taking the (elementwise) minimum over all iteration’s results,max
the (elementwise) maximum andavg
the (elementwise) average.- If
imgaug.ALL
, then a random value will be picked per image from the valid ones. - If a string, then that value will always be used as the method.
- If a list of string, then a random value will be picked from that list per image.
- If a
StochasticParameter
, then a random value will be sampled from that parameter per image.
- If
sigmoid (bool or number, optional) – Whether to apply a sigmoid function to the final noise maps, resulting in maps that have more extreme values (close to
0.0
or1.0
).- If
bool
, then a sigmoid will always (True
) or never (False
) be applied. - If a number
p
with0<=p<=1
, then a sigmoid will be applied top
percent of all final noise maps.
- If
sigmoid_thresh (None or number or tuple of number or imgaug.parameters.StochasticParameter, optional) – Threshold of the sigmoid, when applied. Thresholds above zero (e.g.
5.0
) will move the saddle point towards the right, leading to more values close to0.0
.- If
None
, thenNormal(0, 5.0)
will be used. - If number, then that threshold will be used for all images.
- If tuple of two numbers
(a, b)
, then a random value will be sampled per image from the range[a, b]
. - If
StochasticParameter
, then a random value will be sampled from that parameter per image.
- If
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.BlendAlphaFrequencyNoise(foreground=iaa.EdgeDetect(1.0))
Detect per image all edges, mark them in a black and white image and then alpha-blend the result with the original image using frequency noise masks.
>>> aug = iaa.BlendAlphaFrequencyNoise( >>> foreground=iaa.EdgeDetect(1.0), >>> upscale_method="nearest")
Same as the first example, but using only linear upscaling to scale the frequency noise masks to the final image sizes, i.e. no nearest neighbour upsampling is used. This results in smooth edges.
>>> aug = iaa.BlendAlphaFrequencyNoise( >>> foreground=iaa.EdgeDetect(1.0), >>> upscale_method="linear")
Same as the first example, but using only linear upscaling to scale the frequency noise masks to the final image sizes, i.e. no nearest neighbour upsampling is used. This results in smooth edges.
>>> aug = iaa.BlendAlphaFrequencyNoise( >>> foreground=iaa.EdgeDetect(1.0), >>> upscale_method="linear", >>> exponent=-2, >>> sigmoid=False)
Same as in the previous example, but with the exponent set to a constant
-2
and the sigmoid deactivated, resulting in cloud-like patterns without sharp edges.>>> aug = iaa.BlendAlphaFrequencyNoise( >>> foreground=iaa.EdgeDetect(1.0), >>> sigmoid_thresh=iap.Normal(10.0, 5.0))
Same as the first example, but using a threshold for the sigmoid function that is further to the right. This is more conservative, i.e. the generated noise masks will be mostly black (values around
0.0
), which means that most of the original images (parameter/branch background) will be kept, rather than using the results of the augmentation (parameter/branch foreground).Attributes: - factor
Methods
__call__
(self, \*args, \*\*kwargs)Alias for augment()
.augment
(self[, return_batch, hooks])Augment a batch. augment_batch
(self, batch[, hooks])Deprecated. augment_batch_
(self, batch[, parents, hooks])Augment a single batch in-place. augment_batches
(self, batches[, hooks, …])Augment multiple batches. augment_bounding_boxes
(self, …[, parents, …])Augment a batch of bounding boxes. augment_heatmaps
(self, heatmaps[, parents, …])Augment a batch of heatmaps. augment_image
(self, image[, hooks])Augment a single image. augment_images
(self, images[, parents, hooks])Augment a batch of images. augment_keypoints
(self, keypoints_on_images)Augment a batch of keypoints/landmarks. augment_line_strings
(self, …[, parents, hooks])Augment a batch of line strings. augment_polygons
(self, polygons_on_images[, …])Augment a batch of polygons. augment_segmentation_maps
(self, segmaps[, …])Augment a batch of segmentation maps. copy
(self)Create a shallow copy of this Augmenter instance. copy_random_state
(self, source[, recursive, …])Copy the RNGs from a source augmenter sequence. copy_random_state_
(self, source[, …])Copy the RNGs from a source augmenter sequence (in-place). deepcopy
(self)Create a deep copy of this Augmenter instance. draw_grid
(self, images, rows, cols)Augment images and draw the results as a single grid-like image. find_augmenters
(self, func[, parents, flat])Find augmenters that match a condition. find_augmenters_by_name
(self, name[, regex, …])Find augmenter(s) by name. find_augmenters_by_names
(self, names[, …])Find augmenter(s) by names. get_all_children
(self[, flat])Get all children of this augmenter as a list. get_children_lists
(self)See get_children_lists()
.get_parameters
(self)See get_parameters()
.localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one.
-
class
imgaug.augmenters.blend.
BlendAlphaHorizontalLinearGradient
(foreground=None, background=None, min_value=(0.0, 0.2), max_value=(0.8, 1.0), start_at=(0.0, 0.2), end_at=(0.8, 1.0), seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.blend.BlendAlphaMask
Blend images from two branches along a horizontal linear gradient.
This class generates a horizontal linear gradient mask (i.e. usually a mask with low values on the left and high values on the right) and alphas-blends between foreground and background branch using that mask.
This class is a thin wrapper around
BlendAlphaMask
together withHorizontalLinearGradientMaskGen
.Note
Avoid using augmenters as children that affect pixel locations (e.g. horizontal flips). See
BlendAlphaMask
for details.Added in 0.4.0.
Supported dtypes:
See
BlendAlphaMask
.Parameters: foreground (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) that make up the foreground branch. High alpha values will show this branch’s results.
- If
None
, then the input images will be reused as the output of the foreground branch. - If
Augmenter
, then that augmenter will be used as the branch. - If iterable of
Augmenter
, then that iterable will be converted into aSequential
and used as the augmenter.
- If
background (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) that make up the background branch. Low alpha values will show this branch’s results.
- If
None
, then the input images will be reused as the output of the background branch. - If
Augmenter
, then that augmenter will be used as the branch. - If iterable of
Augmenter
, then that iterable will be converted into aSequential
and used as the augmenter.
- If
min_value (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See
HorizontalLinearGradientMaskGen
.max_value (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See
HorizontalLinearGradientMaskGen
.start_at (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See
HorizontalLinearGradientMaskGen
.end_at (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See
HorizontalLinearGradientMaskGen
.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.BlendAlphaHorizontalLinearGradient(iaa.AddToHue((-100, 100)))
Create an augmenter that randomizes the hue towards the right of the image.
>>> aug = iaa.BlendAlphaHorizontalLinearGradient( >>> iaa.TotalDropout(1.0), >>> min_value=0.2, max_value=0.8)
Create an augmenter that replaces pixels towards the right with darker and darker values. However it always keeps at least 20% (
1.0 - max_value
) of the original pixel value on the far right and always replaces at least 20% on the far left (min_value=0.2
).>>> aug = iaa.BlendAlphaHorizontalLinearGradient( >>> iaa.AveragePooling(11), >>> start_at=(0.0, 1.0), end_at=(0.0, 1.0))
Create an augmenter that blends with an average-pooled image according to a horizontal gradient that starts at a random x-coordinate and reaches its maximum at another random x-coordinate. Due to that randomness, the gradient may increase towards the left or right.
Methods
__call__
(self, \*args, \*\*kwargs)Alias for augment()
.augment
(self[, return_batch, hooks])Augment a batch. augment_batch
(self, batch[, hooks])Deprecated. augment_batch_
(self, batch[, parents, hooks])Augment a single batch in-place. augment_batches
(self, batches[, hooks, …])Augment multiple batches. augment_bounding_boxes
(self, …[, parents, …])Augment a batch of bounding boxes. augment_heatmaps
(self, heatmaps[, parents, …])Augment a batch of heatmaps. augment_image
(self, image[, hooks])Augment a single image. augment_images
(self, images[, parents, hooks])Augment a batch of images. augment_keypoints
(self, keypoints_on_images)Augment a batch of keypoints/landmarks. augment_line_strings
(self, …[, parents, hooks])Augment a batch of line strings. augment_polygons
(self, polygons_on_images[, …])Augment a batch of polygons. augment_segmentation_maps
(self, segmaps[, …])Augment a batch of segmentation maps. copy
(self)Create a shallow copy of this Augmenter instance. copy_random_state
(self, source[, recursive, …])Copy the RNGs from a source augmenter sequence. copy_random_state_
(self, source[, …])Copy the RNGs from a source augmenter sequence (in-place). deepcopy
(self)Create a deep copy of this Augmenter instance. draw_grid
(self, images, rows, cols)Augment images and draw the results as a single grid-like image. find_augmenters
(self, func[, parents, flat])Find augmenters that match a condition. find_augmenters_by_name
(self, name[, regex, …])Find augmenter(s) by name. find_augmenters_by_names
(self, names[, …])Find augmenter(s) by names. get_all_children
(self[, flat])Get all children of this augmenter as a list. get_children_lists
(self)See get_children_lists()
.get_parameters
(self)See get_parameters()
.localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one.
-
class
imgaug.augmenters.blend.
BlendAlphaMask
(mask_generator, foreground=None, background=None, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.meta.Augmenter
Alpha-blend two image sources using non-binary masks generated per image.
This augmenter queries for each image a mask generator to generate a
(H,W)
or(H,W,C)
channelwise mask[0.0, 1.0]
, whereH
is the image height andW
the width. The mask will then be used to alpha-blend pixel- and possibly channel-wise between a foreground branch of augmenters and a background branch. (Both branches default to the identity operation if not provided.)See also
BlendAlpha
.Note
It is not recommended to use
BlendAlphaMask
with augmenters that change the geometry of images (e.g. horizontal flips, affine transformations) if you also want to augment coordinates (e.g. keypoints, polygons, …), as it is unclear which of the two coordinate results (foreground or background branch) should be used as the final output coordinates after augmentation.Currently, for keypoints the results of the foreground and background branch will be mixed. That means that for each coordinate the augmented result will be picked from the foreground or background branch based on the average alpha mask value at the corresponding spatial location.
For bounding boxes, line strings and polygons, either all objects (on an image) of the foreground or all of the background branch will be used, based on the average over the whole alpha mask.
Added in 0.4.0.
Supported dtypes:
See
blend_alpha()
.Parameters: mask_generator (IBatchwiseMaskGenerator) – A generator that will be queried per image to generate a mask.
foreground (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) that make up the foreground branch. High alpha values will show this branch’s results.
- If
None
, then the input images will be reused as the output of the foreground branch (i.e. identity function). - If
Augmenter
, then that augmenter will be used as the branch. - If iterable of
Augmenter
, then that iterable will be converted into aSequential
and used as the augmenter.
- If
background (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) that make up the background branch. Low alpha values will show this branch’s results.
- If
None
, then the input images will be reused as the output of the background branch (i.e. identity function). - If
Augmenter
, then that augmenter will be used as the branch. - If iterable of
Augmenter
, then that iterable will be converted into aSequential
and used as the augmenter.
- If
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.BlendAlphaMask( >>> iaa.InvertMaskGen(0.5, iaa.VerticalLinearGradientMaskGen()), >>> iaa.Sequential([ >>> iaa.Clouds(), >>> iaa.WithChannels([1, 2], iaa.Multiply(0.5)) >>> ]) >>> )
Create an augmenter that sometimes adds clouds at the bottom and sometimes at the top of the 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)See get_children_lists()
.get_parameters
(self)See get_parameters()
.localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one. -
get_children_lists
(self)[source]¶ See
get_children_lists()
.
-
get_parameters
(self)[source]¶ See
get_parameters()
.
-
class
imgaug.augmenters.blend.
BlendAlphaRegularGrid
(nb_rows, nb_cols, foreground=None, background=None, alpha=[0.0, 1.0], seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.blend.BlendAlphaMask
Blend images from two branches according to a regular grid.
This class generates for each image a mask that splits the image into a grid-like pattern of
H
rows andW
columns. Each cell is then filled with an alpha value, sampled randomly per cell.The difference to
AlphaBlendCheckerboard
is that this class samples random alpha values per grid cell, while in the checkerboard the alpha values follow a fixed pattern.This class is a thin wrapper around
BlendAlphaMask
together withRegularGridMaskGen
.Note
Avoid using augmenters as children that affect pixel locations (e.g. horizontal flips). See
BlendAlphaMask
for details.Added in 0.4.0.
Supported dtypes:
See
BlendAlphaMask
.Parameters: nb_rows (int or tuple of int or list of int or imgaug.parameters.StochasticParameter) – Number of rows of the checkerboard. See
CheckerboardMaskGen
for details.nb_cols (int or tuple of int or list of int or imgaug.parameters.StochasticParameter) – Number of columns of the checkerboard. Analogous to nb_rows. See
CheckerboardMaskGen
for details.foreground (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) that make up the foreground branch. High alpha values will show this branch’s results.
- If
None
, then the input images will be reused as the output of the foreground branch. - If
Augmenter
, then that augmenter will be used as the branch. - If iterable of
Augmenter
, then that iterable will be converted into aSequential
and used as the augmenter.
- If
background (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) that make up the background branch. Low alpha values will show this branch’s results.
- If
None
, then the input images will be reused as the output of the background branch. - If
Augmenter
, then that augmenter will be used as the branch. - If iterable of
Augmenter
, then that iterable will be converted into aSequential
and used as the augmenter.
- If
alpha (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Alpha value of each cell.
- If
number
: Exactly that value will be used for all images. - If
tuple
(a, b)
: A random value will be uniformly sampled per image from the interval[a, b]
. - If
list
: A random value will be picked per image from that list. - If
StochasticParameter
: That parameter will be queried once per batch for(N,)
values – one per image.
- If
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.BlendAlphaRegularGrid(nb_rows=(4, 6), nb_cols=(1, 4), >>> foreground=iaa.Multiply(0.0))
Create an augmenter that places a
HxW
grid on each image, whereH
(rows) is randomly and uniformly sampled from the interval[4, 6]
andW
is analogously sampled from the interval[1, 4]
. Roughly half of the cells in the grid are filled with0.0
, the remaining ones are unaltered. Which cells exactly are “dropped” is randomly decided per image. The resulting effect is similar toCoarseDropout
.>>> aug = iaa.BlendAlphaRegularGrid(nb_rows=2, nb_cols=2, >>> foreground=iaa.Multiply(0.0), >>> background=iaa.AveragePooling(8), >>> alpha=[0.0, 0.0, 1.0])
Create an augmenter that always placed
2x2
cells on each image and sets about1/3
of them to zero (foreground branch) and the remaining2/3
to a pixelated version (background branch).Methods
__call__
(self, \*args, \*\*kwargs)Alias for augment()
.augment
(self[, return_batch, hooks])Augment a batch. augment_batch
(self, batch[, hooks])Deprecated. augment_batch_
(self, batch[, parents, hooks])Augment a single batch in-place. augment_batches
(self, batches[, hooks, …])Augment multiple batches. augment_bounding_boxes
(self, …[, parents, …])Augment a batch of bounding boxes. augment_heatmaps
(self, heatmaps[, parents, …])Augment a batch of heatmaps. augment_image
(self, image[, hooks])Augment a single image. augment_images
(self, images[, parents, hooks])Augment a batch of images. augment_keypoints
(self, keypoints_on_images)Augment a batch of keypoints/landmarks. augment_line_strings
(self, …[, parents, hooks])Augment a batch of line strings. augment_polygons
(self, polygons_on_images[, …])Augment a batch of polygons. augment_segmentation_maps
(self, segmaps[, …])Augment a batch of segmentation maps. copy
(self)Create a shallow copy of this Augmenter instance. copy_random_state
(self, source[, recursive, …])Copy the RNGs from a source augmenter sequence. copy_random_state_
(self, source[, …])Copy the RNGs from a source augmenter sequence (in-place). deepcopy
(self)Create a deep copy of this Augmenter instance. draw_grid
(self, images, rows, cols)Augment images and draw the results as a single grid-like image. find_augmenters
(self, func[, parents, flat])Find augmenters that match a condition. find_augmenters_by_name
(self, name[, regex, …])Find augmenter(s) by name. find_augmenters_by_names
(self, names[, …])Find augmenter(s) by names. get_all_children
(self[, flat])Get all children of this augmenter as a list. get_children_lists
(self)See get_children_lists()
.get_parameters
(self)See get_parameters()
.localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one.
-
class
imgaug.augmenters.blend.
BlendAlphaSegMapClassIds
(class_ids, foreground=None, background=None, nb_sample_classes=None, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.blend.BlendAlphaMask
Blend images from two branches based on segmentation map ids.
This class generates masks that are
1.0
at pixel locations covered by specific classes in segmentation maps.This class is a thin wrapper around
BlendAlphaMask
together withSegMapClassIdsMaskGen
.Note
Avoid using augmenters as children that affect pixel locations (e.g. horizontal flips). See
BlendAlphaMask
for details.Note
Segmentation maps can have multiple channels. If that is the case then for each position
(x, y)
it is sufficient that any class id in any channel matches one of the desired class ids.Note
This class will produce an
AssertionError
if there are no segmentation maps in a batch.Added in 0.4.0.
Supported dtypes:
See
BlendAlphaMask
.Parameters: class_ids (int or tuple of int or list of int or imgaug.parameters.StochasticParameter) – See
SegMapClassIdsMaskGen
.foreground (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) that make up the foreground branch. High alpha values will show this branch’s results.
- If
None
, then the input images will be reused as the output of the foreground branch. - If
Augmenter
, then that augmenter will be used as the branch. - If iterable of
Augmenter
, then that iterable will be converted into aSequential
and used as the augmenter.
- If
background (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) that make up the background branch. Low alpha values will show this branch’s results.
- If
None
, then the input images will be reused as the output of the background branch. - If
Augmenter
, then that augmenter will be used as the branch. - If iterable of
Augmenter
, then that iterable will be converted into aSequential
and used as the augmenter.
- If
nb_sample_classes (None or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – See
SegMapClassIdsMaskGen
.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.BlendAlphaSegMapClassIds( >>> [1, 3], >>> foreground=iaa.AddToHue((-100, 100)))
Create an augmenter that randomizes the hue wherever the segmentation maps contain the classes
1
or3
.>>> aug = iaa.BlendAlphaSegMapClassIds( >>> [1, 2, 3, 4], >>> nb_sample_classes=2, >>> foreground=iaa.GaussianBlur(3.0))
Create an augmenter that randomly picks
2
classes from the list[1, 2, 3, 4]
and blurs the image content wherever these classes appear in the segmentation map. Note that as the sampling of class ids happens with replacement, it is not guaranteed to sample two unique class ids.>>> aug = iaa.Sometimes(0.2, >>> iaa.BlendAlphaSegMapClassIds( >>> 2, >>> background=iaa.TotalDropout(1.0)))
Create an augmenter that zeros for roughly every fifth image all image pixels that do not belong to class id
2
(note that the background branch was used, not the foreground branch). Example use case: Human body landmark detection where both the landmarks/keypoints and the body segmentation map are known. Train the model to detect landmarks and sometimes remove all non-body information to force the model to become more independent of the background.Methods
__call__
(self, \*args, \*\*kwargs)Alias for augment()
.augment
(self[, return_batch, hooks])Augment a batch. augment_batch
(self, batch[, hooks])Deprecated. augment_batch_
(self, batch[, parents, hooks])Augment a single batch in-place. augment_batches
(self, batches[, hooks, …])Augment multiple batches. augment_bounding_boxes
(self, …[, parents, …])Augment a batch of bounding boxes. augment_heatmaps
(self, heatmaps[, parents, …])Augment a batch of heatmaps. augment_image
(self, image[, hooks])Augment a single image. augment_images
(self, images[, parents, hooks])Augment a batch of images. augment_keypoints
(self, keypoints_on_images)Augment a batch of keypoints/landmarks. augment_line_strings
(self, …[, parents, hooks])Augment a batch of line strings. augment_polygons
(self, polygons_on_images[, …])Augment a batch of polygons. augment_segmentation_maps
(self, segmaps[, …])Augment a batch of segmentation maps. copy
(self)Create a shallow copy of this Augmenter instance. copy_random_state
(self, source[, recursive, …])Copy the RNGs from a source augmenter sequence. copy_random_state_
(self, source[, …])Copy the RNGs from a source augmenter sequence (in-place). deepcopy
(self)Create a deep copy of this Augmenter instance. draw_grid
(self, images, rows, cols)Augment images and draw the results as a single grid-like image. find_augmenters
(self, func[, parents, flat])Find augmenters that match a condition. find_augmenters_by_name
(self, name[, regex, …])Find augmenter(s) by name. find_augmenters_by_names
(self, names[, …])Find augmenter(s) by names. get_all_children
(self[, flat])Get all children of this augmenter as a list. get_children_lists
(self)See get_children_lists()
.get_parameters
(self)See get_parameters()
.localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one.
-
class
imgaug.augmenters.blend.
BlendAlphaSimplexNoise
(foreground=None, background=None, per_channel=False, size_px_max=(2, 16), upscale_method=None, iterations=(1, 3), aggregation_method='max', sigmoid=True, sigmoid_thresh=None, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.blend.BlendAlphaElementwise
Alpha-blend two image sources using simplex noise alpha masks.
The alpha masks are sampled using a simplex noise method, roughly creating connected blobs of 1s surrounded by 0s. If nearest neighbour upsampling is used, these blobs can be rectangular with sharp edges.
Added in 0.4.0. (Before that named SimplexNoiseAlpha.)
Supported dtypes:
Parameters: foreground (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) that make up the foreground branch. High alpha values will show this branch’s results.
- If
None
, then the input images will be reused as the output of the foreground branch. - If
Augmenter
, then that augmenter will be used as the branch. - If iterable of
Augmenter
, then that iterable will be converted into aSequential
and used as the augmenter.
- If
background (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) that make up the background branch. Low alpha values will show this branch’s results.
- If
None
, then the input images will be reused as the output of the background branch. - If
Augmenter
, then that augmenter will be used as the branch. - If iterable of
Augmenter
, then that iterable will be converted into aSequential
and used as the augmenter.
- If
per_channel (bool or float, optional) – Whether to use the same factor for all channels (
False
) or to sample a new value for each channel (True
). If this value is a floatp
, then forp
percent of all images per_channel will be treated asTrue
, otherwise asFalse
.size_px_max (int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – The simplex noise is always generated in a low resolution environment. This parameter defines the maximum size of that environment (in pixels). The environment is initialized at the same size as the input image and then downscaled, so that no side exceeds size_px_max (aspect ratio is kept).
- If int, then that number will be used as the size for all iterations.
- If tuple of two
int
s(a, b)
, then a value will be sampled per iteration from the discrete interval[a..b]
. - If a list of
int
s, then a value will be picked per iteration at random from that list. - If a
StochasticParameter
, then a value will be sampled from that parameter per iteration.
upscale_method (None or imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional) – After generating the noise maps in low resolution environments, they have to be upscaled to the input image size. This parameter controls the upscaling method.
- If
None
, then eithernearest
orlinear
orcubic
is picked. Most weight is put onlinear
, followed bycubic
. - If
imgaug.ALL
, then eithernearest
orlinear
orarea
orcubic
is picked per iteration (all same probability). - If a string, then that value will be used as the method (must be
nearest
orlinear
orarea
orcubic
). - If list of string, then a random value will be picked from that list per iteration.
- If
StochasticParameter
, then a random value will be sampled from that parameter per iteration.
- If
iterations (int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) –
How often to repeat the simplex noise generation process per image.
- If
int
, then that number will be used as the iterations for all images. - If tuple of two
int
s(a, b)
, then a value will be sampled per image from the discrete interval[a..b]
. - If a list of
int
s, then a value will be picked per image at random from that list. - If a
StochasticParameter
, then a value will be sampled from that parameter per image.
- If
aggregation_method (imgaug.ALL or str or list of str or imgaug.parameters.StochasticParameter, optional) – The noise maps (from each iteration) are combined to one noise map using an aggregation process. This parameter defines the method used for that process. Valid methods are
min
,max
oravg
, wheremin
combines the noise maps by taking the (elementwise) minimum over all iteration’s results,max
the (elementwise) maximum andavg
the (elementwise) average.- If
imgaug.ALL
, then a random value will be picked per image from the valid ones. - If a string, then that value will always be used as the method.
- If a list of string, then a random value will be picked from that list per image.
- If a
StochasticParameter
, then a random value will be sampled from that paramter per image.
- If
sigmoid (bool or number, optional) – Whether to apply a sigmoid function to the final noise maps, resulting in maps that have more extreme values (close to 0.0 or 1.0).
- If
bool
, then a sigmoid will always (True
) or never (False
) be applied. - If a number
p
with0<=p<=1
, then a sigmoid will be applied top
percent of all final noise maps.
- If
sigmoid_thresh (None or number or tuple of number or imgaug.parameters.StochasticParameter, optional) – Threshold of the sigmoid, when applied. Thresholds above zero (e.g.
5.0
) will move the saddle point towards the right, leading to more values close to 0.0.- If
None
, thenNormal(0, 5.0)
will be used. - If number, then that threshold will be used for all images.
- If tuple of two numbers
(a, b)
, then a random value will be sampled per image from the interval[a, b]
. - If
StochasticParameter
, then a random value will be sampled from that parameter per image.
- If
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.BlendAlphaSimplexNoise(iaa.EdgeDetect(1.0))
Detect per image all edges, mark them in a black and white image and then alpha-blend the result with the original image using simplex noise masks.
>>> aug = iaa.BlendAlphaSimplexNoise( >>> iaa.EdgeDetect(1.0), >>> upscale_method="nearest")
Same as in the previous example, but using only nearest neighbour upscaling to scale the simplex noise masks to the final image sizes, i.e. no nearest linear upsampling is used. This leads to rectangles with sharp edges.
>>> aug = iaa.BlendAlphaSimplexNoise( >>> iaa.EdgeDetect(1.0), >>> upscale_method="linear")
Same as in the previous example, but using only linear upscaling to scale the simplex noise masks to the final image sizes, i.e. no nearest neighbour upsampling is used. This leads to rectangles with smooth edges.
>>> aug = iaa.BlendAlphaSimplexNoise( >>> iaa.EdgeDetect(1.0), >>> sigmoid_thresh=iap.Normal(10.0, 5.0))
Same as in the first example, but using a threshold for the sigmoid function that is further to the right. This is more conservative, i.e. the generated noise masks will be mostly black (values around
0.0
), which means that most of the original images (parameter/branch background) will be kept, rather than using the results of the augmentation (parameter/branch foreground).Attributes: - factor
Methods
__call__
(self, \*args, \*\*kwargs)Alias for augment()
.augment
(self[, return_batch, hooks])Augment a batch. augment_batch
(self, batch[, hooks])Deprecated. augment_batch_
(self, batch[, parents, hooks])Augment a single batch in-place. augment_batches
(self, batches[, hooks, …])Augment multiple batches. augment_bounding_boxes
(self, …[, parents, …])Augment a batch of bounding boxes. augment_heatmaps
(self, heatmaps[, parents, …])Augment a batch of heatmaps. augment_image
(self, image[, hooks])Augment a single image. augment_images
(self, images[, parents, hooks])Augment a batch of images. augment_keypoints
(self, keypoints_on_images)Augment a batch of keypoints/landmarks. augment_line_strings
(self, …[, parents, hooks])Augment a batch of line strings. augment_polygons
(self, polygons_on_images[, …])Augment a batch of polygons. augment_segmentation_maps
(self, segmaps[, …])Augment a batch of segmentation maps. copy
(self)Create a shallow copy of this Augmenter instance. copy_random_state
(self, source[, recursive, …])Copy the RNGs from a source augmenter sequence. copy_random_state_
(self, source[, …])Copy the RNGs from a source augmenter sequence (in-place). deepcopy
(self)Create a deep copy of this Augmenter instance. draw_grid
(self, images, rows, cols)Augment images and draw the results as a single grid-like image. find_augmenters
(self, func[, parents, flat])Find augmenters that match a condition. find_augmenters_by_name
(self, name[, regex, …])Find augmenter(s) by name. find_augmenters_by_names
(self, names[, …])Find augmenter(s) by names. get_all_children
(self[, flat])Get all children of this augmenter as a list. get_children_lists
(self)See get_children_lists()
.get_parameters
(self)See get_parameters()
.localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one.
-
class
imgaug.augmenters.blend.
BlendAlphaSomeColors
(foreground=None, background=None, nb_bins=(5, 15), smoothness=(0.1, 0.3), alpha=[0.0, 1.0], rotation_deg=(0, 360), from_colorspace='RGB', seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.blend.BlendAlphaMask
Blend images from two branches using colorwise masks.
This class generates masks that “mark” a few colors and replace the pixels within these colors with the results of the foreground branch. The remaining pixels are replaced with the results of the background branch (usually the identity function). That allows to e.g. selectively grayscale a few colors, while keeping other colors unchanged.
This class is a thin wrapper around
BlendAlphaMask
together withSomeColorsMaskGen
.Note
The underlying mask generator will produce an
AssertionError
for batches that contain no images.Note
Avoid using augmenters as children that affect pixel locations (e.g. horizontal flips). See
BlendAlphaMask
for details.Added in 0.4.0.
Supported dtypes:
Parameters: foreground (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) that make up the foreground branch. High alpha values will show this branch’s results.
- If
None
, then the input images will be reused as the output of the foreground branch. - If
Augmenter
, then that augmenter will be used as the branch. - If iterable of
Augmenter
, then that iterable will be converted into aSequential
and used as the augmenter.
- If
background (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) that make up the background branch. Low alpha values will show this branch’s results.
- If
None
, then the input images will be reused as the output of the background branch. - If
Augmenter
, then that augmenter will be used as the branch. - If iterable of
Augmenter
, then that iterable will be converted into aSequential
and used as the augmenter.
- If
nb_bins (int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – See
SomeColorsMaskGen
.smoothness (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See
SomeColorsMaskGen
.alpha (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See
SomeColorsMaskGen
.rotation_deg (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See
SomeColorsMaskGen
.from_colorspace (str, optional) – See
SomeColorsMaskGen
.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.BlendAlphaSomeColors(iaa.Grayscale(1.0))
Create an augmenter that turns randomly removes some colors in images by grayscaling them.
>>> aug = iaa.BlendAlphaSomeColors(iaa.TotalDropout(1.0))
Create an augmenter that removes some colors in images by replacing them with black pixels.
>>> aug = iaa.BlendAlphaSomeColors( >>> iaa.MultiplySaturation(0.5), iaa.MultiplySaturation(1.5))
Create an augmenter that desaturates some colors and increases the saturation of the remaining ones.
>>> aug = iaa.BlendAlphaSomeColors( >>> iaa.AveragePooling(7), alpha=[0.0, 1.0], smoothness=0.0)
Create an augmenter that applies average pooling to some colors. Each color tune is either selected (alpha of
1.0
) or not selected (0.0
). There is no gradual change between similar colors.>>> aug = iaa.BlendAlphaSomeColors( >>> iaa.AveragePooling(7), nb_bins=2, smoothness=0.0)
Create an augmenter that applies average pooling to some colors. Choose on average half of all colors in images for the blending operation.
>>> aug = iaa.BlendAlphaSomeColors( >>> iaa.AveragePooling(7), from_colorspace="BGR")
Create an augmenter that applies average pooling to some colors with input images being in BGR colorspace.
Methods
__call__
(self, \*args, \*\*kwargs)Alias for augment()
.augment
(self[, return_batch, hooks])Augment a batch. augment_batch
(self, batch[, hooks])Deprecated. augment_batch_
(self, batch[, parents, hooks])Augment a single batch in-place. augment_batches
(self, batches[, hooks, …])Augment multiple batches. augment_bounding_boxes
(self, …[, parents, …])Augment a batch of bounding boxes. augment_heatmaps
(self, heatmaps[, parents, …])Augment a batch of heatmaps. augment_image
(self, image[, hooks])Augment a single image. augment_images
(self, images[, parents, hooks])Augment a batch of images. augment_keypoints
(self, keypoints_on_images)Augment a batch of keypoints/landmarks. augment_line_strings
(self, …[, parents, hooks])Augment a batch of line strings. augment_polygons
(self, polygons_on_images[, …])Augment a batch of polygons. augment_segmentation_maps
(self, segmaps[, …])Augment a batch of segmentation maps. copy
(self)Create a shallow copy of this Augmenter instance. copy_random_state
(self, source[, recursive, …])Copy the RNGs from a source augmenter sequence. copy_random_state_
(self, source[, …])Copy the RNGs from a source augmenter sequence (in-place). deepcopy
(self)Create a deep copy of this Augmenter instance. draw_grid
(self, images, rows, cols)Augment images and draw the results as a single grid-like image. find_augmenters
(self, func[, parents, flat])Find augmenters that match a condition. find_augmenters_by_name
(self, name[, regex, …])Find augmenter(s) by name. find_augmenters_by_names
(self, names[, …])Find augmenter(s) by names. get_all_children
(self[, flat])Get all children of this augmenter as a list. get_children_lists
(self)See get_children_lists()
.get_parameters
(self)See get_parameters()
.localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one.
-
class
imgaug.augmenters.blend.
BlendAlphaVerticalLinearGradient
(foreground=None, background=None, min_value=(0.0, 0.2), max_value=(0.8, 1.0), start_at=(0.0, 0.2), end_at=(0.8, 1.0), seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Bases:
imgaug.augmenters.blend.BlendAlphaMask
Blend images from two branches along a vertical linear gradient.
This class generates a vertical linear gradient mask (i.e. usually a mask with low values on the left and high values on the right) and alphas-blends between foreground and background branch using that mask.
This class is a thin wrapper around
BlendAlphaMask
together withVerticalLinearGradientMaskGen
.Note
Avoid using augmenters as children that affect pixel locations (e.g. horizontal flips). See
BlendAlphaMask
for details.Added in 0.4.0.
Supported dtypes:
See
BlendAlphaMask
.Parameters: foreground (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) that make up the foreground branch. High alpha values will show this branch’s results.
- If
None
, then the input images will be reused as the output of the foreground branch. - If
Augmenter
, then that augmenter will be used as the branch. - If iterable of
Augmenter
, then that iterable will be converted into aSequential
and used as the augmenter.
- If
background (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) – Augmenter(s) that make up the background branch. Low alpha values will show this branch’s results.
- If
None
, then the input images will be reused as the output of the background branch. - If
Augmenter
, then that augmenter will be used as the branch. - If iterable of
Augmenter
, then that iterable will be converted into aSequential
and used as the augmenter.
- If
min_value (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See
VerticalLinearGradientMaskGen
.max_value (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See
VerticalLinearGradientMaskGen
.start_at (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See
VerticalLinearGradientMaskGen
.end_at (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See
VerticalLinearGradientMaskGen
.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.BlendAlphaVerticalLinearGradient(iaa.AddToHue((-100, 100)))
Create an augmenter that randomizes the hue towards the bottom of the image.
>>> aug = iaa.BlendAlphaVerticalLinearGradient( >>> iaa.TotalDropout(1.0), >>> min_value=0.2, max_value=0.8)
Create an augmenter that replaces pixels towards the bottom with darker and darker values. However it always keeps at least 20% (
1.0 - max_value
) of the original pixel value on the far bottom and always replaces at least 20% on the far top (min_value=0.2
).>>> aug = iaa.BlendAlphaVerticalLinearGradient( >>> iaa.AveragePooling(11), >>> start_at=(0.0, 1.0), end_at=(0.0, 1.0))
Create an augmenter that blends with an average-pooled image according to a vertical gradient that starts at a random y-coordinate and reaches its maximum at another random y-coordinate. Due to that randomness, the gradient may increase towards the bottom or top.
>>> aug = iaa.BlendAlphaVerticalLinearGradient( >>> iaa.Clouds(), >>> start_at=(0.15, 0.35), end_at=0.0)
Create an augmenter that draws clouds in roughly the top quarter of the 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)See get_children_lists()
.get_parameters
(self)See get_parameters()
.localize_random_state
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. localize_random_state_
(self[, recursive])Assign augmenter-specific RNGs to this augmenter and its children. pool
(self[, processes, maxtasksperchild, seed])Create a pool used for multicore augmentation. remove_augmenters
(self, func[, copy, …])Remove this augmenter or children that match a condition. remove_augmenters_
(self, func[, parents])Remove in-place children of this augmenter that match a condition. remove_augmenters_inplace
(self, func[, parents])Deprecated. reseed
(self[, random_state, deterministic_too])Deprecated. seed_
(self[, entropy, deterministic_too])Seed this augmenter and all of its children. show_grid
(self, images, rows, cols)Augment images and plot the results as a single grid-like image. to_deterministic
(self[, n])Convert this augmenter from a stochastic to a deterministic one.
-
class
imgaug.augmenters.blend.
BoundingBoxesMaskGen
(labels=None, nb_sample_labels=None)[source]¶ Bases:
imgaug.augmenters.blend.IBatchwiseMaskGenerator
Generator that produces masks highlighting bounding boxes.
This class produces for each row (i.e. image + bounding boxes) in a batch a mask in which the inner areas of bounding box rectangles with given labels are marked (i.e. set to
1.0
). The labels may be provided as a fixed list of strings or a stochastic parameter from which labels will be sampled. If no labels are provided, all bounding boxes will be marked.A pixel will be set to
1.0
if at least one bounding box at that location has one of the requested labels, even if there is also one bounding box at that location with a not requested label.Note
This class will produce an
AssertionError
if there are no bounding boxes in a batch.Added in 0.4.0.
Parameters: labels (None or str or list of str or imgaug.parameters.StochasticParameter) – Labels of bounding boxes to select for.
If nb_sample_labels is
None
then this is expected to be either alsoNone
(select all BBs) or a singlestr
(select BBs with this one label) or alist
ofstr
s (always select BBs with these labels).If nb_sample_labels is set, then this parameter will be treated as a stochastic parameter with the following valid types:
- If
None
: Ignore the sampling count and always use all bounding boxes. - If
str
: Exactly that label will be used for all images. - If
list
ofstr
:N
random values will be picked per image from that list and used as the labels. - If
StochasticParameter
: That parameter will be queried once per batch for(sum(N),)
values.
N
denotes the number of labels to sample per segmentation map (derived from nb_sample_labels) andsum(N)
denotes the sum ofN
s over all images.- If
nb_sample_labels (None or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – Number of labels to sample (with replacement) per image. As sampling happens with replacement, fewer unique labels may be sampled.
- If
None
: labels is expected to also beNone
or a fixed value of labels to be used for all images. - If
int
: Exactly that many labels will be sampled for all images. - If
tuple
(a, b)
: A random value will be uniformly sampled per image from the discrete interval[a..b]
. - If
list
: A random value will be picked per image from that list. - If
StochasticParameter
: That parameter will be queried once per batch for(B,)
values, whereB
is the number of images.
- If
Methods
draw_masks
(self, batch[, random_state])See draw_masks()
.generate_mask
(bbsoi, labels)Generate a mask of the areas of bounding boxes with given labels. -
draw_masks
(self, batch, random_state=None)[source]¶ See
draw_masks()
.Added in 0.4.0.
-
classmethod
generate_mask
(bbsoi, labels)[source]¶ Generate a mask of the areas of bounding boxes with given labels.
Added in 0.4.0.
Parameters: - bbsoi (imgaug.augmentables.bbs.BoundingBoxesOnImage) – The bounding boxes for which to generate the mask.
- labels (None or iterable of str) – Labels of the bounding boxes to set to
1.0
. For an(x, y)
position, it is enough that any bounding box at the given location has one of the labels. If this isNone
, all bounding boxes will be marked.
Returns: float32
mask array with same height and width assegmap.shape
. Values are in[0.0, 1.0]
.Return type: ndarray
-
class
imgaug.augmenters.blend.
CheckerboardMaskGen
(nb_rows, nb_cols)[source]¶ Bases:
imgaug.augmenters.blend.IBatchwiseMaskGenerator
Generate masks following a checkerboard-like pattern.
This mask generator splits each image into a regular grid of
H
rows andW
columns. Each cell is then filled with either1.0
or0.0
. The cell at the top-left is always1.0
. Its right and bottom neighbour cells are0.0
. The 4-neighbours of any cell always have a value opposite to the cell’s value (0.0
vs.1.0
).Added in 0.4.0.
Parameters: nb_rows (int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) –
Number of rows of the checkerboard.
- If
int
: Exactly that value will be used for all images. - If
tuple
(a, b)
: A random value will be uniformly sampled per image from the discrete interval[a..b]
. - If
list
: A random value will be picked per image from that list. - If
StochasticParameter
: That parameter will be queried once per batch for(N,)
values – one per image.
- If
nb_cols (int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – Number of columns of the checkerboard. Analogous to nb_rows.
Attributes: Methods
draw_masks
(self, batch[, random_state])See draw_masks()
.generate_mask
(shape, nb_rows, nb_cols)Generate a mask following a checkerboard pattern. -
draw_masks
(self, batch, random_state=None)[source]¶ See
draw_masks()
.Added in 0.4.0.
-
classmethod
generate_mask
(shape, nb_rows, nb_cols)[source]¶ Generate a mask following a checkerboard pattern.
Added in 0.4.0.
Parameters: - shape (tuple of int) – Height and width of the output mask.
- nb_rows (int) – Number of rows of the checkerboard pattern.
- nb_cols (int) – Number of columns of the checkerboard pattern.
Returns: float32
mask array with same height and width assegmap.shape
. Values are in[0.0, 1.0]
.Return type: ndarray
-
nb_cols
¶ Get the number of columns of the checkerboard grid.
Added in 0.4.0.
Returns: The number of columns. Return type: int
-
nb_rows
¶ Get the number of rows of the checkerboard grid.
Added in 0.4.0.
Returns: The number of rows. Return type: int
-
imgaug.augmenters.blend.
FrequencyNoiseAlpha
(exponent=(-4, 4), first=None, second=None, per_channel=False, size_px_max=(4, 16), upscale_method=None, iterations=(1, 3), aggregation_method=['avg', 'max'], sigmoid=0.5, sigmoid_thresh=None, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Deprecated. Use
BlendAlphaFrequencyNoise
instead. FrequencyNoiseAlpha is deprecated. Use BlendAlphaFrequencyNoise instead. The order of parameters is the same. Parameter ‘first’ was renamed to ‘foreground’. Parameter ‘second’ was renamed to ‘background’.Deprecated since 0.4.0.
-
class
imgaug.augmenters.blend.
HorizontalLinearGradientMaskGen
(min_value=(0.0, 0.2), max_value=(0.8, 1.0), start_at=(0.0, 0.2), end_at=(0.8, 1.0))[source]¶ Bases:
imgaug.augmenters.blend._LinearGradientMaskGen
Generator that produces horizontal linear gradient masks.
This class receives batches and produces for each row (i.e. image) a horizontal linear gradient that matches the row’s shape (i.e. image shape). The gradient increases linearly from a minimum value to a maximum value along the x-axis. The start and end points (i.e. where the minimum value starts to increase and where it reaches the maximum) may be defines as fractions of the width. E.g. for width
100
andstart=0.25
,end=0.75
, the gradient would have its minimum in interval[0px, 25px]
and its maximum in interval[75px, 100px]
.Note that this has nothing to do with a derivative along the x-axis.
Added in 0.4.0.
Parameters: min_value (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Minimum value that the mask will have up to the start point of the linear gradient. Note that min_value is allowed to be larger than max_value, in which case the gradient will start at the (higher) min_value and decrease towards the (lower) max_value.
- If
number
: Exactly that value will be used for all images. - If
tuple
(a, b)
: A random value will be uniformly sampled per image from the interval[a, b]
. - If
list
: A random value will be picked per image from that list. - If
StochasticParameter
: That parameter will be queried once per batch for(N,)
values – one per image.
- If
max_value (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Maximum value that the mask will have at the end of the linear gradient.
Datatypes are analogous to min_value.
start_at (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Position on the x-axis where the linear gradient starts, given as a fraction of the axis size. Interval is
[0.0, 1.0]
, where0.0
is at the left of the image. Ifend_at < start_at
the gradient will be inverted.Datatypes are analogous to min_value.
end_at (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Position on the x-axis where the linear gradient ends, given as a fraction of the axis size. Interval is
[0.0, 1.0]
, where0.0
is at the right of the image.Datatypes are analogous to min_value.
Methods
draw_masks
(self, batch[, random_state])See draw_masks()
.generate_mask
(shape, min_value, max_value, …)Generate a linear horizontal gradient mask. -
classmethod
generate_mask
(shape, min_value, max_value, start_at, end_at)[source]¶ Generate a linear horizontal gradient mask.
Added in 0.4.0.
Parameters: - shape (tuple of int) – Shape of the image. The mask will have the same height and width.
- min_value (number) – Minimum value of the gradient in interval
[0.0, 1.0]
. - max_value (number) – Maximum value of the gradient in interval
[0.0, 1.0]
. - start_at (number) – Position on the x-axis where the linear gradient starts, given as
a fraction of the axis size. Interval is
[0.0, 1.0]
. - end_at (number) – Position on the x-axis where the linear gradient ends, given as
a fraction of the axis size. Interval is
[0.0, 1.0]
.
Returns: float32
mask array with same height and width as the image. Values are in[0.0, 1.0]
.Return type: ndarray
-
class
imgaug.augmenters.blend.
IBatchwiseMaskGenerator
[source]¶ Bases:
object
Interface for classes generating masks for batches.
Child classes are supposed to receive a batch and generate an iterable of masks, one per row (i.e. image), matching the row shape (i.e. image shape). This is used in
BlendAlphaMask
.Added in 0.4.0.
Methods
draw_masks
(self, batch[, random_state])Generate a mask with given shape. -
draw_masks
(self, batch, random_state=None)[source]¶ Generate a mask with given shape.
Parameters: - batch (imgaug.augmentables.batches._BatchInAugmentation) – Shape of the mask to sample.
- 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) – A seed or random number generator to use during the sampling
process. If
None
, the global RNG will be used. See also__init__()
for a similar parameter with more details.
Returns: Masks, one per row in the batch. Each mask must be a
float32
array in interval[0.0, 1.0]
. It must either have the same shape as the row (i.e. the image) or shape(H, W)
if all channels are supposed to have the same mask.Return type: iterable of ndarray
-
-
class
imgaug.augmenters.blend.
InvertMaskGen
(p, child)[source]¶ Bases:
imgaug.augmenters.blend.IBatchwiseMaskGenerator
Generator that inverts the outputs of other mask generators.
This class receives batches and calls for each row (i.e. image) a child mask generator to produce a mask. That mask is then inverted for
p%
of all rows, i.e. converted to1.0 - mask
.Added in 0.4.0.
Parameters: - p (bool or float or imgaug.parameters.StochasticParameter, optional) – Probability of inverting each mask produced by the other mask generator.
- child (IBatchwiseMaskGenerator) – The other mask generator to invert.
Methods
draw_masks
(self, batch[, random_state])See draw_masks()
.-
draw_masks
(self, batch, random_state=None)[source]¶ See
draw_masks()
.Added in 0.4.0.
-
class
imgaug.augmenters.blend.
RegularGridMaskGen
(nb_rows, nb_cols, alpha=[0.0, 1.0])[source]¶ Bases:
imgaug.augmenters.blend.IBatchwiseMaskGenerator
Generate masks following a regular grid pattern.
This mask generator splits each image into a grid-like pattern of
H
rows andW
columns. Each cell is then filled with an alpha value, sampled randomly per cell.The difference to
CheckerboardMaskGen
is that this mask generator samples random alpha values per cell, while in the checkerboard the alpha values follow a fixed pattern.Added in 0.4.0.
Parameters: nb_rows (int or tuple of int or list of int or imgaug.parameters.StochasticParameter) –
Number of rows of the regular grid.
- If
int
: Exactly that value will be used for all images. - If
tuple
(a, b)
: A random value will be uniformly sampled per image from the discrete interval[a..b]
. - If
list
: A random value will be picked per image from that list. - If
StochasticParameter
: That parameter will be queried once per batch for(N,)
values – one per image.
- If
nb_cols (int or tuple of int or list of int or imgaug.parameters.StochasticParameter) – Number of columns of the checkerboard. Analogous to nb_rows.
alpha (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Alpha value of each cell.
- If
number
: Exactly that value will be used for all images. - If
tuple
(a, b)
: A random value will be uniformly sampled per image from the interval[a, b]
. - If
list
: A random value will be picked per image from that list. - If
StochasticParameter
: That parameter will be queried once per batch for(N,)
values – one per image.
- If
Methods
draw_masks
(self, batch[, random_state])See draw_masks()
.generate_mask
(shape, nb_rows, nb_cols, alphas)Generate a mask following a checkerboard pattern. -
draw_masks
(self, batch, random_state=None)[source]¶ See
draw_masks()
.Added in 0.4.0.
-
classmethod
generate_mask
(shape, nb_rows, nb_cols, alphas)[source]¶ Generate a mask following a checkerboard pattern.
Added in 0.4.0.
Parameters: - shape (tuple of int) – Height and width of the output mask.
- nb_rows (int) – Number of rows of the checkerboard pattern.
- nb_cols (int) – Number of columns of the checkerboard pattern.
- alphas (ndarray) – 1D or 2D array containing for each cell the alpha value, i.e.
nb_rows*nb_cols
values.
Returns: float32
mask array with same height and width assegmap.shape
. Values are in[0.0, 1.0]
.Return type: ndarray
-
class
imgaug.augmenters.blend.
SegMapClassIdsMaskGen
(class_ids, nb_sample_classes=None)[source]¶ Bases:
imgaug.augmenters.blend.IBatchwiseMaskGenerator
Generator that produces masks highlighting segmentation map classes.
This class produces for each segmentation map in a batch a mask in which the locations of a set of provided classes are highlighted (i.e.
1.0
). The classes may be provided as a fixed list of class ids or a stochastic parameter from which class ids will be sampled.The produced masks are initially of the same height and width as the segmentation map arrays and later upscaled to the image height and width.
Note
Segmentation maps can have multiple channels. If that is the case then for each position
(x, y)
it is sufficient that any class id in any channel matches one of the desired class ids.Note
This class will produce an
AssertionError
if there are no segmentation maps in a batch.Added in 0.4.0.
Parameters: class_ids (int or tuple of int or list of int or imgaug.parameters.StochasticParameter) – Segmentation map classes to mark in the produced mask.
If nb_sample_classes is
None
then this is expected to be either a singleint
(always mark this one class id) or alist
ofint
s (always mark these class ids).If nb_sample_classes is set, then this parameter will be treated as a stochastic parameter with the following valid types:
- If
int
: Exactly that class id will be used for all segmentation maps. - If
tuple
(a, b)
:N
random values will be uniformly sampled per segmentation map from the discrete interval[a..b]
and used as the class ids. - If
list
:N
random values will be picked per segmentation map from that list and used as the class ids. - If
StochasticParameter
: That parameter will be queried once per batch for(sum(N),)
values.
N
denotes the number of classes to sample per segmentation map (derived from nb_sample_classes) andsum(N)
denotes the sum ofN
s over all segmentation maps.- If
nb_sample_classes (None or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – Number of class ids to sample (with replacement) per segmentation map. As sampling happens with replacement, fewer unique class ids may be sampled.
- If
None
: class_ids is expected to be a fixed value of class ids to be used for all segmentation maps. - If
int
: Exactly that many class ids will be sampled for all segmentation maps. - If
tuple
(a, b)
: A random value will be uniformly sampled per segmentation map from the discrete interval[a..b]
. - If
list
orint
: A random value will be picked per segmentation map from that list. - If
StochasticParameter
: That parameter will be queried once per batch for(B,)
values, whereB
is the number of segmentation maps.
- If
Methods
draw_masks
(self, batch[, random_state])See draw_masks()
.generate_mask
(segmap, class_ids)Generate a mask of where the segmentation map has the given classes. -
draw_masks
(self, batch, random_state=None)[source]¶ See
draw_masks()
.Added in 0.4.0.
-
classmethod
generate_mask
(segmap, class_ids)[source]¶ Generate a mask of where the segmentation map has the given classes.
Added in 0.4.0.
Parameters: - segmap (imgaug.augmentables.segmap.SegmentationMapsOnImage) – The segmentation map for which to generate the mask.
- class_ids (iterable of int) – IDs of the classes to set to
1.0
. For an(x, y)
position, it is enough that any channel at the given location to have one of these class ids to be marked as1.0
.
Returns: float32
mask array with same height and width assegmap.shape
. Values are in[0.0, 1.0]
.Return type: ndarray
-
imgaug.augmenters.blend.
SimplexNoiseAlpha
(first=None, second=None, per_channel=False, size_px_max=(2, 16), upscale_method=None, iterations=(1, 3), aggregation_method='max', sigmoid=True, sigmoid_thresh=None, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]¶ Deprecated. Use
BlendAlphaSimplexNoise
instead. SimplexNoiseAlpha is deprecated. Use BlendAlphaSimplexNoise instead. The order of parameters is the same. Parameter ‘first’ was renamed to ‘foreground’. Parameter ‘second’ was renamed to ‘background’.Deprecated since 0.4.0.
-
class
imgaug.augmenters.blend.
SomeColorsMaskGen
(nb_bins=(5, 15), smoothness=(0.1, 0.3), alpha=[0.0, 1.0], rotation_deg=(0, 360), from_colorspace='RGB')[source]¶ Bases:
imgaug.augmenters.blend.IBatchwiseMaskGenerator
Generator that produces masks based on some similar colors in images.
This class receives batches for which to generate masks, iterates over the batch rows (i.e. images) and generates one mask per row. The mask contains high alpha values for some colors, while other colors get low mask values. Which colors are chosen is random. How wide or narrow the selection is (e.g. very specific blue tone or all blue-ish colors) is determined by the hyperparameters.
The color selection method performs roughly the following steps:
- Split the full color range of the hue in
HSV
intonb_bins
bins (i.e.256/nb_bins
different possible hue tones). - Shift the bins by
rotation_deg
degrees. (This way, the0th
bin does not always start at exactly0deg
of hue.) - Sample
alpha
values for each bin. - Repeat the
nb_bins
bins until there are256
bins. - Smoothen the alpha values of neighbouring bins using a gaussian
kernel. The kernel’s
sigma
is derived fromsmoothness
. - Associate all hue values in the image with the corresponding bin’s alpha value. This results in the alpha mask.
Note
This mask generator will produce an
AssertionError
for batches that contain no images.Added in 0.4.0.
Supported dtypes:
Parameters: nb_bins (int or tuple of int or list of int or imgaug.parameters.StochasticParameter, optional) – Number of bins. For
B
bins, each bin denotes roughly360/B
degrees of colors in the hue channel. Lower values lead to a coarser selection of colors. Expected value range is[2, 256]
.- If
int
: Exactly that value will be used for all images. - If
tuple
(a, b)
: A random value will be uniformly sampled per image from the discrete interval[a..b]
. - If
list
: A random value will be picked per image from that list. - If
StochasticParameter
: That parameter will be queried once per batch for(N,)
values – one per image.
- If
smoothness (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Strength of the 1D gaussian kernel applied to the sampled binwise alpha values. Larger values will lead to more similar grayscaling of neighbouring colors. Expected value range is
[0.0, 1.0]
.- If
number
: Exactly that value will be used for all images. - If
tuple
(a, b)
: A random value will be uniformly sampled per image from the interval[a, b]
. - If
list
: A random value will be picked per image from that list. - If
StochasticParameter
: That parameter will be queried once per batch for(N,)
values – one per image.
- If
alpha (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Parameter to sample binwise alpha blending factors from. Expected value range is
[0.0, 1.0]
. Note that the alpha values will be smoothed between neighbouring bins. Hence, it is usually a good idea to set this so that the probability distribution peaks are around0.0
and1.0
, e.g. via a list[0.0, 1.0]
or aBeta
distribution. It is not recommended to set this to a deterministic value, otherwise all bins and hence all pixels in the generated mask will have the same value.- If
number
: Exactly that value will be used for all bins. - If
tuple
(a, b)
: A random value will be uniformly sampled per bin from the interval[a, b]
. - If
list
: A random value will be picked per bin from that list. - If
StochasticParameter
: That parameter will be queried once per batch for(N*B,)
values – one per image and bin.
- If
rotation_deg (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Rotiational shift of each bin as a fraction of
360
degrees. E.g.0.0
will not shift any bins, while a value of0.5
will shift by around180
degrees. This shift is mainly used so that the0th
bin does not always start at0deg
. Expected value range is[-360, 360]
. This parameter can usually be kept at the default value.- If
number
: Exactly that value will be used for all images. - If
tuple
(a, b)
: A random value will be uniformly sampled per image from the interval[a, b]
. - If
list
: A random value will be picked per image from that list. - If
StochasticParameter
: That parameter will be queried once per batch for(N,)
values – one per image.
- If
from_colorspace (str, optional) – The source colorspace (of the input images). See
change_colorspace_()
.
Methods
draw_masks
(self, batch[, random_state])See draw_masks()
.generate_mask
(image, binwise_alphas, sigma, …)Generate a colorwise alpha mask for a single image. -
draw_masks
(self, batch, random_state=None)[source]¶ See
draw_masks()
.
-
classmethod
generate_mask
(image, binwise_alphas, sigma, rotation_bins, from_colorspace)[source]¶ Generate a colorwise alpha mask for a single image.
Added in 0.4.0.
Parameters: - image (ndarray) – Image for which to generate the mask. Must have shape
(H,W,3)
in colorspace from_colorspace. - binwise_alphas (ndarray) – Alpha values of shape
(B,)
withB
in[1, 256]
and values in interval[0.0, 1.0]
. Will be upscaled to 256 bins by simple repetition. Each bin represents1/256
th of the hue. - sigma (float) – Sigma of the 1D gaussian kernel applied to the upscaled binwise alpha value array.
- rotation_bins (int) – By how much to rotate the 256 bin alpha array. The rotation is given in number of bins.
- from_colorspace (str) – Colorspace of the input image. One of
imgaug.augmenters.color.CSPACE_*
.
Returns: float32
mask array of shape(H, W)
with values in[0.0, 1.0]
Return type: ndarray
- image (ndarray) – Image for which to generate the mask. Must have shape
- Split the full color range of the hue in
-
class
imgaug.augmenters.blend.
StochasticParameterMaskGen
(parameter, per_channel)[source]¶ Bases:
imgaug.augmenters.blend.IBatchwiseMaskGenerator
Mask generator that queries stochastic parameters for mask values.
This class receives batches for which to generate masks, iterates over the batch rows (i.e. images) and generates one mask per row. For a row with shape
(H, W, C)
(= image shape), it generates either a(H, W)
mask (ifper_channel
is false-like) or a(H, W, C)
mask (ifper_channel
is true-like). Theper_channel
is sampled per batch for each row/image.Added in 0.4.0.
Parameters: - parameter (imgaug.parameters.StochasticParameter) – Stochastic parameter to draw mask samples from.
Expected to return values in interval
[0.0, 1.0]
(not all stochastic parameters do that) and must be able to handle sampling shapes(H, W)
and(H, W, C)
(all stochastic parameters should do that). - per_channel (bool or float or imgaug.parameters.StochasticParameter, optional) – Whether to use the same mask for all channels (
False
) or to sample a new mask for each channel (True
). If this value is a floatp
, then forp
percent of all rows (i.e. images) per_channel will be treated asTrue
, otherwise asFalse
.
Methods
draw_masks
(self, batch[, random_state])See draw_masks()
.-
draw_masks
(self, batch, random_state=None)[source]¶ See
draw_masks()
.
- parameter (imgaug.parameters.StochasticParameter) – Stochastic parameter to draw mask samples from.
Expected to return values in interval
-
class
imgaug.augmenters.blend.
VerticalLinearGradientMaskGen
(min_value=(0.0, 0.2), max_value=(0.8, 1.0), start_at=(0.0, 0.2), end_at=(0.8, 1.0))[source]¶ Bases:
imgaug.augmenters.blend._LinearGradientMaskGen
Generator that produces vertical linear gradient masks.
See
HorizontalLinearGradientMaskGen
for details.Added in 0.4.0.
Parameters: min_value (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Minimum value that the mask will have up to the start point of the linear gradient. Note that min_value is allowed to be larger than max_value, in which case the gradient will start at the (higher) min_value and decrease towards the (lower) max_value.
- If
number
: Exactly that value will be used for all images. - If
tuple
(a, b)
: A random value will be uniformly sampled per image from the interval[a, b]
. - If
list
: A random value will be picked per image from that list. - If
StochasticParameter
: That parameter will be queried once per batch for(N,)
values – one per image.
- If
max_value (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Maximum value that the mask will have at the end of the linear gradient.
Datatypes are analogous to min_value.
start_at (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Position on the y-axis where the linear gradient starts, given as a fraction of the axis size. Interval is
[0.0, 1.0]
, where0.0
is at the top of the image. Ifend_at < start_at
the gradient will be inverted.Datatypes are analogous to min_value.
end_at (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Position on the x-axis where the linear gradient ends, given as a fraction of the axis size. Interval is
[0.0, 1.0]
, where1.0
is at the bottom of the image.Datatypes are analogous to min_value.
Methods
draw_masks
(self, batch[, random_state])See draw_masks()
.generate_mask
(shape, min_value, max_value, …)Generate a linear horizontal gradient mask. -
classmethod
generate_mask
(shape, min_value, max_value, start_at, end_at)[source]¶ Generate a linear horizontal gradient mask.
Added in 0.4.0.
Parameters: - shape (tuple of int) – Shape of the image. The mask will have the same height and width.
- min_value (number) – Minimum value of the gradient in interval
[0.0, 1.0]
. - max_value (number) – Maximum value of the gradient in interval
[0.0, 1.0]
. - start_at (number) – Position on the x-axis where the linear gradient starts, given as
a fraction of the axis size. Interval is
[0.0, 1.0]
. - end_at (number) – Position on the x-axis where the linear gradient ends, given as
a fraction of the axis size. Interval is
[0.0, 1.0]
.
Returns: float32
mask array with same height and width as the image. Values are in[0.0, 1.0]
.Return type: ndarray
-
imgaug.augmenters.blend.
blend_alpha
(image_fg, image_bg, alpha, eps=0.01)[source]¶ Blend two images using an alpha blending.
In alpha blending, the two images are naively mixed using a multiplier. Let
A
be the foreground image andB
the background image anda
is the alpha value. Each pixel intensity is then computed asa * A_ij + (1-a) * B_ij
.Supported dtypes:
uint8
: yes; fully testeduint16
: yes; fully testeduint32
: yes; fully testeduint64
: yes; fully tested (1)int8
: yes; fully testedint16
: yes; fully testedint32
: yes; fully testedint64
: yes; fully tested (1)float16
: yes; fully testedfloat32
: yes; fully testedfloat64
: yes; fully tested (1)float128
: no (2)bool
: yes; fully tested (2)
- Tests show that these dtypes work, but a conversion to
float128
happens, which only has 96 bits of size instead of true 128 bits and hence not twice as much resolution. It is possible that these dtypes result in inaccuracies, though the tests did not indicate that.
- Tests show that these dtypes work, but a conversion to
- Not available due to the input dtype having to be increased to an equivalent float dtype with two times the input resolution.
- Mapped internally to
float16
.
- Mapped internally to
Parameters: - image_fg ((H,W,[C]) ndarray) – Foreground image. Shape and dtype kind must match the one of the background image.
- image_bg ((H,W,[C]) ndarray) – Background image. Shape and dtype kind must match the one of the foreground image.
- alpha (number or iterable of number or ndarray) – The blending factor, between
0.0
and1.0
. Can be interpreted as the opacity of the foreground image. Values around1.0
result in only the foreground image being visible. Values around0.0
result in only the background image being visible. Multiple alphas may be provided. In these cases, there must be exactly one alpha per channel in the foreground/background image. Alternatively, for(H,W,C)
images, either one(H,W)
array or an(H,W,C)
array of alphas may be provided, denoting the elementwise alpha value. - eps (number, optional) – Controls when an alpha is to be interpreted as exactly
1.0
or exactly0.0
, resulting in only the foreground/background being visible and skipping the actual computation.
Returns: image_blend – Blend of foreground and background image.
Return type: (H,W,C) ndarray