imgaug.augmenters.arithmetic

Augmenters that perform simple arithmetic changes.

List of augmenters:

class imgaug.augmenters.arithmetic.Add(value=(-20, 20), per_channel=False, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Add a value to all pixels in an image.

Supported dtypes:

See add_scalar().

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

    Value to add to all pixels.

    • If a number, exactly that value will always be used.
    • If a tuple (a, b), then a value from the discrete interval [a..b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then a value will be sampled per image from that parameter.
  • per_channel (bool or float or imgaug.parameters.StochasticParameter, optional) – Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image. If this value is a float p, then for p percent of all images per_channel will be treated as True. If it is a StochasticParameter it is expected to produce samples with values between 0.0 and 1.0, where values >0.5 will lead to per-channel behaviour (i.e. same as True).

  • 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.Add(10)

Always adds a value of 10 to all channels of all pixels of all input images.

>>> aug = iaa.Add((-10, 10))

Adds a value from the discrete interval [-10..10] to all pixels of input images. The exact value is sampled per image.

>>> aug = iaa.Add((-10, 10), per_channel=True)

Adds a value from the discrete interval [-10..10] to all pixels of input images. The exact value is sampled per image and channel, i.e. to a red-channel it might add 5 while subtracting 7 from the blue channel of the same image.

>>> aug = iaa.Add((-10, 10), per_channel=0.5)

Identical to the previous example, but the per_channel feature is only active for 50 percent of all images.

Methods

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

See get_parameters().

class imgaug.augmenters.arithmetic.AddElementwise(value=(-20, 20), per_channel=False, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Add to the pixels of images values that are pixelwise randomly sampled.

While the Add Augmenter samples one value to add per image (and optionally per channel), this augmenter samples different values per image and per pixel (and optionally per channel), i.e. intensities of neighbouring pixels may be increased/decreased by different amounts.

Supported dtypes:

See add_elementwise().

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

    Value to add to the pixels.

    • If an int, exactly that value will always be used.
    • If a tuple (a, b), then values from the discrete interval [a..b] will be sampled per image and pixel.
    • If a list of integers, a random value will be sampled from the list per image and pixel.
    • If a StochasticParameter, then values will be sampled per image and pixel from that parameter.
  • per_channel (bool or float or imgaug.parameters.StochasticParameter, optional) – Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image. If this value is a float p, then for p percent of all images per_channel will be treated as True. If it is a StochasticParameter it is expected to produce samples with values between 0.0 and 1.0, where values >0.5 will lead to per-channel behaviour (i.e. same as True).

  • 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.AddElementwise(10)

Always adds a value of 10 to all channels of all pixels of all input images.

>>> aug = iaa.AddElementwise((-10, 10))

Samples per image and pixel a value from the discrete interval [-10..10] and adds that value to the respective pixel.

>>> aug = iaa.AddElementwise((-10, 10), per_channel=True)

Samples per image, pixel and also channel a value from the discrete interval [-10..10] and adds it to the respective pixel’s channel value. Therefore, added values may differ between channels of the same pixel.

>>> aug = iaa.AddElementwise((-10, 10), per_channel=0.5)

Identical to the previous example, but the per_channel feature is only active for 50 percent of all images.

Methods

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

See get_parameters().

class imgaug.augmenters.arithmetic.AdditiveGaussianNoise(loc=0, scale=(0, 15), per_channel=False, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.arithmetic.AddElementwise

Add noise sampled from gaussian distributions elementwise to images.

This augmenter samples and adds noise elementwise, i.e. it can add different noise values to neighbouring pixels and is comparable to AddElementwise.

Supported dtypes:

See AddElementwise.

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

    Mean of the normal distribution from which the noise is sampled.

    • If a number, exactly that value will always be used.
    • If a tuple (a, b), a random value from the interval [a, b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, a value will be sampled from the parameter per image.
  • scale (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Standard deviation of the normal distribution that generates the noise. Must be >=0. If 0 then loc will simply be added to all pixels.

    • If a number, exactly that value will always be used.
    • If a tuple (a, b), a random value from the interval [a, b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, a value will be sampled from the parameter per image.
  • per_channel (bool or float or imgaug.parameters.StochasticParameter, optional) – Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image. If this value is a float p, then for p percent of all images per_channel will be treated as True. If it is a StochasticParameter it is expected to produce samples with values between 0.0 and 1.0, where values >0.5 will lead to per-channel behaviour (i.e. same as True).

  • 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.AdditiveGaussianNoise(scale=0.1*255)

Adds gaussian noise from the distribution N(0, 0.1*255) to images. The samples are drawn per image and pixel.

>>> aug = iaa.AdditiveGaussianNoise(scale=(0, 0.1*255))

Adds gaussian noise from the distribution N(0, s) to images, where s is sampled per image from the interval [0, 0.1*255].

>>> aug = iaa.AdditiveGaussianNoise(scale=0.1*255, per_channel=True)

Adds gaussian noise from the distribution N(0, 0.1*255) to images, where the noise value is different per image and pixel and channel (e.g. a different one for red, green and blue channels of the same pixel). This leads to “colorful” noise.

>>> aug = iaa.AdditiveGaussianNoise(scale=0.1*255, per_channel=0.5)

Identical to the previous example, but the per_channel feature is only active for 50 percent of all images.

Methods

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

Bases: imgaug.augmenters.arithmetic.AddElementwise

Add noise sampled from laplace distributions elementwise to images.

The laplace distribution is similar to the gaussian distribution, but puts more weight on the long tail. Hence, this noise will add more outliers (very high/low values). It is somewhere between gaussian noise and salt and pepper noise.

Values of around 255 * 0.05 for scale lead to visible noise (for uint8). Values of around 255 * 0.10 for scale lead to very visible noise (for uint8). It is recommended to usually set per_channel to True.

This augmenter samples and adds noise elementwise, i.e. it can add different noise values to neighbouring pixels and is comparable to AddElementwise.

Supported dtypes:

See AddElementwise.

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

    Mean of the laplace distribution that generates the noise.

    • If a number, exactly that value will always be used.
    • If a tuple (a, b), a random value from the interval [a, b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, a value will be sampled from the parameter per image.
  • scale (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Standard deviation of the laplace distribution that generates the noise. Must be >=0. If 0 then only loc will be used. Recommended to be around 255*0.05.

    • If a number, exactly that value will always be used.
    • If a tuple (a, b), a random value from the interval [a, b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, a value will be sampled from the parameter per image.
  • per_channel (bool or float or imgaug.parameters.StochasticParameter, optional) – Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image. If this value is a float p, then for p percent of all images per_channel will be treated as True. If it is a StochasticParameter it is expected to produce samples with values between 0.0 and 1.0, where values >0.5 will lead to per-channel behaviour (i.e. same as True).

  • 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.AdditiveLaplaceNoise(scale=0.1*255)

Adds laplace noise from the distribution Laplace(0, 0.1*255) to images. The samples are drawn per image and pixel.

>>> aug = iaa.AdditiveLaplaceNoise(scale=(0, 0.1*255))

Adds laplace noise from the distribution Laplace(0, s) to images, where s is sampled per image from the interval [0, 0.1*255].

>>> aug = iaa.AdditiveLaplaceNoise(scale=0.1*255, per_channel=True)

Adds laplace noise from the distribution Laplace(0, 0.1*255) to images, where the noise value is different per image and pixel and channel (e.g. a different one for the red, green and blue channels of the same pixel). This leads to “colorful” noise.

>>> aug = iaa.AdditiveLaplaceNoise(scale=0.1*255, per_channel=0.5)

Identical to the previous example, but the per_channel feature is only active for 50 percent of all images.

Methods

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

Bases: imgaug.augmenters.arithmetic.AddElementwise

Add noise sampled from poisson distributions elementwise to images.

Poisson noise is comparable to gaussian noise, as e.g. generated via AdditiveGaussianNoise. As poisson distributions produce only positive numbers, the sign of the sampled values are here randomly flipped.

Values of around 10.0 for lam lead to visible noise (for uint8). Values of around 20.0 for lam lead to very visible noise (for uint8). It is recommended to usually set per_channel to True.

This augmenter samples and adds noise elementwise, i.e. it can add different noise values to neighbouring pixels and is comparable to AddElementwise.

Supported dtypes:

See AddElementwise.

Parameters:
  • lam (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Lambda parameter of the poisson distribution. Must be >=0. Recommended values are around 0.0 to 10.0.

    • If a number, exactly that value will always be used.
    • If a tuple (a, b), a random value from the interval [a, b] will be sampled per image.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, a value will be sampled from the parameter per image.
  • per_channel (bool or float or imgaug.parameters.StochasticParameter, optional) – Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image. If this value is a float p, then for p percent of all images per_channel will be treated as True. If it is a StochasticParameter it is expected to produce samples with values between 0.0 and 1.0, where values >0.5 will lead to per-channel behaviour (i.e. same as True).

  • 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.AdditivePoissonNoise(lam=5.0)

Adds poisson noise sampled from a poisson distribution with a lambda parameter of 5.0 to images. The samples are drawn per image and pixel.

>>> aug = iaa.AdditivePoissonNoise(lam=(0.0, 15.0))

Adds poisson noise sampled from Poisson(x) to images, where x is randomly sampled per image from the interval [0.0, 15.0].

>>> aug = iaa.AdditivePoissonNoise(lam=5.0, per_channel=True)

Adds poisson noise sampled from Poisson(5.0) to images, where the values are different per image and pixel and channel (e.g. a different one for red, green and blue channels for the same pixel).

>>> aug = iaa.AdditivePoissonNoise(lam=(0.0, 15.0), per_channel=True)

Adds poisson noise sampled from Poisson(x) to images, with x being sampled from uniform(0.0, 15.0) per image and channel. This is the recommended configuration.

>>> aug = iaa.AdditivePoissonNoise(lam=(0.0, 15.0), per_channel=0.5)

Identical to the previous example, but the per_channel feature is only active for 50 percent of all images.

Methods

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

Bases: imgaug.augmenters.arithmetic.MultiplyElementwise

Set rectangular areas within images to zero.

In contrast to Dropout, these areas can have larger sizes. (E.g. you might end up with three large black rectangles in an image.) Note that the current implementation leads to correlated sizes, so if e.g. there is any thin and high rectangle that is dropped, there is a high likelihood that all other dropped areas are also thin and high.

This method is implemented by generating the dropout mask at a lower resolution (than the image has) and then upsampling the mask before dropping the pixels.

This augmenter is similar to Cutout. Usually, cutout is defined as an operation that drops exactly one rectangle from an image, while here CoarseDropout can drop multiple rectangles (with some correlation between the sizes of these rectangles).

Supported dtypes:

See MultiplyElementwise.

Parameters:
  • p (float or tuple of float or imgaug.parameters.StochasticParameter, optional) – The probability of any pixel being dropped (i.e. set to zero) in the lower-resolution dropout mask.

    • If a float, then that value will be used for all pixels. A value of 1.0 would mean, that all pixels will be dropped. A value of 0.0 would lead to no pixels being dropped.
    • If a tuple (a, b), then a value p will be sampled from the interval [a, b] per image and be used as the dropout probability.
    • If a list, then a value will be sampled from that list per batch and used as the probability.
    • If a StochasticParameter, then this parameter will be used to determine per pixel whether it should be kept (sampled value of >0.5) or shouldn’t be kept (sampled value of <=0.5). If you instead want to provide the probability as a stochastic parameter, you can usually do imgaug.parameters.Binomial(1-p) to convert parameter p to a 0/1 representation.
  • size_px (None or int or tuple of int or imgaug.parameters.StochasticParameter, optional) – The size of the lower resolution image from which to sample the dropout mask in absolute pixel dimensions. Note that this means that lower values of this parameter lead to larger areas being dropped (as any pixel in the lower resolution image will correspond to a larger area at the original resolution).

    • If None then size_percent must be set.
    • If an integer, then that size will always be used for both height and width. E.g. a value of 3 would lead to a 3x3 mask, which is then upsampled to HxW, where H is the image size and W the image width.
    • If a tuple (a, b), then two values M, N will be sampled from the discrete interval [a..b]. The dropout mask will then be generated at size MxN and upsampled to HxW.
    • If a StochasticParameter, then this parameter will be used to determine the sizes. It is expected to be discrete.
  • size_percent (None or float or tuple of float or imgaug.parameters.StochasticParameter, optional) – The size of the lower resolution image from which to sample the dropout mask in percent of the input image. Note that this means that lower values of this parameter lead to larger areas being dropped (as any pixel in the lower resolution image will correspond to a larger area at the original resolution).

    • If None then size_px must be set.
    • If a float, then that value will always be used as the percentage of the height and width (relative to the original size). E.g. for value p, the mask will be sampled from (p*H)x(p*W) and later upsampled to HxW.
    • If a tuple (a, b), then two values m, n will be sampled from the interval (a, b) and used as the size fractions, i.e the mask size will be (m*H)x(n*W).
    • If a StochasticParameter, then this parameter will be used to sample the percentage values. It is expected to be continuous.
  • per_channel (bool or float or imgaug.parameters.StochasticParameter, optional) – Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image. If this value is a float p, then for p percent of all images per_channel will be treated as True. If it is a StochasticParameter it is expected to produce samples with values between 0.0 and 1.0, where values >0.5 will lead to per-channel behaviour (i.e. same as True).

  • min_size (int, optional) – Minimum height and width of the low resolution mask. If size_percent or size_px leads to a lower value than this, min_size will be used instead. This should never have a value of less than 2, otherwise one may end up with a 1x1 low resolution mask, leading easily to the whole image being dropped.

  • 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.CoarseDropout(0.02, size_percent=0.5)

Drops 2 percent of all pixels on a lower-resolution image that has 50 percent of the original image’s size, leading to dropped areas that have roughly 2x2 pixels size.

>>> aug = iaa.CoarseDropout((0.0, 0.05), size_percent=(0.05, 0.5))

Generates a dropout mask at 5 to 50 percent of each input image’s size. In that mask, 0 to 5 percent of all pixels are marked as being dropped. The mask is afterwards projected to the input image’s size to apply the actual dropout operation.

>>> aug = iaa.CoarseDropout((0.0, 0.05), size_px=(2, 16))

Same as the previous example, but the lower resolution image has 2 to 16 pixels size. On images of e.g. 224x224` pixels in size this would lead to fairly large areas being dropped (height/width of ``224/2 to 224/16).

>>> aug = iaa.CoarseDropout(0.02, size_percent=0.5, per_channel=True)

Drops 2 percent of all pixels at 50 percent resolution (2x2 sizes) in a channel-wise fashion, i.e. it is unlikely for any pixel to have all channels set to zero (black pixels).

>>> aug = iaa.CoarseDropout(0.02, size_percent=0.5, per_channel=0.5)

Same as the previous example, but the per_channel feature is only active for 50 percent of all images.

Methods

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

Bases: imgaug.augmenters.arithmetic.ReplaceElementwise

Replace rectangular areas in images with black-ish pixel noise.

Supported dtypes:

See ReplaceElementwise.

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

    Probability of changing a pixel to pepper noise.

    • If a float, then that value will always be used as the probability.
    • If a tuple (a, b), then a probability will be sampled uniformly per image from the interval [a, b].
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then a lower-resolution mask will be sampled from that parameter per image. Any value >0.5 in that mask will denote a spatial location that is to be replaced by pepper noise.
  • size_px (int or tuple of int or imgaug.parameters.StochasticParameter, optional) – The size of the lower resolution image from which to sample the replacement mask in absolute pixel dimensions. Note that this means that lower values of this parameter lead to larger areas being replaced (as any pixel in the lower resolution image will correspond to a larger area at the original resolution).

    • If None then size_percent must be set.
    • If an integer, then that size will always be used for both height and width. E.g. a value of 3 would lead to a 3x3 mask, which is then upsampled to HxW, where H is the image size and W the image width.
    • If a tuple (a, b), then two values M, N will be sampled from the discrete interval [a..b]. The mask will then be generated at size MxN and upsampled to HxW.
    • If a StochasticParameter, then this parameter will be used to determine the sizes. It is expected to be discrete.
  • size_percent (float or tuple of float or imgaug.parameters.StochasticParameter, optional) – The size of the lower resolution image from which to sample the replacement mask in percent of the input image. Note that this means that lower values of this parameter lead to larger areas being replaced (as any pixel in the lower resolution image will correspond to a larger area at the original resolution).

    • If None then size_px must be set.
    • If a float, then that value will always be used as the percentage of the height and width (relative to the original size). E.g. for value p, the mask will be sampled from (p*H)x(p*W) and later upsampled to HxW.
    • If a tuple (a, b), then two values m, n will be sampled from the interval (a, b) and used as the size fractions, i.e the mask size will be (m*H)x(n*W).
    • If a StochasticParameter, then this parameter will be used to sample the percentage values. It is expected to be continuous.
  • per_channel (bool or float or imgaug.parameters.StochasticParameter, optional) – Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image. If this value is a float p, then for p percent of all images per_channel will be treated as True. If it is a StochasticParameter it is expected to produce samples with values between 0.0 and 1.0, where values >0.5 will lead to per-channel behaviour (i.e. same as True).

  • min_size (int, optional) – Minimum size of the low resolution mask, both width and height. If size_percent or size_px leads to a lower value than this, min_size will be used instead. This should never have a value of less than 2, otherwise one may end up with a 1x1 low resolution mask, leading easily to the whole image being replaced.

  • 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.CoarsePepper(0.05, size_percent=(0.01, 0.1))

Mark 5% of all pixels in a mask to be replaced by pepper noise. The mask has 1% to 10% the size of the input image. The mask is then upscaled to the input image size, leading to large rectangular areas being marked as to be replaced. These areas are then replaced in the input image by pepper noise.

Methods

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

Bases: imgaug.augmenters.arithmetic.ReplaceElementwise

Replace rectangular areas in images with white-ish pixel noise.

See also the similar CoarseSaltAndPepper.

Supported dtypes:

See ReplaceElementwise.

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

    Probability of changing a pixel to salt noise.

    • If a float, then that value will always be used as the probability.
    • If a tuple (a, b), then a probability will be sampled uniformly per image from the interval [a, b].
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then a lower-resolution mask will be sampled from that parameter per image. Any value >0.5 in that mask will denote a spatial location that is to be replaced by salt noise.
  • size_px (int or tuple of int or imgaug.parameters.StochasticParameter, optional) – The size of the lower resolution image from which to sample the replacement mask in absolute pixel dimensions. Note that this means that lower values of this parameter lead to larger areas being replaced (as any pixel in the lower resolution image will correspond to a larger area at the original resolution).

    • If None then size_percent must be set.
    • If an integer, then that size will always be used for both height and width. E.g. a value of 3 would lead to a 3x3 mask, which is then upsampled to HxW, where H is the image size and W the image width.
    • If a tuple (a, b), then two values M, N will be sampled from the discrete interval [a..b]. The mask will then be generated at size MxN and upsampled to HxW.
    • If a StochasticParameter, then this parameter will be used to determine the sizes. It is expected to be discrete.
  • size_percent (float or tuple of float or imgaug.parameters.StochasticParameter, optional) – The size of the lower resolution image from which to sample the replacement mask in percent of the input image. Note that this means that lower values of this parameter lead to larger areas being replaced (as any pixel in the lower resolution image will correspond to a larger area at the original resolution).

    • If None then size_px must be set.
    • If a float, then that value will always be used as the percentage of the height and width (relative to the original size). E.g. for value p, the mask will be sampled from (p*H)x(p*W) and later upsampled to HxW.
    • If a tuple (a, b), then two values m, n will be sampled from the interval (a, b) and used as the size fractions, i.e the mask size will be (m*H)x(n*W).
    • If a StochasticParameter, then this parameter will be used to sample the percentage values. It is expected to be continuous.
  • per_channel (bool or float or imgaug.parameters.StochasticParameter, optional) – Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image. If this value is a float p, then for p percent of all images per_channel will be treated as True. If it is a StochasticParameter it is expected to produce samples with values between 0.0 and 1.0, where values >0.5 will lead to per-channel behaviour (i.e. same as True).

  • min_size (int, optional) – Minimum height and width of the low resolution mask. If size_percent or size_px leads to a lower value than this, min_size will be used instead. This should never have a value of less than 2, otherwise one may end up with a 1x1 low resolution mask, leading easily to the whole image being replaced.

  • 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.CoarseSalt(0.05, size_percent=(0.01, 0.1))

Mark 5% of all pixels in a mask to be replaced by salt noise. The mask has 1% to 10% the size of the input image. The mask is then upscaled to the input image size, leading to large rectangular areas being marked as to be replaced. These areas are then replaced in the input image by salt noise.

Methods

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

Bases: imgaug.augmenters.arithmetic.ReplaceElementwise

Replace rectangular areas in images with white/black-ish pixel noise.

This adds salt and pepper noise (noisy white-ish and black-ish pixels) to rectangular areas within the image. Note that this means that within these rectangular areas the color varies instead of each rectangle having only one color.

See also the similar CoarseDropout.

TODO replace dtype support with uint8 only, because replacement is
geared towards that value range

Supported dtypes:

See ReplaceElementwise.

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

    Probability of changing a pixel to salt/pepper noise.

    • If a float, then that value will always be used as the probability.
    • If a tuple (a, b), then a probability will be sampled uniformly per image from the interval [a, b].
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then a lower-resolution mask will be sampled from that parameter per image. Any value >0.5 in that mask will denote a spatial location that is to be replaced by salt and pepper noise.
  • size_px (int or tuple of int or imgaug.parameters.StochasticParameter, optional) – The size of the lower resolution image from which to sample the replacement mask in absolute pixel dimensions. Note that this means that lower values of this parameter lead to larger areas being replaced (as any pixel in the lower resolution image will correspond to a larger area at the original resolution).

    • If None then size_percent must be set.
    • If an integer, then that size will always be used for both height and width. E.g. a value of 3 would lead to a 3x3 mask, which is then upsampled to HxW, where H is the image size and W the image width.
    • If a tuple (a, b), then two values M, N will be sampled from the discrete interval [a..b]. The mask will then be generated at size MxN and upsampled to HxW.
    • If a StochasticParameter, then this parameter will be used to determine the sizes. It is expected to be discrete.
  • size_percent (float or tuple of float or imgaug.parameters.StochasticParameter, optional) – The size of the lower resolution image from which to sample the replacement mask in percent of the input image. Note that this means that lower values of this parameter lead to larger areas being replaced (as any pixel in the lower resolution image will correspond to a larger area at the original resolution).

    • If None then size_px must be set.
    • If a float, then that value will always be used as the percentage of the height and width (relative to the original size). E.g. for value p, the mask will be sampled from (p*H)x(p*W) and later upsampled to HxW.
    • If a tuple (a, b), then two values m, n will be sampled from the interval (a, b) and used as the size fractions, i.e the mask size will be (m*H)x(n*W).
    • If a StochasticParameter, then this parameter will be used to sample the percentage values. It is expected to be continuous.
  • per_channel (bool or float or imgaug.parameters.StochasticParameter, optional) – Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image. If this value is a float p, then for p percent of all images per_channel will be treated as True. If it is a StochasticParameter it is expected to produce samples with values between 0.0 and 1.0, where values >0.5 will lead to per-channel behaviour (i.e. same as True).

  • min_size (int, optional) – Minimum height and width of the low resolution mask. If size_percent or size_px leads to a lower value than this, min_size will be used instead. This should never have a value of less than 2, otherwise one may end up with a 1x1 low resolution mask, leading easily to the whole image being replaced.

  • 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.CoarseSaltAndPepper(0.05, size_percent=(0.01, 0.1))

Marks 5% of all pixels in a mask to be replaced by salt/pepper noise. The mask has 1% to 10% the size of the input image. The mask is then upscaled to the input image size, leading to large rectangular areas being marked as to be replaced. These areas are then replaced in the input image by salt/pepper noise.

>>> aug = iaa.CoarseSaltAndPepper(0.05, size_px=(4, 16))

Same as in the previous example, but the replacement mask before upscaling has a size between 4x4 and 16x16 pixels (the axis sizes are sampled independently, i.e. the mask may be rectangular).

>>> aug = iaa.CoarseSaltAndPepper(
>>>    0.05, size_percent=(0.01, 0.1), per_channel=True)

Same as in the first example, but mask and replacement are each sampled independently per image channel.

Methods

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

Deprecated. Use imgaug.contrast.LinearContrast instead.

Change the contrast of images.

dtype support:

See imgaug.augmenters.contrast.LinearContrast.

Deprecated since 0.3.0.

Parameters:
  • alpha (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Strength of the contrast normalization. Higher values than 1.0 lead to higher contrast, lower values decrease the contrast.

    • If a number, then that value will be used for all images.
    • If a tuple (a, b), then a value will be sampled per image uniformly from the interval [a, b] and be used as the alpha value.
    • If a list, then a random value will be picked per image from that list.
    • If a StochasticParameter, then this parameter will be used to sample the alpha value per image.
  • per_channel (bool or float or imgaug.parameters.StochasticParameter, optional) – Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image. If this value is a float p, then for p percent of all images per_channel will be treated as True. If it is a StochasticParameter it is expected to produce samples with values between 0.0 and 1.0, where values >0.5 will lead to per-channel behaviour (i.e. same as True).

  • 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
>>> iaa.ContrastNormalization((0.5, 1.5))

Decreases oder improves contrast per image by a random factor between 0.5 and 1.5. The factor 0.5 means that any difference from the center value (i.e. 128) will be halved, leading to less contrast.

>>> iaa.ContrastNormalization((0.5, 1.5), per_channel=0.5)

Same as before, but for 50 percent of all images the normalization is done independently per channel (i.e. factors can vary per channel for the same image). In the other 50 percent of all images, the factor is the same for all channels.

class imgaug.augmenters.arithmetic.Cutout(nb_iterations=1, position='uniform', size=0.2, squared=True, fill_mode='constant', cval=128, fill_per_channel=False, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Fill one or more rectangular areas in an image using a fill mode.

See paper “Improved Regularization of Convolutional Neural Networks with Cutout” by DeVries and Taylor.

In contrast to the paper, this implementation also supports replacing image sub-areas with gaussian noise, random intensities or random RGB colors. It also supports non-squared areas. While the paper uses absolute pixel values for the size and position, this implementation uses relative values, which seems more appropriate for mixed-size datasets. The position parameter furthermore allows more flexibility, e.g. gaussian distributions around the center.

Note

This augmenter affects only image data. Other datatypes (e.g. segmentation map pixels or keypoints within the filled areas) are not affected.

Note

Gaussian fill mode will assume that float input images contain values in the interval [0.0, 1.0] and hence sample values from a gaussian within that interval, i.e. from N(0.5, std=0.5/3).

Added in 0.4.0.

Supported dtypes:

See cutout_().

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

    How many rectangular areas to fill.

    • If int: Exactly that many areas will be filled on all images.
    • If tuple (a, b): A value from the interval [a, b] will be sampled per image.
    • If list: A random value will be sampled from that list per image.
    • If StochasticParameter: That parameter will be used to sample (B,) values per batch of B images.
  • position ({‘uniform’, ‘normal’, ‘center’, ‘left-top’, ‘left-center’, ‘left-bottom’, ‘center-top’, ‘center-center’, ‘center-bottom’, ‘right-top’, ‘right-center’, ‘right-bottom’} or tuple of float or StochasticParameter or tuple of StochasticParameter, optional) – Defines the position of each area to fill. Analogous to the definition in e.g. CropToFixedSize. Usually, uniform (anywhere in the image) or normal (anywhere in the image with preference around the center) are sane values.

  • size (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – The size of the rectangle to fill as a fraction of the corresponding image size, i.e. with value range [0.0, 1.0]. The size is sampled independently per image axis.

    • If number: Exactly that size is always used.
    • If tuple (a, b): A value from the interval [a, b] will be sampled per area and axis.
    • If list: A random value will be sampled from that list per area and axis.
    • If StochasticParameter: That parameter will be used to sample (N, 2) values per batch, where N is the total number of areas to fill within the whole batch.
  • squared (bool or float or imgaug.parameters.StochasticParameter, optional) – Whether to generate only squared areas cutout areas or allow rectangular ones. If this evaluates to a true-like value, the first value from size will be converted to absolute pixels and used for both axes.

    If this value is a float p, then for p percent of all areas to be filled per_channel will be treated as True. If it is a StochasticParameter it is expected to produce samples with values between 0.0 and 1.0, where values >0.5 will lead to per-channel behaviour (i.e. same as True).

  • fill_mode (str or list of str or imgaug.parameters.StochasticParameter, optional) – Mode to use in order to fill areas. Corresponds to mode parameter in some other augmenters. Valid strings for the mode are:

    • contant: Fill each area with a single value.
    • gaussian: Fill each area with gaussian noise.

    Valid datatypes are:

    • If str: Exactly that mode will alaways be used.
    • If list: A random value will be sampled from that list per area.
    • If StochasticParameter: That parameter will be used to sample (N,) values per batch, where N is the total number of areas to fill within the whole batch.
  • cval (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – The value to use (i.e. the color) to fill areas if fill_mode is `constant.

    • If number: Exactly that value is used for all areas and channels.
    • If tuple (a, b): A value from the interval [a, b] will be sampled per area (and channel if per_channel=True).
    • If list: A random value will be sampled from that list per area (and channel if per_channel=True).
    • If StochasticParameter: That parameter will be used to sample (N, Cmax) values per batch, where N is the total number of areas to fill within the whole batch and Cmax is the maximum number of channels in any image (usually 3). If per_channel=False, only the first value of the second axis is used.
  • fill_per_channel (bool or float or imgaug.parameters.StochasticParameter, optional) – Whether to fill each area in a channelwise fashion (True) or not (False). The behaviour per fill mode is:

    • constant: Whether to fill all channels with the same value (i.e, grayscale) or different values (i.e. usually RGB color).
    • gaussian: Whether to sample once from a gaussian and use the values for all channels (i.e. grayscale) or to sample channelwise (i.e. RGB colors)

    If this value is a float p, then for p percent of all areas to be filled per_channel will be treated as True. If it is a StochasticParameter it is expected to produce samples with values between 0.0 and 1.0, where values >0.5 will lead to per-channel behaviour (i.e. same as True).

  • name (None or str, optional) – See __init__().

  • deterministic (bool, optional) – See __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 __init__().

Examples

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

Fill per image two random areas, by default with grayish pixels.

>>> aug = iaa.Cutout(nb_iterations=(1, 5), size=0.2, squared=False)

Fill per image between one and five areas, each having 20% of the corresponding size of the height and width (for non-square images this results in non-square areas to be filled).

>>> aug = iaa.Cutout(fill_mode="constant", cval=255)

Fill all areas with white pixels.

>>> aug = iaa.Cutout(fill_mode="constant", cval=(0, 255),
>>>                  fill_per_channel=0.5)

Fill 50% of all areas with a random intensity value between 0 and 256. Fill the other 50% of all areas with random colors.

>>> aug = iaa.Cutout(fill_mode="gaussian", fill_per_channel=True)

Fill areas with gaussian channelwise noise (i.e. usually RGB).

Methods

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

See get_parameters().

class imgaug.augmenters.arithmetic.Dropout(p=(0.0, 0.05), per_channel=False, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.arithmetic.MultiplyElementwise

Set a fraction of pixels in images to zero.

Supported dtypes:

See MultiplyElementwise.

Parameters:
  • p (float or tuple of float or imgaug.parameters.StochasticParameter, optional) –

    The probability of any pixel being dropped (i.e. to set it to zero).

    • If a float, then that value will be used for all images. A value of 1.0 would mean that all pixels will be dropped and 0.0 that no pixels will be dropped. A value of 0.05 corresponds to 5 percent of all pixels being dropped.
    • If a tuple (a, b), then a value p will be sampled from the interval [a, b] per image and be used as the pixel’s dropout probability.
    • If a list, then a value will be sampled from that list per batch and used as the probability.
    • If a StochasticParameter, then this parameter will be used to determine per pixel whether it should be kept (sampled value of >0.5) or shouldn’t be kept (sampled value of <=0.5). If you instead want to provide the probability as a stochastic parameter, you can usually do imgaug.parameters.Binomial(1-p) to convert parameter p to a 0/1 representation.
  • per_channel (bool or float or imgaug.parameters.StochasticParameter, optional) – Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image. If this value is a float p, then for p percent of all images per_channel will be treated as True. If it is a StochasticParameter it is expected to produce samples with values between 0.0 and 1.0, where values >0.5 will lead to per-channel behaviour (i.e. same as True).

  • 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.Dropout(0.02)

Drops 2 percent of all pixels.

>>> aug = iaa.Dropout((0.0, 0.05))

Drops in each image a random fraction of all pixels, where the fraction is uniformly sampled from the interval [0.0, 0.05].

>>> aug = iaa.Dropout(0.02, per_channel=True)

Drops 2 percent of all pixels in a channelwise fashion, i.e. it is unlikely for any pixel to have all channels set to zero (black pixels).

>>> aug = iaa.Dropout(0.02, per_channel=0.5)

Identical to the previous example, but the per_channel feature is only active for 50 percent of all images.

Methods

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

Bases: imgaug.augmenters.meta.Augmenter

Drop random channels from images.

For image data, dropped channels will be filled with zeros.

Note

This augmenter may also set the arrays of heatmaps and segmentation maps to zero and remove all coordinate-based data (e.g. it removes all bounding boxes on images that were filled with zeros). It does so if and only if all channels of an image are dropped. If nb_keep_channels >= 1 then that never happens.

Added in 0.4.0.

Supported dtypes:

  • uint8: yes; fully tested
  • uint16: yes; tested
  • uint32: yes; tested
  • uint64: yes; tested
  • int8: yes; tested
  • int16: yes; tested
  • int32: yes; tested
  • int64: yes; tested
  • float16: yes; tested
  • float32: yes; tested
  • float64: yes; tested
  • float128: yes; tested
  • bool: yes; tested
Parameters:
  • p (float or tuple of float or imgaug.parameters.StochasticParameter, optional) –

    The probability of any channel to be dropped (i.e. set to zero).

    • If a float, then that value will be used for all channels. A value of 1.0 would mean, that all channels will be dropped. A value of 0.0 would lead to no channels being dropped.
    • If a tuple (a, b), then a value p will be sampled from the interval [a, b) per batch and be used as the dropout probability.
    • If a list, then a value will be sampled from that list per batch and used as the probability.
    • If a StochasticParameter, then this parameter will be used to determine per channel whether it should be kept (sampled value of >=0.5) or shouldn’t be kept (sampled value of <0.5). If you instead want to provide the probability as a stochastic parameter, you can usually do imgaug.parameters.Binomial(1-p) to convert parameter p to a 0/1 representation.
  • nb_keep_channels (int) – Minimum number of channels to keep unaltered in all images. E.g. a value of 1 means that at least one channel in every image will not be dropped, even if p=1.0. Set to 0 to allow dropping all channels.

  • 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.Dropout2d(p=0.5)

Create a dropout augmenter that drops on average half of all image channels. Dropped channels will be filled with zeros. At least one channel is kept unaltered in each image (default setting).

>>> import imgaug.augmenters as iaa
>>> aug = iaa.Dropout2d(p=0.5, nb_keep_channels=0)

Create a dropout augmenter that drops on average half of all image channels and may drop all channels in an image (i.e. images may contain nothing but zeros).

Methods

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

See get_parameters().

class imgaug.augmenters.arithmetic.ImpulseNoise(p=(0.0, 0.03), seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.arithmetic.SaltAndPepper

Add impulse noise to images.

This is identical to SaltAndPepper, except that per_channel is always set to True.

Supported dtypes:

See SaltAndPepper.

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

    Probability of replacing a pixel to impulse noise.

    • If a float, then that value will always be used as the probability.
    • If a tuple (a, b), then a probability will be sampled uniformly per image from the interval [a, b].
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then a image-sized mask will be sampled from that parameter per image. Any value >0.5 in that mask will be replaced with impulse noise noise.
  • 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.ImpulseNoise(0.1)

Replace 10% of all pixels with impulse noise.

Methods

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

Bases: imgaug.augmenters.meta.Augmenter

Invert all values in images, e.g. turn 5 into 255-5=250.

For the standard value range of 0-255 it converts 0 to 255, 255 to 0 and 10 to (255-10)=245. Let M be the maximum value possible, m the minimum value possible, v a value. Then the distance of v to m is d=abs(v-m) and the new value is given by v'=M-d.

Supported dtypes:

See invert_().

Parameters:
  • p (float or imgaug.parameters.StochasticParameter, optional) –

    The probability of an image to be inverted.

    • If a float, then that probability will be used for all images, i.e. p percent of all images will be inverted.
    • If a StochasticParameter, then that parameter will be queried per image and is expected to return values in the interval [0.0, 1.0], where values >0.5 mean that the image is supposed to be inverted. Recommended to be some form of imgaug.parameters.Binomial.
  • per_channel (bool or float or imgaug.parameters.StochasticParameter, optional) – Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image. If this value is a float p, then for p percent of all images per_channel will be treated as True. If it is a StochasticParameter it is expected to produce samples with values between 0.0 and 1.0, where values >0.5 will lead to per-channel behaviour (i.e. same as True).

  • min_value (None or number, optional) – Minimum of the value range of input images, e.g. 0 for uint8 images. If set to None, the value will be automatically derived from the image’s dtype.

  • max_value (None or number, optional) – Maximum of the value range of input images, e.g. 255 for uint8 images. If set to None, the value will be automatically derived from the image’s dtype.

  • threshold (None or number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – A threshold to use in order to invert only numbers above or below the threshold. If None no thresholding will be used.

    • If None: No thresholding will be used.
    • If number: The value will be used for all images.
    • If tuple (a, b): A value will be uniformly sampled per image from the interval [a, b).
    • If list: A random value will be picked from the list per image.
    • If StochasticParameter: Per batch of size N, the parameter will be queried once to return (N,) samples.
  • invert_above_threshold (bool or float or imgaug.parameters.StochasticParameter, optional) – If True, only values >=threshold will be inverted. Otherwise, only values <threshold will be inverted. If a number, then expected to be in the interval [0.0, 1.0] and denoting an imagewise probability. If a StochasticParameter then (N,) values will be sampled from the parameter per batch of size N and interpreted as True if >0.5. If threshold is None this parameter has no effect.

  • 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.Invert(0.1)

Inverts the colors in 10 percent of all images.

>>> aug = iaa.Invert(0.1, per_channel=True)

Inverts the colors in 10 percent of all image channels. This may or may not lead to multiple channels in an image being inverted.

>>> aug = iaa.Invert(0.1, per_channel=0.5)

Identical to the previous example, but the per_channel feature is only active for 50 percent of all images.

Methods

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

See get_parameters().

class imgaug.augmenters.arithmetic.JpegCompression(compression=(0, 100), seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Degrade the quality of images by JPEG-compressing them.

During JPEG compression, high frequency components (e.g. edges) are removed. With low compression (strength) only the highest frequency components are removed, while very high compression (strength) will lead to only the lowest frequency components “surviving”. This lowers the image quality. For more details, see https://en.wikipedia.org/wiki/Compression_artifact.

Note that this augmenter still returns images as numpy arrays (i.e. saves the images with JPEG compression and then reloads them into arrays). It does not return the raw JPEG file content.

Supported dtypes:

See compress_jpeg().

Parameters:
  • compression (number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – Degree of compression used during JPEG compression within value range [0, 100]. Higher values denote stronger compression and will cause low-frequency components to disappear. Note that JPEG’s compression strength is also often set as a quality, which is the inverse of this parameter. Common choices for the quality setting are around 80 to 95, depending on the image. This translates here to a compression parameter of around 20 to 5.

    • If a single number, then that value always will be used as the compression.
    • If a tuple (a, b), then the compression will be a value sampled uniformly from the interval [a, b].
    • If a list, then a random value will be sampled from that list per image and used as the compression.
    • If a StochasticParameter, then N samples will be drawn from that parameter per N input images, each representing the compression for the n-th image.
  • seed (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – See __init__().

  • name (None or str, optional) – See __init__().

  • random_state (None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional) – Old name for parameter seed. Its usage will not yet cause a deprecation warning, but it is still recommended to use seed now. Outdated since 0.4.0.

  • deterministic (bool, optional) – Deprecated since 0.4.0. See method to_deterministic() for an alternative and for details about what the “deterministic mode” actually does.

Examples

>>> import imgaug.augmenters as iaa
>>> aug = iaa.JpegCompression(compression=(70, 99))

Remove high frequency components in images via JPEG compression with a compression strength between 70 and 99 (randomly and uniformly sampled per image). This corresponds to a (very low) quality setting of 1 to 30.

Methods

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

See get_parameters().

class imgaug.augmenters.arithmetic.Multiply(mul=(0.8, 1.2), per_channel=False, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Multiply all pixels in an image with a random value sampled once per image.

This augmenter can be used to make images lighter or darker.

Supported dtypes:

See multiply_scalar().

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

    The value with which to multiply the pixel values in each image.

    • If a number, then that value will always be used.
    • If a tuple (a, b), then a value from the interval [a, b] will be sampled per image and used for all pixels.
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then that parameter will be used to sample a new value per image.
  • per_channel (bool or float or imgaug.parameters.StochasticParameter, optional) – Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image. If this value is a float p, then for p percent of all images per_channel will be treated as True. If it is a StochasticParameter it is expected to produce samples with values between 0.0 and 1.0, where values >0.5 will lead to per-channel behaviour (i.e. same as True).

  • 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.Multiply(2.0)

Multiplies all images by a factor of 2, making the images significantly brighter.

>>> aug = iaa.Multiply((0.5, 1.5))

Multiplies images by a random value sampled uniformly from the interval [0.5, 1.5], making some images darker and others brighter.

>>> aug = iaa.Multiply((0.5, 1.5), per_channel=True)

Identical to the previous example, but the sampled multipliers differ by image and channel, instead of only by image.

>>> aug = iaa.Multiply((0.5, 1.5), per_channel=0.5)

Identical to the previous example, but the per_channel feature is only active for 50 percent of all images.

Methods

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

See get_parameters().

class imgaug.augmenters.arithmetic.MultiplyElementwise(mul=(0.8, 1.2), per_channel=False, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.meta.Augmenter

Multiply image pixels with values that are pixelwise randomly sampled.

While the Multiply Augmenter uses a constant multiplier per image (and optionally channel), this augmenter samples the multipliers to use per image and per pixel (and optionally per channel).

Supported dtypes:

See multiply_elementwise().

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

    The value with which to multiply pixel values in the image.

    • If a number, then that value will always be used.
    • If a tuple (a, b), then a value from the interval [a, b] will be sampled per image and pixel.
    • If a list, then a random value will be sampled from that list per image and pixel.
    • If a StochasticParameter, then that parameter will be used to sample a new value per image and pixel.
  • per_channel (bool or float or imgaug.parameters.StochasticParameter, optional) – Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image. If this value is a float p, then for p percent of all images per_channel will be treated as True. If it is a StochasticParameter it is expected to produce samples with values between 0.0 and 1.0, where values >0.5 will lead to per-channel behaviour (i.e. same as True).

  • 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.MultiplyElementwise(2.0)

Multiply all images by a factor of 2.0, making them significantly bighter.

>>> aug = iaa.MultiplyElementwise((0.5, 1.5))

Samples per image and pixel uniformly a value from the interval [0.5, 1.5] and multiplies the pixel with that value.

>>> aug = iaa.MultiplyElementwise((0.5, 1.5), per_channel=True)

Samples per image and pixel and channel uniformly a value from the interval [0.5, 1.5] and multiplies the pixel with that value. Therefore, used multipliers may differ between channels of the same pixel.

>>> aug = iaa.MultiplyElementwise((0.5, 1.5), per_channel=0.5)

Identical to the previous example, but the per_channel feature is only active for 50 percent of all images.

Methods

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

See get_parameters().

class imgaug.augmenters.arithmetic.Pepper(p=(0.0, 0.05), per_channel=False, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.arithmetic.ReplaceElementwise

Replace pixels in images with pepper noise, i.e. black-ish pixels.

This augmenter is similar to SaltAndPepper, but adds no salt noise to images.

This augmenter is similar to Dropout, but slower and the black pixels are not uniformly black.

Supported dtypes:

See ReplaceElementwise.

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

    Probability of replacing a pixel with pepper noise.

    • If a float, then that value will always be used as the probability.
    • If a tuple (a, b), then a probability will be sampled uniformly per image from the interval [a, b].
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then a image-sized mask will be sampled from that parameter per image. Any value >0.5 in that mask will be replaced with pepper noise.
  • per_channel (bool or float or imgaug.parameters.StochasticParameter, optional) – Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image. If this value is a float p, then for p percent of all images per_channel will be treated as True. If it is a StochasticParameter it is expected to produce samples with values between 0.0 and 1.0, where values >0.5 will lead to per-channel behaviour (i.e. same as True).

  • 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.Pepper(0.05)

Replace 5% of all pixels with pepper noise (black-ish colors).

Methods

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

Bases: imgaug.augmenters.meta.Augmenter

Replace pixels in an image with new values.

Supported dtypes:

See replace_elementwise_().

Parameters:
  • mask (float or tuple of float or list of float or imgaug.parameters.StochasticParameter) – Mask that indicates the pixels that are supposed to be replaced. The mask will be binarized using a threshold of 0.5. A value of 1 then indicates a pixel that is supposed to be replaced.

    • If this is a float, then that value will be used as the probability of being a 1 in the mask (sampled per image and pixel) and hence being replaced.
    • If a tuple (a, b), then the probability will be uniformly sampled per image from the interval [a, b].
    • If a list, then a random value will be sampled from that list per image and pixel.
    • If a StochasticParameter, then this parameter will be used to sample a mask per image.
  • replacement (number or tuple of number or list of number or imgaug.parameters.StochasticParameter) – The replacement to use at all locations that are marked as 1 in the mask.

    • If this is a number, then that value will always be used as the replacement.
    • If a tuple (a, b), then the replacement will be sampled uniformly per image and pixel from the interval [a, b].
    • If a list, then a random value will be sampled from that list per image and pixel.
    • If a StochasticParameter, then this parameter will be used sample replacement values per image and pixel.
  • per_channel (bool or float or imgaug.parameters.StochasticParameter, optional) – Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image. If this value is a float p, then for p percent of all images per_channel will be treated as True. If it is a StochasticParameter it is expected to produce samples with values between 0.0 and 1.0, where values >0.5 will lead to per-channel behaviour (i.e. same as True).

  • 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 = ReplaceElementwise(0.05, [0, 255])

Replaces 5 percent of all pixels in each image by either 0 or 255.

>>> import imgaug.augmenters as iaa
>>> aug = ReplaceElementwise(0.1, [0, 255], per_channel=0.5)

For 50% of all images, replace 10% of all pixels with either the value 0 or the value 255 (same as in the previous example). For the other 50% of all images, replace channelwise 10% of all pixels with either the value 0 or the value 255. So, it will be very rare for each pixel to have all channels replaced by 255 or 0.

>>> import imgaug.augmenters as iaa
>>> import imgaug.parameters as iap
>>> aug = ReplaceElementwise(0.1, iap.Normal(128, 0.4*128), per_channel=0.5)

Replace 10% of all pixels by gaussian noise centered around 128. Both the replacement mask and the gaussian noise are sampled channelwise for 50% of all images.

>>> import imgaug.augmenters as iaa
>>> import imgaug.parameters as iap
>>> aug = ReplaceElementwise(
>>>     iap.FromLowerResolution(iap.Binomial(0.1), size_px=8),
>>>     iap.Normal(128, 0.4*128),
>>>     per_channel=0.5)

Replace 10% of all pixels by gaussian noise centered around 128. Sample the replacement mask at a lower resolution (8x8 pixels) and upscale it to the image size, resulting in coarse areas being replaced by gaussian noise.

Methods

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

See get_parameters().

class imgaug.augmenters.arithmetic.Salt(p=(0.0, 0.03), per_channel=False, seed=None, name=None, random_state='deprecated', deterministic='deprecated')[source]

Bases: imgaug.augmenters.arithmetic.ReplaceElementwise

Replace pixels in images with salt noise, i.e. white-ish pixels.

This augmenter is similar to SaltAndPepper, but adds no pepper noise to images.

Supported dtypes:

See ReplaceElementwise.

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

    Probability of replacing a pixel with salt noise.

    • If a float, then that value will always be used as the probability.
    • If a tuple (a, b), then a probability will be sampled uniformly per image from the interval [a, b].
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then a image-sized mask will be sampled from that parameter per image. Any value >0.5 in that mask will be replaced with salt noise.
  • per_channel (bool or float or imgaug.parameters.StochasticParameter, optional) – Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image. If this value is a float p, then for p percent of all images per_channel will be treated as True. If it is a StochasticParameter it is expected to produce samples with values between 0.0 and 1.0, where values >0.5 will lead to per-channel behaviour (i.e. same as True).

  • 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.Salt(0.05)

Replace 5% of all pixels with salt noise (white-ish colors).

Methods

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

Bases: imgaug.augmenters.arithmetic.ReplaceElementwise

Replace pixels in images with salt/pepper noise (white/black-ish colors).

Supported dtypes:

See ReplaceElementwise.

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

    Probability of replacing a pixel to salt/pepper noise.

    • If a float, then that value will always be used as the probability.
    • If a tuple (a, b), then a probability will be sampled uniformly per image from the interval [a, b].
    • If a list, then a random value will be sampled from that list per image.
    • If a StochasticParameter, then a image-sized mask will be sampled from that parameter per image. Any value >0.5 in that mask will be replaced with salt and pepper noise.
  • per_channel (bool or float or imgaug.parameters.StochasticParameter, optional) – Whether to use (imagewise) the same sample(s) for all channels (False) or to sample value(s) for each channel (True). Setting this to True will therefore lead to different transformations per image and channel, otherwise only per image. If this value is a float p, then for p percent of all images per_channel will be treated as True. If it is a StochasticParameter it is expected to produce samples with values between 0.0 and 1.0, where values >0.5 will lead to per-channel behaviour (i.e. same as True).

  • 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.SaltAndPepper(0.05)

Replace 5% of all pixels with salt and pepper noise.

>>> import imgaug.augmenters as iaa
>>> aug = iaa.SaltAndPepper(0.05, per_channel=True)

Replace channelwise 5% of all pixels with salt and pepper noise.

Methods

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

Bases: imgaug.augmenters.arithmetic.Invert

Invert all pixel values above a threshold.

This is the same as Invert, but sets a default threshold around 128 (+/- 64, decided per image) and default invert_above_threshold to True (i.e. only values above the threshold will be inverted).

See Invert for more details.

Added in 0.4.0.

Supported dtypes:

See Invert.

Parameters:
  • p (float or imgaug.parameters.StochasticParameter) – See Invert.
  • per_channel (bool or float or imgaug.parameters.StochasticParameter, optional) – See Invert.
  • min_value (None or number, optional) – See Invert.
  • max_value (None or number, optional) – See Invert.
  • threshold (None or number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional) – See Invert.
  • invert_above_threshold (bool or float or imgaug.parameters.StochasticParameter, optional) – See Invert.
  • 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.Solarize(0.5, threshold=(32, 128))

Invert the colors in 50 percent of all images for pixels with a value between 32 and 128 or more. The threshold is sampled once per image. The thresholding operation happens per channel.

Methods

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

Bases: imgaug.augmenters.meta.Augmenter

Drop all channels of a defined fraction of all images.

For image data, all components of dropped images will be filled with zeros.

Note

This augmenter also sets the arrays of heatmaps and segmentation maps to zero and removes all coordinate-based data (e.g. it removes all bounding boxes on images that were filled with zeros).

Added in 0.4.0.

Supported dtypes:

  • uint8: yes; fully tested
  • uint16: yes; tested
  • uint32: yes; tested
  • uint64: yes; tested
  • int8: yes; tested
  • int16: yes; tested
  • int32: yes; tested
  • int64: yes; tested
  • float16: yes; tested
  • float32: yes; tested
  • float64: yes; tested
  • float128: yes; tested
  • bool: yes; tested
Parameters:
  • p (float or tuple of float or imgaug.parameters.StochasticParameter, optional) –

    The probability of an image to be filled with zeros.

    • If float: The value will be used for all images. A value of 1.0 would mean that all images will be set to zero. A value of 0.0 would lead to no images being set to zero.
    • If tuple (a, b): A value p will be sampled from the interval [a, b) per batch and be used as the dropout probability.
    • If a list, then a value will be sampled from that list per batch and used as the probability.
    • If StochasticParameter: The parameter will be used to determine per image whether it should be kept (sampled value of >=0.5) or shouldn’t be kept (sampled value of <0.5). If you instead want to provide the probability as a stochastic parameter, you can usually do imgaug.parameters.Binomial(1-p) to convert parameter p to a 0/1 representation.
  • 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.TotalDropout(1.0)

Create an augmenter that sets all components of all images to zero.

>>> aug = iaa.TotalDropout(0.5)

Create an augmenter that sets all components of 50% of all images to zero.

Methods

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

See get_parameters().

imgaug.augmenters.arithmetic.add_elementwise(image, values)[source]

Add an array of values to an image.

This method ensures that uint8 does not overflow during the addition.

Supported dtypes:

  • uint8: yes; fully tested
  • uint16: limited; tested (1)
  • uint32: no
  • uint64: no
  • int8: limited; tested (1)
  • int16: limited; tested (1)
  • int32: no
  • int64: no
  • float16: limited; tested (1)
  • float32: limited; tested (1)
  • float64: no
  • float128: no
  • bool: limited; tested (1)
    1. Non-uint8 dtypes can overflow. For floats, this can result in +/-inf.
Parameters:
  • image (ndarray) – Image array of shape (H,W,[C]).
  • values (ndarray) – The values to add to the image. Expected to have the same height and width as image and either no channels or one channel or the same number of channels as image.
Returns:

Image with values added to it.

Return type:

ndarray

imgaug.augmenters.arithmetic.add_scalar(image, value)[source]

Add a single scalar value or one scalar value per channel to an image.

This method ensures that uint8 does not overflow during the addition.

Supported dtypes:

  • uint8: yes; fully tested
  • uint16: limited; tested (1)
  • uint32: no
  • uint64: no
  • int8: limited; tested (1)
  • int16: limited; tested (1)
  • int32: no
  • int64: no
  • float16: limited; tested (1)
  • float32: limited; tested (1)
  • float64: no
  • float128: no
  • bool: limited; tested (1)
    1. Non-uint8 dtypes can overflow. For floats, this can result in +/-inf.
Parameters:
  • image (ndarray) – Image array of shape (H,W,[C]). If value contains more than one value, the shape of the image is expected to be (H,W,C).
  • value (number or ndarray) – The value to add to the image. Either a single value or an array containing exactly one component per channel, i.e. C components.
Returns:

Image with value added to it.

Return type:

ndarray

imgaug.augmenters.arithmetic.compress_jpeg(image, compression)[source]

Compress an image using jpeg compression.

Supported dtypes:

  • uint8: yes; fully tested
  • uint16: ?
  • uint32: ?
  • uint64: ?
  • int8: ?
  • int16: ?
  • int32: ?
  • int64: ?
  • float16: ?
  • float32: ?
  • float64: ?
  • float128: ?
  • bool: ?
Parameters:
  • image (ndarray) – Image of dtype uint8 and shape (H,W,[C]). If C is provided, it must be 1 or 3.
  • compression (int) – Strength of the compression in the interval [0, 100].
Returns:

Input image after applying jpeg compression to it and reloading the result into a new array. Same shape and dtype as the input.

Return type:

ndarray

imgaug.augmenters.arithmetic.cutout(image, x1, y1, x2, y2, fill_mode='constant', cval=0, fill_per_channel=False, seed=None)[source]

Fill a single area within an image using a fill mode.

This cutout method uses the top-left and bottom-right corner coordinates of the cutout region given as absolute pixel values.

Note

Gaussian fill mode will assume that float input images contain values in the interval [0.0, 1.0] and hence sample values from a gaussian within that interval, i.e. from N(0.5, std=0.5/3).

Supported dtypes:

See cutout_().

Added in 0.4.0.

Parameters:
  • image (ndarray) – Image to modify.
  • x1 (number) – See cutout_().
  • y1 (number) – See cutout_().
  • x2 (number) – See cutout_().
  • y2 (number) – See cutout_().
  • fill_mode ({‘constant’, ‘gaussian’}, optional) – See cutout_().
  • cval (number or tuple of number, optional) – See cutout_().
  • fill_per_channel (number or bool, optional) – See cutout_().
  • 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 cutout_().
Returns:

Image with area filled in.

Return type:

ndarray

imgaug.augmenters.arithmetic.cutout_(image, x1, y1, x2, y2, fill_mode='constant', cval=0, fill_per_channel=False, seed=None)[source]

Fill a single area within an image using a fill mode (in-place).

This cutout method uses the top-left and bottom-right corner coordinates of the cutout region given as absolute pixel values.

Note

Gaussian fill mode will assume that float input images contain values in the interval [0.0, 1.0] and hence sample values from a gaussian within that interval, i.e. from N(0.5, std=0.5/3).

Added in 0.4.0.

Supported dtypes:

minimum of (
_fill_rectangle_gaussian_(), _fill_rectangle_constant_()

)

Parameters:
  • image (ndarray) – Image to modify. Might be modified in-place.
  • x1 (number) – X-coordinate of the top-left corner of the cutout region.
  • y1 (number) – Y-coordinate of the top-left corner of the cutout region.
  • x2 (number) – X-coordinate of the bottom-right corner of the cutout region.
  • y2 (number) – Y-coordinate of the bottom-right corner of the cutout region.
  • fill_mode ({‘constant’, ‘gaussian’}, optional) – Fill mode to use.
  • cval (number or tuple of number, optional) – The constant value to use when filling with mode constant. May be an intensity value or color tuple.
  • fill_per_channel (number or bool, optional) – Whether to fill in a channelwise fashion. If number then a value >=0.5 will be interpreted as True.
  • 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) – A random number generator to sample random values from. Usually an integer seed value or an RNG instance. See imgaug.random.RNG for details.
Returns:

Image with area filled in. The input image might have been modified in-place.

Return type:

ndarray

imgaug.augmenters.arithmetic.invert(image, min_value=None, max_value=None, threshold=None, invert_above_threshold=True)[source]

Invert an array.

Supported dtypes:

See invert_().

Parameters:
  • image (ndarray) – See invert_().
  • min_value (None or number, optional) – See invert_().
  • max_value (None or number, optional) – See invert_().
  • threshold (None or number, optional) – See invert_().
  • invert_above_threshold (bool, optional) – See invert_().
Returns:

Inverted image.

Return type:

ndarray

imgaug.augmenters.arithmetic.invert_(image, min_value=None, max_value=None, threshold=None, invert_above_threshold=True)[source]

Invert an array in-place.

Added in 0.4.0.

Supported dtypes:

if (min_value=None and max_value=None):

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

if (min_value!=None or max_value!=None):

  • uint8: yes; fully tested
  • uint16: yes; tested
  • uint32: yes; tested
  • uint64: no (1)
  • int8: yes; tested
  • int16: yes; tested
  • int32: yes; tested
  • int64: no (2)
  • float16: yes; tested
  • float32: yes; tested
  • float64: no (2)
  • float128: no (3)
  • bool: no (4)
    1. Not allowed due to numpy’s clip converting from uint64 to float64.
    1. Not allowed as int/float have to be increased in resolution when using min/max values.
    1. Not tested.
    1. Makes no sense when using min/max values.
Parameters:
  • image (ndarray) – Image array of shape (H,W,[C]). The array might be modified in-place.
  • min_value (None or number, optional) – Minimum of the value range of input images, e.g. 0 for uint8 images. If set to None, the value will be automatically derived from the image’s dtype.
  • max_value (None or number, optional) – Maximum of the value range of input images, e.g. 255 for uint8 images. If set to None, the value will be automatically derived from the image’s dtype.
  • threshold (None or number, optional) – A threshold to use in order to invert only numbers above or below the threshold. If None no thresholding will be used.
  • invert_above_threshold (bool, optional) – If True, only values >=threshold will be inverted. Otherwise, only values <threshold will be inverted. If threshold is None this parameter has no effect.
Returns:

Inverted image. This can be the same array as input in image, modified in-place.

Return type:

ndarray

imgaug.augmenters.arithmetic.multiply_elementwise(image, multipliers)[source]

Multiply an image with an array of values.

This method ensures that uint8 does not overflow during the addition.

Supported dtypes:

  • uint8: yes; fully tested
  • uint16: limited; tested (1)
  • uint32: no
  • uint64: no
  • int8: limited; tested (1)
  • int16: limited; tested (1)
  • int32: no
  • int64: no
  • float16: limited; tested (1)
  • float32: limited; tested (1)
  • float64: no
  • float128: no
  • bool: limited; tested (1)
    1. Non-uint8 dtypes can overflow. For floats, this can result in +/-inf.

note:

Tests were only conducted for rather small multipliers, around
``-10.0`` to ``+10.0``.

In general, the multipliers sampled from `multipliers` must be in a
value range that corresponds to the input image's dtype. E.g. if the
input image has dtype ``uint16`` and the samples generated from
`multipliers` are ``float64``, this function will still force all
samples to be within the value range of ``float16``, as it has the
same number of bytes (two) as ``uint16``. This is done to make
overflows less likely to occur.
Parameters:
  • image (ndarray) – Image array of shape (H,W,[C]).
  • multipliers (ndarray) – The multipliers with which to multiply the image. Expected to have the same height and width as image and either no channels or one channel or the same number of channels as image.
Returns:

Image, multiplied by multipliers.

Return type:

ndarray

imgaug.augmenters.arithmetic.multiply_scalar(image, multiplier)[source]

Multiply an image by a single scalar or one scalar per channel.

This method ensures that uint8 does not overflow during the multiplication.

Supported dtypes:

  • uint8: yes; fully tested
  • uint16: limited; tested (1)
  • uint32: no
  • uint64: no
  • int8: limited; tested (1)
  • int16: limited; tested (1)
  • int32: no
  • int64: no
  • float16: limited; tested (1)
  • float32: limited; tested (1)
  • float64: no
  • float128: no
  • bool: limited; tested (1)
    1. Non-uint8 dtypes can overflow. For floats, this can result in +/-inf.

note:

Tests were only conducted for rather small multipliers, around
``-10.0`` to ``+10.0``.

In general, the multipliers sampled from `multiplier` must be in a
value range that corresponds to the input image's dtype. E.g. if the
input image has dtype ``uint16`` and the samples generated from
`multiplier` are ``float64``, this function will still force all
samples to be within the value range of ``float16``, as it has the
same number of bytes (two) as ``uint16``. This is done to make
overflows less likely to occur.
Parameters:
  • image (ndarray) – Image array of shape (H,W,[C]). If value contains more than one value, the shape of the image is expected to be (H,W,C).
  • multiplier (number or ndarray) – The multiplier to use. Either a single value or an array containing exactly one component per channel, i.e. C components.
Returns:

Image, multiplied by multiplier.

Return type:

ndarray

imgaug.augmenters.arithmetic.replace_elementwise_(image, mask, replacements)[source]

Replace components in an image array with new values.

Supported dtypes:

  • uint8: yes; fully tested
  • uint16: yes; tested
  • uint32: yes; tested
  • uint64: no (1)
  • int8: yes; tested
  • int16: yes; tested
  • int32: yes; tested
  • int64: no (2)
  • float16: yes; tested
  • float32: yes; tested
  • float64: yes; tested
  • float128: no
  • bool: yes; tested
    1. uint64 is currently not supported, because clip_to_dtype_value_range_() does not support it, which again is because numpy.clip() seems to not support it.
    1. int64 is disallowed due to being converted to float64 by numpy.clip() since 1.17 (possibly also before?).
Parameters:
  • image (ndarray) – Image array of shape (H,W,[C]).
  • mask (ndarray) – Mask of shape (H,W,[C]) denoting which components to replace. If C is provided, it must be 1 or match the C of image. May contain floats in the interval [0.0, 1.0].
  • replacements (iterable) – Replacements to place in image at the locations defined by mask. This 1-dimensional iterable must contain exactly as many values as there are replaced components in image.
Returns:

Image with replaced components.

Return type:

ndarray

imgaug.augmenters.arithmetic.solarize(image, threshold=128)[source]

Invert pixel values above a threshold.

Added in 0.4.0.

Supported dtypes:

See solarize_().

Parameters:
Returns:

Inverted image.

Return type:

ndarray

imgaug.augmenters.arithmetic.solarize_(image, threshold=128)[source]

Invert pixel values above a threshold in-place.

This function is a wrapper around invert().

This function performs the same transformation as PIL.ImageOps.solarize().

Added in 0.4.0.

Supported dtypes:

See ~imgaug.augmenters.arithmetic.invert_(min_value=None and max_value=None).

Parameters:
  • image (ndarray) – See invert_().
  • threshold (None or number, optional) – See invert_(). Note: The default threshold is optimized for uint8 images.
Returns:

Inverted image. This can be the same array as input in image, modified in-place.

Return type:

ndarray