Skip to content

Functional transforms (augmentations.functional)

def albumentations.augmentations.functional.add_fog(img, fog_coef, alpha_coef, haze_list) [view source on GitHub]

Add fog to the image.

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

Parameters:

Name Type Description
img numpy.ndarray

Image.

fog_coef float

Fog coefficient.

alpha_coef float

Alpha coefficient.

haze_list list

Returns:

Type Description
numpy.ndarray

Image.

def albumentations.augmentations.functional.add_rain(img, slant, drop_length, drop_width, drop_color, blur_value, brightness_coefficient, rain_drops) [view source on GitHub]

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

Parameters:

Name Type Description
img numpy.ndarray

Image.

slant int
drop_length
drop_width
drop_color
blur_value int

Rainy view are blurry.

brightness_coefficient float

Rainy days are usually shady.

rain_drops

Returns:

Type Description
numpy.ndarray

Image.

def albumentations.augmentations.functional.add_shadow(img, vertices_list) [view source on GitHub]

Add shadows to the image.

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

Parameters:

Name Type Description
img numpy.ndarray
vertices_list list

Returns:

Type Description
numpy.ndarray

def albumentations.augmentations.functional.add_snow(img, snow_point, brightness_coeff) [view source on GitHub]

Bleaches out pixels, imitation snow.

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

Parameters:

Name Type Description
img numpy.ndarray

Image.

snow_point

Number of show points.

brightness_coeff

Brightness coefficient.

Returns:

Type Description
numpy.ndarray

Image.

def albumentations.augmentations.functional.add_sun_flare(img, flare_center_x, flare_center_y, src_radius, src_color, circles) [view source on GitHub]

Add sun flare.

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

Parameters:

Name Type Description
img numpy.ndarray
flare_center_x float
flare_center_y float
src_radius
src_color int, int, int
circles list

Returns:

Type Description
numpy.ndarray

def albumentations.augmentations.functional.bbox_crop(bbox, x_min, y_min, x_max, y_max, rows, cols) [view source on GitHub]

Crop a bounding box.

Parameters:

Name Type Description
bbox tuple

A bounding box (x_min, y_min, x_max, y_max).

x_min int
y_min int
x_max int
y_max int
rows int

Image rows.

cols int

Image cols.

Returns:

Type Description
tuple

A cropped bounding box (x_min, y_min, x_max, y_max).

def albumentations.augmentations.functional.bbox_flip(bbox, d, rows, cols) [view source on GitHub]

Flip a bounding box either vertically, horizontally or both depending on the value of d.

Parameters:

Name Type Description
bbox tuple

A bounding box (x_min, y_min, x_max, y_max).

d int
rows int

Image rows.

cols int

Image cols.

Returns:

Type Description
tuple

A bounding box (x_min, y_min, x_max, y_max).

Exceptions:

Type Description
ValueError

if value of d is not -1, 0 or 1.

def albumentations.augmentations.functional.bbox_hflip(bbox, rows, cols) [view source on GitHub]

Flip a bounding box horizontally around the y-axis.

Parameters:

Name Type Description
bbox tuple

A bounding box (x_min, y_min, x_max, y_max).

rows int

Image rows.

cols int

Image cols.

Returns:

Type Description
tuple

A bounding box (x_min, y_min, x_max, y_max).

def albumentations.augmentations.functional.bbox_rot90(bbox, factor, rows, cols) [view source on GitHub]

Rotates a bounding box by 90 degrees CCW (see np.rot90)

Parameters:

Name Type Description
bbox tuple

A bounding box tuple (x_min, y_min, x_max, y_max).

factor int

Number of CCW rotations. Must be in set {0, 1, 2, 3} See np.rot90.

rows int

Image rows.

cols int

Image cols.

Returns:

Type Description
tuple

A bounding box tuple (x_min, y_min, x_max, y_max).

def albumentations.augmentations.functional.bbox_rotate(bbox, angle, rows, cols) [view source on GitHub]

Rotates a bounding box by angle degrees.

Parameters:

Name Type Description
bbox tuple

A bounding box (x_min, y_min, x_max, y_max).

angle int

Angle of rotation in degrees.

rows int

Image rows.

cols int

Image cols.

Returns:

Type Description

A bounding box (x_min, y_min, x_max, y_max).

def albumentations.augmentations.functional.bbox_transpose(bbox, axis, rows, cols) [view source on GitHub]

Transposes a bounding box along given axis.

Parameters:

Name Type Description
bbox tuple

A bounding box (x_min, y_min, x_max, y_max).

axis int

0 - main axis, 1 - secondary axis.

rows int

Image rows.

cols int

Image cols.

Returns:

Type Description
tuple

A bounding box tuple (x_min, y_min, x_max, y_max).

Exceptions:

Type Description
ValueError

If axis not equal to 0 or 1.

def albumentations.augmentations.functional.bbox_vflip(bbox, rows, cols) [view source on GitHub]

Flip a bounding box vertically around the x-axis.

Parameters:

Name Type Description
bbox tuple

A bounding box (x_min, y_min, x_max, y_max).

rows int

Image rows.

cols int

Image cols.

Returns:

Type Description
tuple

A bounding box (x_min, y_min, x_max, y_max).

def albumentations.augmentations.functional.crop_bbox_by_coords(bbox, crop_coords, crop_height, crop_width, rows, cols) [view source on GitHub]

Crop a bounding box using the provided coordinates of bottom-left and top-right corners in pixels and the required height and width of the crop.

Parameters:

Name Type Description
bbox tuple

A cropped box (x_min, y_min, x_max, y_max).

crop_coords tuple

Crop coordinates (x1, y1, x2, y2).

crop_height int
crop_width int
rows int

Image rows.

cols int

Image cols.

Returns:

Type Description
tuple

A cropped bounding box (x_min, y_min, x_max, y_max).

def albumentations.augmentations.functional.crop_keypoint_by_coords(keypoint, crop_coords, crop_height, crop_width, rows, cols) [view source on GitHub]

Crop a keypoint using the provided coordinates of bottom-left and top-right corners in pixels and the required height and width of the crop.

Parameters:

Name Type Description
keypoint tuple

A keypoint (x, y, angle, scale).

crop_coords tuple

Crop box coords (x1, x2, y1, y2).

crop height (int

Crop height.

crop_width int

Crop width.

rows int

Image height.

cols int

Image width.

Returns:

Type Description

A keypoint (x, y, angle, scale).

def albumentations.augmentations.functional.elastic_transform(img, alpha, sigma, alpha_affine, interpolation=1, border_mode=4, value=None, random_state=None, approximate=False) [view source on GitHub]

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.

def albumentations.augmentations.functional.elastic_transform_approx(img, alpha, sigma, alpha_affine, interpolation=1, border_mode=4, value=None, random_state=None) [view source on GitHub]

Elastic deformation of images as described in [Simard2003]_ (with modifications for speed). 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.

def albumentations.augmentations.functional.equalize(img, mask=None, mode='cv', by_channels=True) [view source on GitHub]

Equalize the image histogram.

Parameters:

Name Type Description
img numpy.ndarray

RGB or grayscale image.

mask numpy.ndarray

An optional mask. If given, only the pixels selected by the mask are included in the analysis. Maybe 1 channel or 3 channel array.

mode str

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

by_channels bool

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

Returns:

Type Description
numpy.ndarray

Equalized image.

def albumentations.augmentations.functional.fancy_pca(img, alpha=0.1) [view source on GitHub]

Perform 'Fancy PCA' augmentation from: http://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks.pdf

Parameters:

Name Type Description
img

numpy array with (h, w, rgb) shape, as ints between 0-255)

alpha

how much to perturb/scale the eigen vecs and vals the paper used std=0.1

Returns:

Type Description

numpy image-like array as float range(0, 1)

def albumentations.augmentations.functional.grid_distortion(img, num_steps=10, xsteps=(), ysteps=(), interpolation=1, border_mode=4, value=None) [view source on GitHub]

def albumentations.augmentations.functional.iso_noise(image, color_shift=0.05, intensity=0.5, random_state=None, **kwargs) [view source on GitHub]

Apply poisson noise to image to simulate camera sensor noise.

Parameters:

Name Type Description
image numpy.ndarray

Input image, currently, only RGB, uint8 images are supported.

color_shift float
intensity float

Multiplication factor for noise values. Values of ~0.5 are produce noticeable, yet acceptable level of noise.

random_state
**kwargs

Returns:

Type Description
numpy.ndarray

Noised image

def albumentations.augmentations.functional.keypoint_center_crop(keypoint, crop_height, crop_width, rows, cols) [view source on GitHub]

Keypoint center crop.

Parameters:

Name Type Description
keypoint tuple

A keypoint (x, y, angle, scale).

crop_height int

Crop height.

crop_width int

Crop width.

h_start int

Crop height start.

w_start int

Crop width start.

rows int

Image height.

cols int

Image width.

Returns:

Type Description
tuple

A keypoint (x, y, angle, scale).

def albumentations.augmentations.functional.keypoint_flip(keypoint, d, rows, cols) [view source on GitHub]

Flip a keypoint either vertically, horizontally or both depending on the value of d.

Parameters:

Name Type Description
keypoint tuple

A keypoint (x, y, angle, scale).

d int

Number of flip. Must be -1, 0 or 1: * 0 - vertical flip, * 1 - horizontal flip, * -1 - vertical and horizontal flip.

rows int

Image height.

cols int

Image width.

Returns:

Type Description
tuple

A keypoint (x, y, angle, scale).

Exceptions:

Type Description
ValueError

if value of d is not -1, 0 or 1.

def albumentations.augmentations.functional.keypoint_hflip(keypoint, rows, cols) [view source on GitHub]

Flip a keypoint horizontally around the y-axis.

Parameters:

Name Type Description
keypoint tuple

A keypoint (x, y, angle, scale).

rows int

Image height.

cols int

Image width.

Returns:

Type Description
tuple

A keypoint (x, y, angle, scale).

def albumentations.augmentations.functional.keypoint_random_crop(keypoint, crop_height, crop_width, h_start, w_start, rows, cols) [view source on GitHub]

Keypoint random crop.

Parameters:

Name Type Description
keypoint

(tuple): A keypoint (x, y, angle, scale).

crop_height int

Crop height.

crop_width int

Crop width.

h_start int

Crop height start.

w_start int

Crop width start.

rows int

Image height.

cols int

Image width.

Returns:

Type Description

A keypoint (x, y, angle, scale).

def albumentations.augmentations.functional.keypoint_rot90(keypoint, factor, rows, cols, **params) [view source on GitHub]

Rotates a keypoint by 90 degrees CCW (see np.rot90)

Parameters:

Name Type Description
keypoint tuple

A keypoint (x, y, angle, scale).

factor int

Number of CCW rotations. Must be in range [0;3] See np.rot90.

rows int

Image height.

cols int

Image width.

Returns:

Type Description
tuple

A keypoint (x, y, angle, scale).

Exceptions:

Type Description
ValueError

if factor not in set {0, 1, 2, 3}

def albumentations.augmentations.functional.keypoint_rotate(keypoint, angle, rows, cols, **params) [view source on GitHub]

Rotate a keypoint by angle.

Parameters:

Name Type Description
keypoint tuple

A keypoint (x, y, angle, scale).

angle float

Rotation angle.

rows int

Image height.

cols int

Image width.

Returns:

Type Description
tuple

A keypoint (x, y, angle, scale).

def albumentations.augmentations.functional.keypoint_scale(keypoint, scale_x, scale_y) [view source on GitHub]

Scales a keypoint by scale_x and scale_y.

Parameters:

Name Type Description
keypoint tuple

A keypoint (x, y, angle, scale).

scale_x int

Scale coefficient x-axis.

scale_y int

Scale coefficient y-axis.

Returns:

Type Description

A keypoint (x, y, angle, scale).

def albumentations.augmentations.functional.keypoint_transpose(keypoint) [view source on GitHub]

Rotate a keypoint by angle.

Parameters:

Name Type Description
keypoint tuple

A keypoint (x, y, angle, scale).

Returns:

Type Description
tuple

A keypoint (x, y, angle, scale).

def albumentations.augmentations.functional.keypoint_vflip(keypoint, rows, cols) [view source on GitHub]

Flip a keypoint vertically around the x-axis.

Parameters:

Name Type Description
keypoint tuple

A keypoint (x, y, angle, scale).

rows int

Image height.

cols( int

Image width.

Returns:

Type Description
tuple

A keypoint (x, y, angle, scale).

def albumentations.augmentations.functional.multiply(img, multiplier) [view source on GitHub]

Parameters:

Name Type Description
img numpy.ndarray

Image.

multiplier numpy.ndarray

Multiplier coefficient.

Returns:

Type Description
numpy.ndarray

Image multiplied by multiplier coefficient.

def albumentations.augmentations.functional.posterize(img, bits) [view source on GitHub]

Reduce the number of bits for each color channel.

Parameters:

Name Type Description
img numpy.ndarray

image to posterize.

bits int

number of high bits. Must be in range [0, 8]

Returns:

Type Description
numpy.ndarray

Image with reduced color channels.

def albumentations.augmentations.functional.preserve_channel_dim(func) [view source on GitHub]

Preserve dummy channel dim.

def albumentations.augmentations.functional.preserve_shape(func) [view source on GitHub]

Preserve shape of the image

def albumentations.augmentations.functional.py3round(number) [view source on GitHub]

Unified rounding in all python versions.

def albumentations.augmentations.functional.solarize(img, threshold=128) [view source on GitHub]

Invert all pixel values above a threshold.

Parameters:

Name Type Description
img numpy.ndarray

The image to solarize.

threshold int

All pixels above this greyscale level are inverted.

Returns:

Type Description
numpy.ndarray

Solarized image.

def albumentations.augmentations.functional.swap_tiles_on_image(image, tiles) [view source on GitHub]

Swap tiles on image.

Parameters:

Name Type Description
image np.ndarray

Input image.

tiles np.ndarray

array of tuples( current_left_up_corner_row, current_left_up_corner_col, old_left_up_corner_row, old_left_up_corner_col, height_tile, width_tile)

Returns:

Type Description
np.ndarray

Output image.