Skip to content

Transforms (augmentations.transforms)

Blur

Blur the input image using a random-sized kernel.

Parameters:

Name Type Description Default
blur_limit int, [int, int]

maximum kernel size for blurring the input image. Should be in range [3, inf). Default: (3, 7).

required
p float

probability of applying the transform. Default: 0.5.

required

Targets

image

Image-types

uint8, float32

CenterCrop

Crop the central part of the input.

Parameters:

Name Type Description Default
height int

height of the crop.

required
width int

width of the crop.

required
p float

probability of applying the transform. Default: 1.

required

Targets

image, mask, bboxes, keypoints

Image-types

uint8, float32

Note

It is recommended to use uint8 images as input. Otherwise the operation will require internal conversion float32 -> uint8 -> float32 that causes worse performance.

ChannelDropout

Randomly Drop Channels in the input Image.

Parameters:

Name Type Description Default
channel_drop_range [int, int]

range from which we choose the number of channels to drop.

required
fill_value int, float

pixel value for the dropped channel.

required
p float

probability of applying the transform. Default: 0.5.

required

Targets

image

Image-types

uint8, uint16, unit32, float32

ChannelShuffle

Randomly rearrange channels of the input RGB image.

Parameters:

Name Type Description Default
p float

probability of applying the transform. Default: 0.5.

required

Targets

image

Image-types

uint8, float32

CLAHE

Apply Contrast Limited Adaptive Histogram Equalization to the input image.

Parameters:

Name Type Description Default
clip_limit float or [float, float]

upper threshold value for contrast limiting. If clip_limit is a single float value, the range will be (1, clip_limit). Default: (1, 4).

required
tile_grid_size [int, int]

size of grid for histogram equalization. Default: (8, 8).

required
p float

probability of applying the transform. Default: 0.5.

required

Targets

image

Image-types

uint8

CoarseDropout

CoarseDropout of the rectangular regions in the image.

Parameters:

Name Type Description Default
max_holes int

Maximum number of regions to zero out.

required
max_height int

Maximum height of the hole.

required
max_width int

Maximum width of the hole.

required
min_holes int

Minimum number of regions to zero out. If None, min_holes is be set to max_holes. Default: None.

required
min_height int

Minimum height of the hole. Default: None. If None, min_height is set to max_height. Default: None.

required
min_width int

Minimum width of the hole. If None, min_height is set to max_width. Default: None.

required
fill_value int, float, lisf of int, list of float

value for dropped pixels.

required

Targets

image

Image-types

uint8, float32

Reference: | https://arxiv.org/abs/1708.04552 | https://github.com/uoguelph-mlrg/Cutout/blob/master/util/cutout.py | https://github.com/aleju/imgaug/blob/master/imgaug/augmenters/arithmetic.py

Crop

Crop region from image.

Parameters:

Name Type Description Default
x_min int

Minimum upper left x coordinate.

required
y_min int

Minimum upper left y coordinate.

required
x_max int

Maximum lower right x coordinate.

required
y_max int

Maximum lower right y coordinate.

required

Targets

image, mask, bboxes, keypoints

Image-types

uint8, float32

CropNonEmptyMaskIfExists

Crop area with mask if mask is non-empty, else make random crop.

Parameters:

Name Type Description Default
height int

vertical size of crop in pixels

required
width int

horizontal size of crop in pixels

required
ignore_values list of int

values to ignore in mask, 0 values are always ignored (e.g. if background value is 5 set ignore_values=[5] to ignore)

required
ignore_channels list of int

channels to ignore in mask (e.g. if background is a first channel set ignore_channels=[0] to ignore)

required
p float

probability of applying the transform. Default: 1.0.

required

Targets

image, mask, bboxes, keypoints

Image-types

uint8, float32

Cutout

CoarseDropout of the square regions in the image.

Parameters:

Name Type Description Default
num_holes int

number of regions to zero out

required
max_h_size int

maximum height of the hole

required
max_w_size int

maximum width of the hole

required
fill_value int, float, lisf of int, list of float

value for dropped pixels.

required

Targets

image

Image-types

uint8, float32

Reference: | https://arxiv.org/abs/1708.04552 | https://github.com/uoguelph-mlrg/Cutout/blob/master/util/cutout.py | https://github.com/aleju/imgaug/blob/master/imgaug/augmenters/arithmetic.py

Downscale

Decreases image quality by downscaling and upscaling back.

Parameters:

Name Type Description Default
scale_min float

lower bound on the image scale. Should be < 1.

required
scale_max float

lower bound on the image scale. Should be .

required
interpolation

cv2 interpolation method. cv2.INTER_NEAREST by default

required

Targets

image

Image-types

uint8, float32

ElasticTransform

Elastic deformation of images as described in [Simard2003]_ (with modifications). Based on https://gist.github.com/erniejunior/601cdf56d2b424757de5

.. [Simard2003] Simard, Steinkraus and Platt, "Best Practices for Convolutional Neural Networks applied to Visual Document Analysis", in Proc. of the International Conference on Document Analysis and Recognition, 2003.

Parameters:

Name Type Description Default
alpha float required
sigma float

Gaussian filter parameter.

required
alpha_affine float

The range will be (-alpha_affine, alpha_affine)

required
interpolation OpenCV flag

flag that is used to specify the interpolation algorithm. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_LINEAR.

required
border_mode OpenCV flag

flag that is used to specify the pixel extrapolation method. Should be one of: cv2.BORDER_CONSTANT, cv2.BORDER_REPLICATE, cv2.BORDER_REFLECT, cv2.BORDER_WRAP, cv2.BORDER_REFLECT_101. Default: cv2.BORDER_REFLECT_101

required
value int, float, list of ints, list of float

padding value if border_mode is cv2.BORDER_CONSTANT.

required
mask_value int, float, list of ints, list of float

padding value if border_mode is cv2.BORDER_CONSTANT applied for masks.

required
approximate boolean

Whether to smooth displacement map with fixed kernel size. Enabling this option gives ~2X speedup on large images.

required

Targets

image, mask

Image-types

uint8, float32

Equalize

Equalize the image histogram.

Parameters:

Name Type Description Default
mode str

{'cv', 'pil'}. Use OpenCV or Pillow equalization method.

required
by_channels bool

If True, use equalization by channels separately, else convert image to YCbCr representation and use equalization by Y channel.

required
mask np.ndarray, callable

If given, only the pixels selected by the mask are included in the analysis. Maybe 1 channel or 3 channel array or callable. Function signature must include image argument.

required
mask_params list of str

Params for mask function.

required

Targets

image

Image-types

uint8

FancyPCA

Augment RGB image using FancyPCA from Krizhevsky's paper "ImageNet Classification with Deep Convolutional Neural Networks"

Parameters:

Name Type Description Default
alpha float

how much to perturb/scale the eigen vecs and vals. scale is samples from gaussian distribution (mu=0, sigma=alpha)

required

Targets

image

Image-types

3-channel uint8 images only

Credit

http://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks.pdf https://deshanadesai.github.io/notes/Fancy-PCA-with-Scikit-Image https://pixelatedbrian.github.io/2018-04-29-fancy_pca/

__init__(self, alpha=0.1, always_apply=False, p=0.5) special

Flip

Flip the input either horizontally, vertically or both horizontally and vertically.

Parameters:

Name Type Description Default
p float

probability of applying the transform. Default: 0.5.

required

Targets

image, mask, bboxes, keypoints

Image-types

uint8, float32

apply(self, img, d=0, **params)

Parameters:

Name Type Description Default
d int

code that specifies how to flip the input. 0 for vertical flipping, 1 for horizontal flipping, -1 for both vertical and horizontal flipping (which is also could be seen as rotating the input by 180 degrees).

0

FromFloat

Take an input array where all values should lie in the range [0, 1.0], multiply them by max_value and then cast the resulted value to a type specified by dtype. If max_value is None the transform will try to infer the maximum value for the data type from the dtype argument.

This is the inverse transform for :class:~albumentations.augmentations.transforms.ToFloat.

Parameters:

Name Type Description Default
max_value float

maximum possible input value. Default: None.

required
dtype string or numpy data type

data type of the output. See the 'Data types' page from the NumPy docs_. Default: 'uint16'.

required
p float

probability of applying the transform. Default: 1.0.

required

Targets

image

Image-types

float32

.. _'Data types' page from the NumPy docs: https://docs.scipy.org/doc/numpy/user/basics.types.html

GaussianBlur

Blur the input image using using a Gaussian filter with a random kernel size.

Parameters:

Name Type Description Default
blur_limit int

maximum Gaussian kernel size for blurring the input image. Must be zero or odd and in range [3, inf). Default: (3, 7).

required
p float

probability of applying the transform. Default: 0.5.

required

Targets

image

Image-types

uint8, float32

GaussNoise

Apply gaussian noise to the input image.

Parameters:

Name Type Description Default
var_limit [float, float] or float

variance range for noise. If var_limit is a single float, the range will be (0, var_limit). Default: (10.0, 50.0).

required
mean float

mean of the noise. Default: 0

required
p float

probability of applying the transform. Default: 0.5.

required

Targets

image

Image-types

uint8, float32

GlassBlur

Apply glass noise to the input image.

Parameters:

Name Type Description Default
sigma float

standard deviation for Gaussian kernel.

required
max_delta int

max distance between pixels which are swapped.

required
iterations int

number of repeats. Should be in range [1, inf). Default: (2).

required
mode str

mode of computation: fast or exact. Default: "fast".

required
p float

probability of applying the transform. Default: 0.5.

required

Targets

image

Image-types

uint8, float32

Reference: | https://arxiv.org/abs/1903.12261 | https://github.com/hendrycks/robustness/blob/master/ImageNet-C/create_c/make_imagenet_c.py

GridDistortion

Parameters:

Name Type Description Default
num_steps int

count of grid cells on each side.

required
distort_limit float, [float, float]

If distort_limit is a single float, the range will be (-distort_limit, distort_limit). Default: (-0.03, 0.03).

required
interpolation OpenCV flag

flag that is used to specify the interpolation algorithm. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_LINEAR.

required
border_mode OpenCV flag

flag that is used to specify the pixel extrapolation method. Should be one of: cv2.BORDER_CONSTANT, cv2.BORDER_REPLICATE, cv2.BORDER_REFLECT, cv2.BORDER_WRAP, cv2.BORDER_REFLECT_101. Default: cv2.BORDER_REFLECT_101

required
value int, float, list of ints, list of float

padding value if border_mode is cv2.BORDER_CONSTANT.

required
mask_value int, float, list of ints, list of float

padding value if border_mode is cv2.BORDER_CONSTANT applied for masks.

required

Targets

image, mask

Image-types

uint8, float32

GridDropout

GridDropout, drops out rectangular regions of an image and the corresponding mask in a grid fashion.

Parameters:

Name Type Description Default
ratio float

the ratio of the mask holes to the unit_size (same for horizontal and vertical directions). Must be between 0 and 1. Default: 0.5.

required
unit_size_min int

minimum size of the grid unit. Must be between 2 and the image shorter edge. If 'None', holes_number_x and holes_number_y are used to setup the grid. Default: None.

required
unit_size_max int

maximum size of the grid unit. Must be between 2 and the image shorter edge. If 'None', holes_number_x and holes_number_y are used to setup the grid. Default: None.

required
holes_number_x int

the number of grid units in x direction. Must be between 1 and image width//2. If 'None', grid unit width is set as image_width//10. Default: None.

required
holes_number_y int

the number of grid units in y direction. Must be between 1 and image height//2. If None, grid unit height is set equal to the grid unit width or image height, whatever is smaller.

required
shift_x int

offsets of the grid start in x direction from (0,0) coordinate. Clipped between 0 and grid unit_width - hole_width. Default: 0.

required
shift_y int

offsets of the grid start in y direction from (0,0) coordinate. Clipped between 0 and grid unit height - hole_height. Default: 0.

required
random_offset boolean

weather to offset the grid randomly between 0 and grid unit size - hole size If 'True', entered shift_x, shift_y are ignored and set randomly. Default: False.

required
fill_value int

value for the dropped pixels. Default = 0

required
mask_fill_value int

value for the dropped pixels in mask. If None, tranformation is not applied to the mask. Default: None.

required

Targets

image, mask

Image-types

uint8, float32

References

https://arxiv.org/abs/2001.04086

HorizontalFlip

Flip the input horizontally around the y-axis.

Parameters:

Name Type Description Default
p float

probability of applying the transform. Default: 0.5.

required

Targets

image, mask, bboxes, keypoints

Image-types

uint8, float32

HueSaturationValue

Randomly change hue, saturation and value of the input image.

Parameters:

Name Type Description Default
hue_shift_limit [int, int] or int

range for changing hue. If hue_shift_limit is a single int, the range will be (-hue_shift_limit, hue_shift_limit). Default: (-20, 20).

required
sat_shift_limit [int, int] or int

range for changing saturation. If sat_shift_limit is a single int, the range will be (-sat_shift_limit, sat_shift_limit). Default: (-30, 30).

required
val_shift_limit [int, int] or int

range for changing value. If val_shift_limit is a single int, the range will be (-val_shift_limit, val_shift_limit). Default: (-20, 20).

required
p float

probability of applying the transform. Default: 0.5.

required

Targets

image

Image-types

uint8, float32

ImageCompression

Decrease Jpeg, WebP compression of an image.

Parameters:

Name Type Description Default
quality_lower float

lower bound on the image quality. Should be in [0, 100] range for jpeg and [1, 100] for webp.

required
quality_upper float

upper bound on the image quality. Should be in [0, 100] range for jpeg and [1, 100] for webp.

required
compression_type ImageCompressionType

should be ImageCompressionType.JPEG or ImageCompressionType.WEBP. Default: ImageCompressionType.JPEG

required

Targets

image

Image-types

uint8, float32

ImageCompressionType

An enumeration.

InvertImg

Invert the input image by subtracting pixel values from 255.

Parameters:

Name Type Description Default
p float

probability of applying the transform. Default: 0.5.

required

Targets

image

Image-types

uint8

ISONoise

Apply camera sensor noise.

Parameters:

Name Type Description Default
color_shift [float, float]

variance range for color hue change. Measured as a fraction of 360 degree Hue angle in HLS colorspace.

required
intensity [float, float]

Multiplicative factor that control strength of color and luminace noise.

required
p float

probability of applying the transform. Default: 0.5.

required

Targets

image

Image-types

uint8

JpegCompression

Decrease Jpeg compression of an image.

Parameters:

Name Type Description Default
quality_lower float

lower bound on the jpeg quality. Should be in [0, 100] range

required
quality_upper float

upper bound on the jpeg quality. Should be in [0, 100] range

required

Targets

image

Image-types

uint8, float32

Lambda

A flexible transformation class for using user-defined transformation functions per targets. Function signature must include **kwargs to accept optinal arguments like interpolation method, image size, etc:

Parameters:

Name Type Description Default
image callable

Image transformation function.

required
mask callable

Mask transformation function.

required
keypoint callable

Keypoint transformation function.

required
bbox callable

BBox transformation function.

required
always_apply bool

Indicates whether this transformation should be always applied.

required
p float

probability of applying the transform. Default: 1.0.

required

Targets

image, mask, bboxes, keypoints

Image-types

Any

LongestMaxSize

Rescale an image so that maximum side is equal to max_size, keeping the aspect ratio of the initial image.

Parameters:

Name Type Description Default
max_size int

maximum size of the image after the transformation.

required
interpolation OpenCV flag

interpolation method. Default: cv2.INTER_LINEAR.

required
p float

probability of applying the transform. Default: 1.

required

Targets

image, mask, bboxes, keypoints

Image-types

uint8, float32

MaskDropout

Image & mask augmentation that zero out mask and image regions corresponding to randomly chosen object instance from mask.

Mask must be single-channel image, zero values treated as background. Image can be any number of channels.

Inspired by https://www.kaggle.com/c/severstal-steel-defect-detection/discussion/114254

__init__(self, max_objects=1, image_fill_value=0, mask_fill_value=0, always_apply=False, p=0.5) special

Parameters:

Name Type Description Default
max_objects

Maximum number of labels that can be zeroed out. Can be tuple, in this case it's [min, max]

1
image_fill_value

Fill value to use when filling image. Can be 'inpaint' to apply inpaining (works only for 3-chahnel images)

0
mask_fill_value

Fill value to use when filling mask.

0

Targets

image, mask

Image-types

uint8, float32

MedianBlur

Blur the input image using using a median filter with a random aperture linear size.

Parameters:

Name Type Description Default
blur_limit int

maximum aperture linear size for blurring the input image. Must be odd and in range [3, inf). Default: (3, 7).

required
p float

probability of applying the transform. Default: 0.5.

required

Targets

image

Image-types

uint8, float32

MotionBlur

Apply motion blur to the input image using a random-sized kernel.

Parameters:

Name Type Description Default
blur_limit int

maximum kernel size for blurring the input image. Should be in range [3, inf). Default: (3, 7).

required
p float

probability of applying the transform. Default: 0.5.

required

Targets

image

Image-types

uint8, float32

MultiplicativeNoise

Multiply image to random number or array of numbers.

Parameters:

Name Type Description Default
multiplier float or tuple of floats

If single float image will be multiplied to this number. If tuple of float multiplier will be in range [multiplier[0], multiplier[1]). Default: (0.9, 1.1).

required
per_channel bool

If False, same values for all channels will be used. If True use sample values for each channels. Default False.

required
elementwise bool

If False multiply multiply all pixels in an image with a random value sampled once. If True Multiply image pixels with values that are pixelwise randomly sampled. Defaule: False.

required

Targets

image

Image-types

Any

Normalize

Divide pixel values by 255 = 2**8 - 1, subtract mean per channel and divide by std per channel.

Parameters:

Name Type Description Default
mean float, list of float

mean values

required
std (float, list of float

std values

required
max_pixel_value float

maximum possible pixel value

required

Targets

image

Image-types

uint8, float32

OpticalDistortion

Parameters:

Name Type Description Default
distort_limit float, [float, float]

If distort_limit is a single float, the range will be (-distort_limit, distort_limit). Default: (-0.05, 0.05).

required
shift_limit float, [float, float]

If shift_limit is a single float, the range will be (-shift_limit, shift_limit). Default: (-0.05, 0.05).

required
interpolation OpenCV flag

flag that is used to specify the interpolation algorithm. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_LINEAR.

required
border_mode OpenCV flag

flag that is used to specify the pixel extrapolation method. Should be one of: cv2.BORDER_CONSTANT, cv2.BORDER_REPLICATE, cv2.BORDER_REFLECT, cv2.BORDER_WRAP, cv2.BORDER_REFLECT_101. Default: cv2.BORDER_REFLECT_101

required
value int, float, list of ints, list of float

padding value if border_mode is cv2.BORDER_CONSTANT.

required
mask_value int, float, list of ints, list of float

padding value if border_mode is cv2.BORDER_CONSTANT applied for masks.

required

Targets

image, mask

Image-types

uint8, float32

PadIfNeeded

Pad side of the image / max if side is less than desired number.

Parameters:

Name Type Description Default
min_height int

minimal result image height.

required
min_width int

minimal result image width.

required
border_mode OpenCV flag

OpenCV border mode.

required
value int, float, list of int, lisft of float

padding value if border_mode is cv2.BORDER_CONSTANT.

required
mask_value int, float, list of int, lisft of float

padding value for mask if border_mode is cv2.BORDER_CONSTANT.

required
p float

probability of applying the transform. Default: 1.0.

required

Targets

image, mask, bbox, keypoints

Image-types

uint8, float32

Posterize

Reduce the number of bits for each color channel.

Parameters:

Name Type Description Default
num_bits [int, int] or int, or list of ints [r, g, b], or list of ints [[r1, r1], [g1, g2], [b1, b2]]

number of high bits. If num_bits is a single value, the range will be [num_bits, num_bits]. Must be in range [0, 8]. Default: 4.

required
p float

probability of applying the transform. Default: 0.5.

required

Targets: image

Image-types

uint8

RandomBrightness

Randomly change brightness of the input image.

Parameters:

Name Type Description Default
limit [float, float] or float

factor range for changing brightness. If limit is a single float, the range will be (-limit, limit). Default: (-0.2, 0.2).

required
p float

probability of applying the transform. Default: 0.5.

required

Targets

image

Image-types

uint8, float32

RandomBrightnessContrast

Randomly change brightness and contrast of the input image.

Parameters:

Name Type Description Default
brightness_limit [float, float] or float

factor range for changing brightness. If limit is a single float, the range will be (-limit, limit). Default: (-0.2, 0.2).

required
contrast_limit [float, float] or float

factor range for changing contrast. If limit is a single float, the range will be (-limit, limit). Default: (-0.2, 0.2).

required
brightness_by_max Boolean

If True adjust contrast by image dtype maximum, else adjust contrast by image mean.

required
p float

probability of applying the transform. Default: 0.5.

required

Targets

image

Image-types

uint8, float32

RandomContrast

Randomly change contrast of the input image.

Parameters:

Name Type Description Default
limit [float, float] or float

factor range for changing contrast. If limit is a single float, the range will be (-limit, limit). Default: (-0.2, 0.2).

required
p float

probability of applying the transform. Default: 0.5.

required

Targets

image

Image-types

uint8, float32

RandomCrop

Crop a random part of the input.

Parameters:

Name Type Description Default
height int

height of the crop.

required
width int

width of the crop.

required
p float

probability of applying the transform. Default: 1.

required

Targets

image, mask, bboxes, keypoints

Image-types

uint8, float32

RandomCropNearBBox

Crop bbox from image with random shift by x,y coordinates

Parameters:

Name Type Description Default
max_part_shift float

float value in (0.0, 1.0) range. Default 0.3

required
p float

probability of applying the transform. Default: 1.

required

Targets

image, mask, bboxes, keypoints

Image-types

uint8, float32

RandomFog

Simulates fog for the image

From https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library

Parameters:

Name Type Description Default
fog_coef_lower float

lower limit for fog intensity coefficient. Should be in [0, 1] range.

required
fog_coef_upper float

upper limit for fog intensity coefficient. Should be in [0, 1] range.

required
alpha_coef float

transparency of the fog circles. Should be in [0, 1] range.

required

Targets

image

Image-types

uint8, float32

RandomGamma

Parameters:

Name Type Description Default
gamma_limit float or [float, float]

If gamma_limit is a single float value, the range will be (-gamma_limit, gamma_limit). Default: (80, 120).

required
eps

Deprecated.

required

Targets

image

Image-types

uint8, float32

RandomGridShuffle

Random shuffle grid's cells on image.

Parameters:

Name Type Description Default
grid [int, int]

size of grid for splitting image.

required

Targets

image, mask

Image-types

uint8, float32

RandomRain

Adds rain effects.

From https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library

Parameters:

Name Type Description Default
slant_lower

should be in range [-20, 20].

required
slant_upper

should be in range [-20, 20].

required
drop_length

should be in range [0, 100].

required
drop_width

should be in range [1, 5].

required
drop_color list of (r, g, b

rain lines color.

required
blur_value int

rainy view are blurry

required
brightness_coefficient float

rainy days are usually shady. Should be in range [0, 1].

required
rain_type

One of [None, "drizzle", "heavy", "torrestial"]

required

Targets

image

Image-types

uint8, float32

RandomResizedCrop

Torchvision's variant of crop a random part of the input and rescale it to some size.

Parameters:

Name Type Description Default
height int

height after crop and resize.

required
width int

width after crop and resize.

required
scale [float, float]

range of size of the origin size cropped

required
ratio [float, float]

range of aspect ratio of the origin aspect ratio cropped

required
interpolation OpenCV flag

flag that is used to specify the interpolation algorithm. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_LINEAR.

required
p float

probability of applying the transform. Default: 1.

required

Targets

image, mask, bboxes, keypoints

Image-types

uint8, float32

RandomRotate90

Randomly rotate the input by 90 degrees zero or more times.

Parameters:

Name Type Description Default
p float

probability of applying the transform. Default: 0.5.

required

Targets

image, mask, bboxes, keypoints

Image-types

uint8, float32

apply(self, img, factor=0, **params)

Parameters:

Name Type Description Default
factor int

number of times the input will be rotated by 90 degrees.

0

RandomScale

Randomly resize the input. Output image size is different from the input image size.

Parameters:

Name Type Description Default
scale_limit [float, float] or float

scaling factor range. If scale_limit is a single float value, the range will be (1 - scale_limit, 1 + scale_limit). Default: (0.9, 1.1).

required
interpolation OpenCV flag

flag that is used to specify the interpolation algorithm. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_LINEAR.

required
p float

probability of applying the transform. Default: 0.5.

required

Targets

image, mask, bboxes, keypoints

Image-types

uint8, float32

RandomShadow

Simulates shadows for the image

From https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library

Parameters:

Name Type Description Default
shadow_roi float, float, float, float

region of the image where shadows will appear (x_min, y_min, x_max, y_max). All values should be in range [0, 1].

required
num_shadows_lower int

Lower limit for the possible number of shadows. Should be in range [0, num_shadows_upper].

required
num_shadows_upper int

Lower limit for the possible number of shadows. Should be in range [num_shadows_lower, inf].

required
shadow_dimension int

number of edges in the shadow polygons

required

Targets

image

Image-types

uint8, float32

RandomSizedBBoxSafeCrop

Crop a random part of the input and rescale it to some size without loss of bboxes.

Parameters:

Name Type Description Default
height int

height after crop and resize.

required
width int

width after crop and resize.

required
erosion_rate float

erosion rate applied on input image height before crop.

required
interpolation OpenCV flag

flag that is used to specify the interpolation algorithm. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_LINEAR.

required
p float

probability of applying the transform. Default: 1.

required

Targets

image, mask, bboxes

Image-types

uint8, float32

RandomSizedCrop

Crop a random part of the input and rescale it to some size.

Parameters:

Name Type Description Default
min_max_height [int, int]

crop size limits.

required
height int

height after crop and resize.

required
width int

width after crop and resize.

required
w2h_ratio float

aspect ratio of crop.

required
interpolation OpenCV flag

flag that is used to specify the interpolation algorithm. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_LINEAR.

required
p float

probability of applying the transform. Default: 1.

required

Targets

image, mask, bboxes, keypoints

Image-types

uint8, float32

RandomSnow

Bleach out some pixel values simulating snow.

From https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library

Parameters:

Name Type Description Default
snow_point_lower float

lower_bond of the amount of snow. Should be in [0, 1] range

required
snow_point_upper float

upper_bond of the amount of snow. Should be in [0, 1] range

required
brightness_coeff float

larger number will lead to a more snow on the image. Should be >= 0

required

Targets

image

Image-types

uint8, float32

RandomSunFlare

Simulates Sun Flare for the image

From https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library

Parameters:

Name Type Description Default
flare_roi float, float, float, float

region of the image where flare will appear (x_min, y_min, x_max, y_max). All values should be in range [0, 1].

required
angle_lower float

should be in range [0, angle_upper].

required
angle_upper float

should be in range [angle_lower, 1].

required
num_flare_circles_lower int

lower limit for the number of flare circles. Should be in range [0, num_flare_circles_upper].

required
num_flare_circles_upper int

upper limit for the number of flare circles. Should be in range [num_flare_circles_lower, inf].

required
src_radius int required
src_color int, int, int

color of the flare

required

Targets

image

Image-types

uint8, float32

Resize

Resize the input to the given height and width.

Parameters:

Name Type Description Default
height int

desired height of the output.

required
width int

desired width of the output.

required
interpolation OpenCV flag

flag that is used to specify the interpolation algorithm. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_LINEAR.

required
p float

probability of applying the transform. Default: 1.

required

Targets

image, mask, bboxes, keypoints

Image-types

uint8, float32

RGBShift

Randomly shift values for each channel of the input RGB image.

Parameters:

Name Type Description Default
r_shift_limit [int, int] or int

range for changing values for the red channel. If r_shift_limit is a single int, the range will be (-r_shift_limit, r_shift_limit). Default: (-20, 20).

required
g_shift_limit [int, int] or int

range for changing values for the green channel. If g_shift_limit is a single int, the range will be (-g_shift_limit, g_shift_limit). Default: (-20, 20).

required
b_shift_limit [int, int] or int

range for changing values for the blue channel. If b_shift_limit is a single int, the range will be (-b_shift_limit, b_shift_limit). Default: (-20, 20).

required
p float

probability of applying the transform. Default: 0.5.

required

Targets

image

Image-types

uint8, float32

Rotate

Rotate the input by an angle selected randomly from the uniform distribution.

Parameters:

Name Type Description Default
limit [int, int] or int

range from which a random angle is picked. If limit is a single int an angle is picked from (-limit, limit). Default: (-90, 90)

required
interpolation OpenCV flag

flag that is used to specify the interpolation algorithm. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_LINEAR.

required
border_mode OpenCV flag

flag that is used to specify the pixel extrapolation method. Should be one of: cv2.BORDER_CONSTANT, cv2.BORDER_REPLICATE, cv2.BORDER_REFLECT, cv2.BORDER_WRAP, cv2.BORDER_REFLECT_101. Default: cv2.BORDER_REFLECT_101

required
value int, float, list of ints, list of float

padding value if border_mode is cv2.BORDER_CONSTANT.

required
mask_value int, float, list of ints, list of float

padding value if border_mode is cv2.BORDER_CONSTANT applied for masks.

required
p float

probability of applying the transform. Default: 0.5.

required

Targets

image, mask, bboxes, keypoints

Image-types

uint8, float32

ShiftScaleRotate

Randomly apply affine transforms: translate, scale and rotate the input.

Parameters:

Name Type Description Default
shift_limit [float, float] or float

shift factor range for both height and width. If shift_limit is a single float value, the range will be (-shift_limit, shift_limit). Absolute values for lower and upper bounds should lie in range [0, 1]. Default: (-0.0625, 0.0625).

required
scale_limit [float, float] or float

scaling factor range. If scale_limit is a single float value, the range will be (-scale_limit, scale_limit). Default: (-0.1, 0.1).

required
rotate_limit [int, int] or int

rotation range. If rotate_limit is a single int value, the range will be (-rotate_limit, rotate_limit). Default: (-45, 45).

required
interpolation OpenCV flag

flag that is used to specify the interpolation algorithm. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_LINEAR.

required
border_mode OpenCV flag

flag that is used to specify the pixel extrapolation method. Should be one of: cv2.BORDER_CONSTANT, cv2.BORDER_REPLICATE, cv2.BORDER_REFLECT, cv2.BORDER_WRAP, cv2.BORDER_REFLECT_101. Default: cv2.BORDER_REFLECT_101

required
value int, float, list of int, list of float

padding value if border_mode is cv2.BORDER_CONSTANT.

required
mask_value int, float, list of int, list of float

padding value if border_mode is cv2.BORDER_CONSTANT applied for masks.

required
p float

probability of applying the transform. Default: 0.5.

required

Targets

image, mask, keypoints

Image-types

uint8, float32

SmallestMaxSize

Rescale an image so that minimum side is equal to max_size, keeping the aspect ratio of the initial image.

Parameters:

Name Type Description Default
max_size int

maximum size of smallest side of the image after the transformation.

required
interpolation OpenCV flag

interpolation method. Default: cv2.INTER_LINEAR.

required
p float

probability of applying the transform. Default: 1.

required

Targets

image, mask, bboxes, keypoints

Image-types

uint8, float32

Solarize

Invert all pixel values above a threshold.

Parameters:

Name Type Description Default
threshold [int, int] or int, or [float, float] or float

range for solarizing threshold.

required
If threshold is a single value, the range will be [threshold, threshold]. Default

128.

required
p float

probability of applying the transform. Default: 0.5.

required

Targets

image

Image-types

any

ToFloat

Divide pixel values by max_value to get a float32 output array where all values lie in the range [0, 1.0]. If max_value is None the transform will try to infer the maximum value by inspecting the data type of the input image.

See Also: :class:~albumentations.augmentations.transforms.FromFloat

Parameters:

Name Type Description Default
max_value float

maximum possible input value. Default: None.

required
p float

probability of applying the transform. Default: 1.0.

required

Targets

image

Image-types

any type

ToGray

Convert the input RGB image to grayscale. If the mean pixel value for the resulting image is greater than 127, invert the resulting grayscale image.

Parameters:

Name Type Description Default
p float

probability of applying the transform. Default: 0.5.

required

Targets

image

Image-types

uint8, float32

ToSepia

Applies sepia filter to the input RGB image

Parameters:

Name Type Description Default
p float

probability of applying the transform. Default: 0.5.

required

Targets

image

Image-types

uint8, float32

Transpose

Transpose the input by swapping rows and columns.

Parameters:

Name Type Description Default
p float

probability of applying the transform. Default: 0.5.

required

Targets

image, mask, bboxes, keypoints

Image-types

uint8, float32

VerticalFlip

Flip the input vertically around the x-axis.

Parameters:

Name Type Description Default
p float

probability of applying the transform. Default: 0.5.

required

Targets

image, mask, bboxes, keypoints

Image-types

uint8, float32