augmenters.arithmetic

Add

Add a value to all pixels in an image.

API link: Add

Example. Add random values between -40 and 40 to images, with each value being sampled once per image and then being the same for all pixels:

import imgaug.augmenters as iaa
aug = iaa.Add((-40, 40))
Add

Example. Add random values between -40 and 40 to images. In 50% of all images the values differ per channel (3 sampled value). In the other 50% of all images the value is the same for all channels:

aug = iaa.Add((-40, 40), per_channel=0.5)
Add per channel

AddElementwise

Add values to the pixels of images with possibly different values for neighbouring pixels.

API link: AddElementwise

Example. Add random values between -40 and 40 to images, with each value being sampled per pixel:

import imgaug.augmenters as iaa
aug = iaa.AddElementwise((-40, 40))
AddElementwise

Example. Add random values between -40 and 40 to images. In 50% of all images the values differ per channel (3 sampled values per pixel). In the other 50% of all images the value is the same for all channels per pixel:

aug = iaa.AddElementwise((-40, 40), per_channel=0.5)
AddElementwise per channel

AdditiveGaussianNoise

Add noise sampled from gaussian distributions elementwise to images.

API link: AdditiveGaussianNoise()

Example. Add gaussian noise to an image, sampled once per pixel from a normal distribution N(0, s), where s is sampled per image and varies between 0 and 0.2*255:

import imgaug.augmenters as iaa
aug = iaa.AdditiveGaussianNoise(scale=(0, 0.2*255))
AdditiveGaussianNoise

Example. Add gaussian noise to an image, sampled once per pixel from a normal distribution N(0, 0.05*255):

aug = iaa.AdditiveGaussianNoise(scale=0.2*255)
AdditiveGaussianNoise large

Example. Add laplace noise to an image, sampled channelwise from N(0, 0.2*255) (i.e. three independent samples per pixel):

aug = iaa.AdditiveGaussianNoise(scale=0.2*255, per_channel=True)
AdditiveGaussianNoise per channel

AdditiveLaplaceNoise

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.

API link: AdditiveLaplaceNoise()

Example. Add laplace noise to an image, sampled once per pixel from Laplace(0, s), where s is sampled per image and varies between 0 and 0.2*255:

import imgaug.augmenters as iaa
aug = iaa.AdditiveLaplaceNoise(scale=(0, 0.2*255))
AdditiveLaplaceNoise

Example. Add laplace noise to an image, sampled once per pixel from Laplace(0, 0.2*255):

aug = iaa.AdditiveLaplaceNoise(scale=0.2*255)
AdditiveLaplaceNoise large

Example. Add laplace noise to an image, sampled channelwise from Laplace(0, 0.2*255) (i.e. three independent samples per pixel):

aug = iaa.AdditiveLaplaceNoise(scale=0.2*255, per_channel=True)
AdditiveLaplaceNoise per channel

AdditivePoissonNoise

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 20.0 for lam lead to visible noise (for uint8). Values of around 40.0 for lam lead to very visible noise (for uint8). It is recommended to usually set per_channel to True.

API link: AdditivePoissonNoise()

Example. Add poisson noise to an image, sampled once per pixel from Poisson(lam), where lam is sampled per image and varies between 0 and 40:

import imgaug.augmenters as iaa
aug = iaa.AdditivePoissonNoise(scale=(0, 40))
AdditivePoissonNoise

Example. Add poisson noise to an image, sampled once per pixel from Poisson(40):

aug = iaa.AdditivePoissonNoise(40)
AdditivePoissonNoise large

Example. Add poisson noise to an image, sampled channelwise from Poisson(40) (i.e. three independent samples per pixel):

aug = iaa.AdditivePoissonNoise(scale=40, per_channel=True)
AdditivePoissonNoise per channel

Multiply

Multiply all pixels in an image with a specific value, thereby making the image darker or brighter.

API link: Multiply

Example. Multiply each image with a random value between 0.5 and 1.5:

import imgaug.augmenters as iaa
aug = iaa.Multiply((0.5, 1.5))
Multiply

Example. Multiply 50% of all images with a random value between 0.5 and 1.5 and multiply the remaining 50% channel-wise, i.e. sample one multiplier independently per channel:

aug = iaa.Multiply((0.5, 1.5), per_channel=0.5)
Multiply per channel

MultiplyElementwise

Multiply values of pixels with possibly different values for neighbouring pixels, making each pixel darker or brighter.

API link: MultiplyElementwise

Example. Multiply each pixel with a random value between 0.5 and 1.5:

import imgaug.augmenters as iaa
aug = iaa.MultiplyElementwise((0.5, 1.5))
MultiplyElementwise

Example. Multiply in 50% of all images each pixel with random values between 0.5 and 1.5 and multiply in the remaining 50% of all images the pixels channel-wise, i.e. sample one multiplier independently per channel and pixel:

aug = iaa.MultiplyElementwise((0.5, 1.5), per_channel=0.5)
MultiplyElementwise per channel

Dropout

Augmenter that sets a certain fraction of pixels in images to zero.

API link: Dropout()

Example. Sample per image a value p from the range 0<=p<=0.2 and then drop p percent of all pixels in the image (i.e. convert them to black pixels):

import imgaug.augmenters as iaa
aug = iaa.Dropout(p=(0, 0.2))
Dropout

Example. Sample per image a value p from the range 0<=p<=0.2 and then drop p percent of all pixels in the image (i.e. convert them to black pixels), but do this independently per channel in 50% of all images:

aug = iaa.Dropout(p=(0, 0.2), per_channel=0.5)
Dropout per channel

CoarseDropout

Augmenter that sets rectangular areas within images to zero.

API link: CoarseDropout()

Example. Drop 2% of all pixels by converting them to black pixels, but do that on a lower-resolution version of the image that has 50% of the original size, leading to 2x2 squares being dropped:

import imgaug.augmenters as iaa
aug = iaa.CoarseDropout(0.02, size_percent=0.5)
CoarseDropout

Example. Drop 0 to 5% of all pixels by converting them to black pixels, but do that on a lower-resolution version of the image that has 5% to 50% of the original size, leading to large rectangular areas being dropped:

import imgaug.augmenters as iaa
aug = iaa.CoarseDropout((0.0, 0.05), size_percent=(0.02, 0.25))
CoarseDropout p and size uniform

Example. Drop 2% of all pixels by converting them to black pixels, but do that on a lower-resolution version of the image that has 50% of the original size, leading to 2x2 squares being dropped. Also do this in 50% of all images channel-wise, so that only the information of some channels in set to 0 while others remain untouched:

aug = iaa.CoarseDropout(0.02, size_percent=0.15, per_channel=0.5)
CoarseDropout per channel

ReplaceElementwise

Replace pixels in an image with new values.

API link: ReplaceElementwise

Example. Replace 10% of all pixels with either the value 0 or the value 255:

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

Example. 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.

aug = ReplaceElementwise(0.1, [0, 255], per_channel=0.5)
ReplaceElementwise per channel at 50%

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

import imgaug.parameters as iap
aug = ReplaceElementwise(0.1, iap.Normal(128, 0.4*128), per_channel=0.5)
ReplaceElementwise with gaussian noise

Example. 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.

aug = ReplaceElementwise(
    iap.FromLowerResolution(iap.Binomial(0.1), size_px=8),
    iap.Normal(128, 0.4*128),
    per_channel=0.5)
ReplaceElementwise with gaussian noise in coarse areas

ImpulseNoise

Add impulse noise to images.

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

API link: ImpulseNoise()

Example. Replace 10% of all pixels with impulse noise:

import imgaug.augmenters as iaa
aug = iaa.ImpulseNoise(0.1)
ImpulseNoise

SaltAndPepper

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

API link: SaltAndPepper()

Example. Replace 10% of all pixels with salt and pepper noise:

import imgaug.augmenters as iaa
aug = iaa.SaltAndPepper(0.1)
SaltAndPepper

Example. Replace channelwise 10% of all pixels with salt and pepper noise:

aug = iaa.SaltAndPepper(0.1, per_channel=True)
SaltAndPepper per channel

CoarseSaltAndPepper

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

API link: CoarseSaltAndPepper()

Example. Mark 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.

import imgaug.augmenters as iaa
aug = iaa.CoarseSaltAndPepper(0.05, size_percent=(0.01, 0.1))
CoarseSaltAndPepper

Example. 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_px=(4, 16))
CoarseSaltAndPepper with size_px

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

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

Salt

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.

API link: Salt()

Example. Replace 10% of all pixels with salt noise (white-ish colors):

import imgaug.augmenters as iaa
aug = iaa.Salt(0.1)
Salt

Example. Similar to SaltAndPepper, this augmenter also supports the per_channel argument, which is skipped here for brevity.

CoarseSalt

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

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

API link: CoarseSalt()

Example. 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.

import imgaug.augmenters as iaa
aug = iaa.CoarseSalt(0.05, size_percent=(0.01, 0.1))
CoarseSalt

Similar to CoarseSaltAndPepper, this augmenter also supports the per_channel argument, which is skipped here for brevity

Pepper

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.

API link: Pepper()

Example. Replace 10% of all pixels with pepper noise (black-ish colors):

import imgaug.augmenters as iaa
aug = iaa.Pepper(0.1)
Pepper

Similar to SaltAndPepper, this augmenter also supports the per_channel argument, which is skipped here for brevity.

CoarsePepper

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

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

API link: CoarsePepper()

Example. 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.

import imgaug.augmenters as iaa
aug = iaa.CoarsePepper(0.05, size_percent=(0.01, 0.1))
CoarsePepper

Similar to CoarseSaltAndPepper, this augmenter also supports the per_channel argument, which is skipped here for brevity

Invert

Augmenter that inverts all values in images, i.e. sets a pixel from value v to 255-v.

API link: Invert

Example. Invert in 50% of all images all pixels:

import imgaug.augmenters as iaa
aug = iaa.Invert(0.5)
Invert

Example. For 50% of all images, invert all pixels in these images with 25% probability (per image). In the remaining 50% of all images, invert 25% of all channels:

aug = iaa.Invert(0.25, per_channel=0.5)
Invert per channel

ContrastNormalization

Augmenter that changes the contrast of images.

API link: ContrastNormalization

Example. Normalize contrast by a factor of 0.5 to 1.5, sampled randomly per image:

import imgaug.augmenters as iaa
aug = iaa.ContrastNormalization((0.5, 1.5))
ContrastNormalization

Example. Normalize contrast by a factor of 0.5 to 1.5, sampled randomly per image and for 50% of all images also independently per channel:

aug = iaa.ContrastNormalization((0.5, 1.5), per_channel=0.5)
ContrastNormalization per channel

JpegCompression

Degrade the quality of images by JPEG-compressing them.

API link: JpegCompression

Example. Remove high frequency components in images via JPEG compression with a compression strength between 80 and 95 (randomly and uniformly sampled per image). This corresponds to a (very low) quality setting of 5 to 20.

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