imgaug.augmenters.blend

Augmenters that blend two images with each other.

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

from imgaug import augmenters as iaa

and then e.g.

seq = iaa.Sequential([
    iaa.Alpha(0.5, iaa.Add((-5, 5)))
])

List of augmenters:

  • Alpha
  • AlphaElementwise
  • SimplexNoiseAlpha
  • FrequencyNoiseAlpha
class imgaug.augmenters.blend.Alpha(factor=0, first=None, second=None, per_channel=False, name=None, deterministic=False, random_state=None)[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 A be the first branch and B be the second branch. Then the result images are defined as factor * A + (1-factor) * B, where factor is an overlay factor.

Note

It is not recommended to use Alpha 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 (first or second branch) should be used as the coordinates after augmentation.

Currently, if factor >= 0.5 (per image), the results of the first branch are used as the new coordinates, otherwise the results of the second branch.

dtype support:

See :func:`imgaug.augmenters.blend.blend_alpha`.
Parameters:
  • factor (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Weighting of the results of the first branch. Values close to 0 mean that the results from the second branch (see parameter second) 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.
  • first (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) –

    Augmenter(s) that make up the first of the two branches.

    • If None, then the input images will be reused as the output of the first branch.
    • If Augmenter, then that augmenter will be used as the branch.
    • If iterable of Augmenter, then that iterable will be converted into a Sequential and used as the augmenter.
  • second (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) –

    Augmenter(s) that make up the second of the two branches.

    • If None, then the input images will be reused as the output of the second branch.
    • If Augmenter, then that augmenter will be used as the branch.
    • If iterable of Augmenter, then that iterable will be converted into a Sequential and used as the augmenter.
  • 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 float p, then for p percent of all images per_channel will be treated as True, otherwise as False.

  • name (None or str, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • deterministic (bool, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.Alpha(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 about 50% of all color. This is equivalent to iaa.Grayscale(0.5).

>>> aug = iaa.Alpha((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 to iaa.Grayscale((0.0, 1.0)).

>>> aug = iaa.Alpha(
>>>     (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]. For 50% 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 near 1.0), while the green and blue channels may not look rotated (factors near 0.0).

>>> aug = iaa.Alpha(
>>>     (0.0, 1.0),
>>>     first=iaa.Add(100),
>>>     second=iaa.Multiply(0.2))

Apply two branches of augmenters – A and Bindependently to input images and alpha-blend the results of these branches using a factor f. Branch A increases image pixel intensities by 100 and B multiplies the pixel intensities by 0.2. f is sampled uniformly from the interval [0.0, 1.0] per image. The resulting images contain a bit of A and a bit of B.

>>> aug = iaa.Alpha([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 exactly 0.75 (sampled once per image).

Methods

__call__(self, \*args, \*\*kwargs) Alias for imgaug.augmenters.meta.Augmenter.augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Augment a single batch.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, hooks]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_inplace(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
reseed(self[, random_state, deterministic_too]) Reseed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
get_parameters  
get_children_lists(self)[source]

Get a list of lists of children of this augmenter.

For most augmenters, the result will be a single empty list. For augmenters with children it will often be a list with one sublist containing all children. In some cases the augmenter will contain multiple distinct lists of children, e.g. an if-list and an else-list. This will lead to a result consisting of a single list with multiple sublists, each representing the respective sublist of children.

E.g. for an if/else-augmenter that executes the children A1, A2 if a condition is met and otherwise executes the children B1, B2, B3 the result will be [[A1, A2], [B1, B2, B3]].

IMPORTANT: While the topmost list may be newly created, each of the sublist must be editable inplace resulting in a changed children list of the augmenter. E.g. if an Augmenter IfElse(condition, [A1, A2], [B1, B2, B3]) returns [[A1, A2], [B1, B2, B3]] for a call to imgaug.augmenters.meta.Augmenter.get_children_lists() and A2 is removed inplace from [A1, A2], then the children lists of IfElse(...) must also change to [A1], [B1, B2, B3]. This is used in imgaug.augmeneters.meta.Augmenter.remove_augmenters_inplace().

Returns:One or more lists of child augmenter. Can also be a single empty list.
Return type:list of list of imgaug.augmenters.meta.Augmenter
get_parameters(self)[source]
class imgaug.augmenters.blend.AlphaElementwise(factor=0, first=None, second=None, per_channel=False, name=None, deterministic=False, random_state=None)[source]

Bases: imgaug.augmenters.blend.Alpha

Alpha-blend two image sources using alpha/opacity values sampled per pixel.

This is the same as Alpha, except that the opacity factor is sampled once per pixel instead of once per image (or a few times per image, if Alpha.per_channel is set to True).

See Alpha for more details.

Note

It is not recommended to use AlphaElementwise 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 (first or second branch) should be used as the coordinates after augmentation.

Currently, the for keypoints and line strings the results of the first and second branch will be mixed. For each coordinate, the augmented one from the first or second branch will be picked based on the average alpha mask value at the corresponding spatial location.

For polygons, only all polygons of the first or all of the second branch will be used, based on the average over the whole alpha mask.

dtype support:

See :func:`imgaug.augmenters.blend.blend_alpha`.
Parameters:
  • factor (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Weighting of the results of the first branch. Values close to 0 mean that the results from the second branch (see parameter second) 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.
  • first (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) –

    Augmenter(s) that make up the first of the two branches.

    • If None, then the input images will be reused as the output of the first branch.
    • If Augmenter, then that augmenter will be used as the branch.
    • If iterable of Augmenter, then that iterable will be converted into a Sequential and used as the augmenter.
  • second (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) –

    Augmenter(s) that make up the second of the two branches.

    • If None, then the input images will be reused as the output of the second branch.
    • If Augmenter, then that augmenter will be used as the branch.
    • If iterable of Augmenter, then that iterable will be converted into a Sequential and used as the augmenter.
  • 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 float p, then for p percent of all images per_channel will be treated as True, otherwise as False.

  • name (None or str, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • deterministic (bool, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.AlphaElementwise(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 about 50% of all color. This is equivalent to iaa.Grayscale(0.5). This is also equivalent to iaa.Alpha(0.5, iaa.Grayscale(1.0)), as the opacity has a fixed value of 0.5 and is hence identical for all pixels.

>>> aug = iaa.AlphaElementwise((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 pixel, thereby removing a random fraction of all colors from each pixel. This is equivalent to iaa.Grayscale((0.0, 1.0)).

>>> aug = iaa.AlphaElementwise(
>>>     (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. For 50% 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 near 1.0), while the green and blue channels may not look rotated (factors near 0.0).

>>> aug = iaa.AlphaElementwise(
>>>     (0.0, 1.0),
>>>     first=iaa.Add(100),
>>>     second=iaa.Multiply(0.2))

Apply two branches of augmenters – A and Bindependently to input images and alpha-blend the results of these branches using a factor f. Branch A increases image pixel intensities by 100 and B multiplies the pixel intensities by 0.2. f is sampled uniformly from the interval [0.0, 1.0] per pixel. The resulting images contain a bit of A and a bit of B.

>>> aug = iaa.AlphaElementwise([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 exactly 0.75 (sampled once per pixel).

Methods

__call__(self, \*args, \*\*kwargs) Alias for imgaug.augmenters.meta.Augmenter.augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Augment a single batch.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, hooks]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_inplace(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
reseed(self[, random_state, deterministic_too]) Reseed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
get_parameters  
class imgaug.augmenters.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, name=None, deterministic=False, random_state=None)[source]

Bases: imgaug.augmenters.blend.AlphaElementwise

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 by 0 s and other times results in smaller patterns. If nearest neighbour upsampling is used, these blobs can be rectangular with sharp edges.

dtype support:

See ``imgaug.augmenters.blend.AlphaElementwise``.
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) to 4 (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.
  • first (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) –

    Augmenter(s) that make up the first of the two branches.

    • If None, then the input images will be reused as the output of the first branch.
    • If Augmenter, then that augmenter will be used as the branch.
    • If iterable of Augmenter, then that iterable will be converted into a Sequential and used as the augmenter.
  • second (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) –

    Augmenter(s) that make up the second of the two branches.

    • If None, then the input images will be reused as the output of the second branch.
    • If Augmenter, then that augmenter will be used as the branch.
    • If iterable of Augmenter, then that iterable will be converted into a Sequential and used as the augmenter.
  • 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 float p, then for p percent of all images per_channel will be treated as True, otherwise as False.

  • 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.
  • 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 either nearest or linear or cubic is picked. Most weight is put on linear, followed by cubic.
    • If imgaug.ALL, then either nearest or linear or area or cubic is picked per iteration (all same probability).
    • If string, then that value will be used as the method (must be nearest or linear or area or cubic).
    • 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.
  • 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.
  • 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 or avg, where ‘min’ combines the noise maps by taking the (elementwise) minimum over all iteration’s results, max the (elementwise) maximum and avg 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.
  • 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 with 0<=p<=1, then a sigmoid will be applied to p percent of all final noise maps.
  • 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, then Normal(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.
  • name (None or str, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • deterministic (bool, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.FrequencyNoiseAlpha(first=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.FrequencyNoiseAlpha(
>>>     first=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.FrequencyNoiseAlpha(
>>>     first=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.FrequencyNoiseAlpha(
>>>     first=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.FrequencyNoiseAlpha(
>>>     first=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 second) will be kept, rather than using the results of the augmentation (parameter/branch first).

Methods

__call__(self, \*args, \*\*kwargs) Alias for imgaug.augmenters.meta.Augmenter.augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Augment a single batch.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, hooks]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_inplace(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
reseed(self[, random_state, deterministic_too]) Reseed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
get_parameters  
class imgaug.augmenters.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, name=None, deterministic=False, random_state=None)[source]

Bases: imgaug.augmenters.blend.AlphaElementwise

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.

dtype support:

See ``imgaug.augmenters.blend.AlphaElementwise``.
Parameters:
  • first (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) –

    Augmenter(s) that make up the first of the two branches.

    • If None, then the input images will be reused as the output of the first branch.
    • If Augmenter, then that augmenter will be used as the branch.
    • If iterable of Augmenter, then that iterable will be converted into a Sequential and used as the augmenter.
  • second (None or imgaug.augmenters.meta.Augmenter or iterable of imgaug.augmenters.meta.Augmenter, optional) –

    Augmenter(s) that make up the second of the two branches.

    • If None, then the input images will be reused as the output of the second branch.
    • If Augmenter, then that augmenter will be used as the branch.
    • If iterable of Augmenter, then that iterable will be converted into a Sequential and used as the augmenter.
  • 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 float p, then for p percent of all images per_channel will be treated as True, otherwise as False.

  • 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 either nearest or linear or cubic is picked. Most weight is put on linear, followed by cubic.
    • If imgaug.ALL, then either nearest or linear or area or cubic is picked per iteration (all same probability).
    • If a string, then that value will be used as the method (must be nearest or linear or area or cubic).
    • 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.
  • 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.
  • 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 or avg, where min combines the noise maps by taking the (elementwise) minimum over all iteration’s results, max the (elementwise) maximum and avg 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.
  • 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 with 0<=p<=1, then a sigmoid will be applied to p percent of all final noise maps.
  • 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, then Normal(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.
  • name (None or str, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • deterministic (bool, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.bit_generator.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See imgaug.augmenters.meta.Augmenter.__init__().

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.SimplexNoiseAlpha(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.SimplexNoiseAlpha(
>>>     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.SimplexNoiseAlpha(
>>>     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.SimplexNoiseAlpha(
>>>     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 second) will be kept, rather than using the results of the augmentation (parameter/branch first).

Methods

__call__(self, \*args, \*\*kwargs) Alias for imgaug.augmenters.meta.Augmenter.augment().
augment(self[, return_batch, hooks]) Augment a batch.
augment_batch(self, batch[, hooks]) Augment a single batch.
augment_batches(self, batches[, hooks, …]) Augment multiple batches.
augment_bounding_boxes(self, …[, hooks]) Augment a batch of bounding boxes.
augment_heatmaps(self, heatmaps[, parents, …]) Augment a batch of heatmaps.
augment_image(self, image[, hooks]) Augment a single image.
augment_images(self, images[, parents, hooks]) Augment a batch of images.
augment_keypoints(self, keypoints_on_images) Augment a batch of keypoints/landmarks.
augment_line_strings(self, …[, parents, hooks]) Augment a batch of line strings.
augment_polygons(self, polygons_on_images[, …]) Augment a batch of polygons.
augment_segmentation_maps(self, segmaps[, …]) Augment a batch of segmentation maps.
copy(self) Create a shallow copy of this Augmenter instance.
copy_random_state(self, source[, recursive, …]) Copy the RNGs from a source augmenter sequence.
copy_random_state_(self, source[, …]) Copy the RNGs from a source augmenter sequence (in-place).
deepcopy(self) Create a deep copy of this Augmenter instance.
draw_grid(self, images, rows, cols) Augment images and draw the results as a single grid-like image.
find_augmenters(self, func[, parents, flat]) Find augmenters that match a condition.
find_augmenters_by_name(self, name[, regex, …]) Find augmenter(s) by name.
find_augmenters_by_names(self, names[, …]) Find augmenter(s) by names.
get_all_children(self[, flat]) Get all children of this augmenter as a list.
get_children_lists(self) Get a list of lists of children of this augmenter.
localize_random_state(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
localize_random_state_(self[, recursive]) Assign augmenter-specific RNGs to this augmenter and its children.
pool(self[, processes, maxtasksperchild, seed]) Create a pool used for multicore augmentation.
remove_augmenters(self, func[, copy, …]) Remove this augmenter or children that match a condition.
remove_augmenters_inplace(self, func[, parents]) Remove in-place children of this augmenter that match a condition.
reseed(self[, random_state, deterministic_too]) Reseed this augmenter and all of its children.
show_grid(self, images, rows, cols) Augment images and plot the results as a single grid-like image.
to_deterministic(self[, n]) Convert this augmenter from a stochastic to a deterministic one.
get_parameters  
imgaug.augmenters.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 and B the background image and a is the alpha value. Each pixel intensity is then computed as a * A_ij + (1-a) * B_ij.

dtype support:

* ``uint8``: yes; fully tested
* ``uint16``: yes; fully tested
* ``uint32``: yes; fully tested
* ``uint64``: yes; fully tested (1)
* ``int8``: yes; fully tested
* ``int16``: yes; fully tested
* ``int32``: yes; fully tested
* ``int64``: yes; fully tested (1)
* ``float16``: yes; fully tested
* ``float32``: yes; fully tested
* ``float64``: yes; fully tested (1)
* ``float128``: no (2)
* ``bool``: yes; fully tested (2)

- (1) 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.
- (2) Not available due to the input dtype having to be increased to
      an equivalent float dtype with two times the input resolution.
- (3) Mapped internally to ``float16``.
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 and 1.0. Can be interpreted as the opacity of the foreground image. Values around 1.0 result in only the foreground image being visible. Values around 0.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 exactly 0.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