Transforms (augmentations.transforms)¶
¶
class albumentations.augmentations.transforms.Blur
(blur_limit=7, always_apply=False, p=0.5)
[view source on GitHub]
¶
Blur the input image using a random-sized kernel.
Parameters:
Name | Type | Description |
---|---|---|
blur_limit |
int, [int, int] |
maximum kernel size for blurring the input image. Should be in range [3, inf). Default: (3, 7). |
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image
Image types: uint8, float32
class albumentations.augmentations.transforms.ChannelDropout
(channel_drop_range=(1, 1), fill_value=0, always_apply=False, p=0.5)
[view source on GitHub]
¶
Randomly Drop Channels in the input Image.
Parameters:
Name | Type | Description |
---|---|---|
channel_drop_range |
[int, int] |
range from which we choose the number of channels to drop. |
fill_value |
int, float |
pixel value for the dropped channel. |
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image
Image types: uint8, uint16, unit32, float32
class albumentations.augmentations.transforms.ChannelShuffle
[view source on GitHub]
¶
Randomly rearrange channels of the input RGB image.
Parameters:
Name | Type | Description |
---|---|---|
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image
Image types: uint8, float32
class albumentations.augmentations.transforms.CLAHE
(clip_limit=4.0, tile_grid_size=(8, 8), always_apply=False, p=0.5)
[view source on GitHub]
¶
Apply Contrast Limited Adaptive Histogram Equalization to the input image.
Parameters:
Name | Type | Description |
---|---|---|
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). |
tile_grid_size |
[int, int] |
size of grid for histogram equalization. Default: (8, 8). |
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image
Image types: uint8
class albumentations.augmentations.transforms.CoarseDropout
(max_holes=8, max_height=8, max_width=8, min_holes=None, min_height=None, min_width=None, fill_value=0, mask_fill_value=None, always_apply=False, p=0.5)
[view source on GitHub]
¶
CoarseDropout of the rectangular regions in the image.
Parameters:
Name | Type | Description |
---|---|---|
max_holes |
int |
Maximum number of regions to zero out. |
max_height |
int |
Maximum height of the hole. |
max_width |
int |
Maximum width of the hole. |
min_holes |
int |
Minimum number of regions to zero out. If |
min_height |
int |
Minimum height of the hole. Default: None. If |
min_width |
int |
Minimum width of the hole. If |
fill_value |
int, float, list of int, list of float |
value for dropped pixels. |
mask_fill_value |
int, float, list of int, list of float |
fill value for dropped pixels
in mask. If |
Targets: image, mask
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
class albumentations.augmentations.transforms.ColorJitter
(brightness=0.2, contrast=0.2, saturation=0.2, hue=0.2, always_apply=False, p=0.5)
[view source on GitHub]
¶
Randomly changes the brightness, contrast, and saturation of an image. Compared to ColorJitter from torchvision, this transform gives a little bit different results because Pillow (used in torchvision) and OpenCV (used in Albumentations) transform an image to HSV format by different formulas. Another difference - Pillow uses uint8 overflow, but we use value saturation.
Parameters:
Name | Type | Description |
---|---|---|
brightness |
float or tuple of float (min, max |
How much to jitter brightness. brightness_factor is chosen uniformly from [max(0, 1 - brightness), 1 + brightness] or the given [min, max]. Should be non negative numbers. |
contrast |
float or tuple of float (min, max |
How much to jitter contrast. contrast_factor is chosen uniformly from [max(0, 1 - contrast), 1 + contrast] or the given [min, max]. Should be non negative numbers. |
saturation |
float or tuple of float (min, max |
How much to jitter saturation. saturation_factor is chosen uniformly from [max(0, 1 - saturation), 1 + saturation] or the given [min, max]. Should be non negative numbers. |
hue |
float or tuple of float (min, max |
How much to jitter hue. hue_factor is chosen uniformly from [-hue, hue] or the given [min, max]. Should have 0 <= hue <= 0.5 or -0.5 <= min <= max <= 0.5. |
class albumentations.augmentations.transforms.Cutout
(num_holes=8, max_h_size=8, max_w_size=8, fill_value=0, always_apply=False, p=0.5)
[view source on GitHub]
¶
CoarseDropout of the square regions in the image.
Parameters:
Name | Type | Description |
---|---|---|
num_holes |
int |
number of regions to zero out |
max_h_size |
int |
maximum height of the hole |
max_w_size |
int |
maximum width of the hole |
fill_value |
int, float, list of int, list of float |
value for dropped pixels. |
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
class albumentations.augmentations.transforms.Downscale
(scale_min=0.25, scale_max=0.25, interpolation=0, always_apply=False, p=0.5)
[view source on GitHub]
¶
Decreases image quality by downscaling and upscaling back.
Parameters:
Name | Type | Description |
---|---|---|
scale_min |
float |
lower bound on the image scale. Should be < 1. |
scale_max |
float |
lower bound on the image scale. Should be . |
interpolation |
|
cv2 interpolation method. cv2.INTER_NEAREST by default |
Targets: image
Image types: uint8, float32
class albumentations.augmentations.transforms.Emboss
(alpha=(0.2, 0.5), strength=(0.2, 0.7), always_apply=False, p=0.5)
[view source on GitHub]
¶
Emboss the input image and overlays the result with the original image.
Parameters:
Name | Type | Description |
---|---|---|
alpha |
[float, float] |
range to choose the visibility of the embossed image. At 0, only the original image is visible,at 1.0 only its embossed version is visible. Default: (0.2, 0.5). |
strength |
[float, float] |
strength range of the embossing. Default: (0.2, 0.7). |
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image
class albumentations.augmentations.transforms.Equalize
(mode='cv', by_channels=True, mask=None, mask_params=(), always_apply=False, p=0.5)
[view source on GitHub]
¶
Equalize the image histogram.
Parameters:
Name | Type | Description |
---|---|---|
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 |
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 |
mask_params |
list of str |
Params for mask function. |
Targets: image
Image types: uint8
class albumentations.augmentations.transforms.FancyPCA
(alpha=0.1, always_apply=False, p=0.5)
[view source on GitHub]
¶
Augment RGB image using FancyPCA from Krizhevsky's paper "ImageNet Classification with Deep Convolutional Neural Networks"
Parameters:
Name | Type | Description |
---|---|---|
alpha |
float |
how much to perturb/scale the eigen vecs and vals. scale is samples from gaussian distribution (mu=0, sigma=alpha) |
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/
class albumentations.augmentations.transforms.Flip
[view source on GitHub]
¶
Flip the input either horizontally, vertically or both horizontally and vertically.
Parameters:
Name | Type | Description |
---|---|---|
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image, mask, bboxes, keypoints
Image types: uint8, float32
albumentations.augmentations.transforms.Flip.apply(self, img, d=0, **params)
¶
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).
class albumentations.augmentations.transforms.FromFloat
(dtype='uint16', max_value=None, always_apply=False, p=1.0)
[view source on GitHub]
¶
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 |
---|---|---|
max_value |
float |
maximum possible input value. Default: None. |
dtype |
string or numpy data type |
data type of the output. See the |
p |
float |
probability of applying the transform. Default: 1.0. |
Targets: image
Image types: float32
.. _'Data types' page from the NumPy docs: https://docs.scipy.org/doc/numpy/user/basics.types.html
class albumentations.augmentations.transforms.GaussianBlur
(blur_limit=(3, 7), sigma_limit=0, always_apply=False, p=0.5)
[view source on GitHub]
¶
Blur the input image using a Gaussian filter with a random kernel size.
Parameters:
Name | Type | Description |
---|---|---|
blur_limit |
int, [int, int] |
maximum Gaussian kernel size for blurring the input image.
Must be zero or odd and in range [0, inf). If set to 0 it will be computed from sigma
as |
sigma_limit |
float, [float, float] |
Gaussian kernel standard deviation. Must be greater in range [0, inf).
If set single value |
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image
Image types: uint8, float32
class albumentations.augmentations.transforms.GaussNoise
(var_limit=(10.0, 50.0), mean=0, per_channel=True, always_apply=False, p=0.5)
[view source on GitHub]
¶
Apply gaussian noise to the input image.
Parameters:
Name | Type | Description |
---|---|---|
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). |
mean |
float |
mean of the noise. Default: 0 |
per_channel |
bool |
if set to True, noise will be sampled for each channel independently. Otherwise, the noise will be sampled once for all channels. Default: True |
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image
Image types: uint8, float32
class albumentations.augmentations.transforms.GlassBlur
(sigma=0.7, max_delta=4, iterations=2, always_apply=False, mode='fast', p=0.5)
[view source on GitHub]
¶
Apply glass noise to the input image.
Parameters:
Name | Type | Description |
---|---|---|
sigma |
float |
standard deviation for Gaussian kernel. |
max_delta |
int |
max distance between pixels which are swapped. |
iterations |
int |
number of repeats. Should be in range [1, inf). Default: (2). |
mode |
str |
mode of computation: fast or exact. Default: "fast". |
p |
float |
probability of applying the transform. Default: 0.5. |
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
class albumentations.augmentations.transforms.GridDistortion
(num_steps=5, distort_limit=0.3, interpolation=1, border_mode=4, value=None, mask_value=None, always_apply=False, p=0.5)
[view source on GitHub]
¶
Parameters:
Name | Type | Description |
---|---|---|
num_steps |
int |
count of grid cells on each side. |
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). |
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. |
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 |
value |
int, float, list of ints, list of float |
padding value if border_mode is cv2.BORDER_CONSTANT. |
mask_value |
int, float,
list of ints,
list of float |
padding value if border_mode is cv2.BORDER_CONSTANT applied for masks. |
Targets: image, mask
Image types: uint8, float32
class albumentations.augmentations.transforms.GridDropout
(ratio=0.5, unit_size_min=None, unit_size_max=None, holes_number_x=None, holes_number_y=None, shift_x=0, shift_y=0, random_offset=False, fill_value=0, mask_fill_value=None, always_apply=False, p=0.5)
[view source on GitHub]
¶
GridDropout, drops out rectangular regions of an image and the corresponding mask in a grid fashion.
Parameters:
Name | Type | Description |
---|---|---|
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. |
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: |
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: |
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: |
holes_number_y |
int |
the number of grid units in y direction. Must be between 1 and image height//2.
If |
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. |
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. |
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: |
fill_value |
int |
value for the dropped pixels. Default = 0 |
mask_fill_value |
int |
value for the dropped pixels in mask.
If |
Targets: image, mask
Image types: uint8, float32
References: https://arxiv.org/abs/2001.04086
class albumentations.augmentations.transforms.HorizontalFlip
[view source on GitHub]
¶
Flip the input horizontally around the y-axis.
Parameters:
Name | Type | Description |
---|---|---|
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image, mask, bboxes, keypoints
Image types: uint8, float32
class albumentations.augmentations.transforms.HueSaturationValue
(hue_shift_limit=20, sat_shift_limit=30, val_shift_limit=20, always_apply=False, p=0.5)
[view source on GitHub]
¶
Randomly change hue, saturation and value of the input image.
Parameters:
Name | Type | Description |
---|---|---|
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). |
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). |
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). |
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image
Image types: uint8, float32
class albumentations.augmentations.transforms.ImageCompression
(quality_lower=99, quality_upper=100, compression_type=<ImageCompressionType.JPEG: 0>, always_apply=False, p=0.5)
[view source on GitHub]
¶
Decrease Jpeg, WebP compression of an image.
Parameters:
Name | Type | Description |
---|---|---|
quality_lower |
float |
lower bound on the image quality. Should be in [0, 100] range for jpeg and [1, 100] for webp. |
quality_upper |
float |
upper bound on the image quality. Should be in [0, 100] range for jpeg and [1, 100] for webp. |
compression_type |
ImageCompressionType |
should be ImageCompressionType.JPEG or ImageCompressionType.WEBP. Default: ImageCompressionType.JPEG |
Targets: image
Image types: uint8, float32
class albumentations.augmentations.transforms.ImageCompression.ImageCompressionType
¶
An enumeration.
class albumentations.augmentations.transforms.InvertImg
[view source on GitHub]
¶
Invert the input image by subtracting pixel values from 255.
Parameters:
Name | Type | Description |
---|---|---|
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image
Image types: uint8
class albumentations.augmentations.transforms.ISONoise
(color_shift=(0.01, 0.05), intensity=(0.1, 0.5), always_apply=False, p=0.5)
[view source on GitHub]
¶
Apply camera sensor noise.
Parameters:
Name | Type | Description |
---|---|---|
color_shift |
[float, float] |
variance range for color hue change. Measured as a fraction of 360 degree Hue angle in HLS colorspace. |
intensity |
[float, float] |
Multiplicative factor that control strength of color and luminace noise. |
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image
Image types: uint8
class albumentations.augmentations.transforms.JpegCompression
(quality_lower=99, quality_upper=100, always_apply=False, p=0.5)
[view source on GitHub]
¶
Decrease Jpeg compression of an image.
Parameters:
Name | Type | Description |
---|---|---|
quality_lower |
float |
lower bound on the jpeg quality. Should be in [0, 100] range |
quality_upper |
float |
upper bound on the jpeg quality. Should be in [0, 100] range |
Targets: image
Image types: uint8, float32
class albumentations.augmentations.transforms.Lambda
(image=None, mask=None, keypoint=None, bbox=None, name=None, always_apply=False, p=1.0)
[view source on GitHub]
¶
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 |
---|---|---|
image |
callable |
Image transformation function. |
mask |
callable |
Mask transformation function. |
keypoint |
callable |
Keypoint transformation function. |
bbox |
callable |
BBox transformation function. |
always_apply |
bool |
Indicates whether this transformation should be always applied. |
p |
float |
probability of applying the transform. Default: 1.0. |
Targets: image, mask, bboxes, keypoints
Image types: Any
class albumentations.augmentations.transforms.MaskDropout
(max_objects=1, image_fill_value=0, mask_fill_value=0, always_apply=False, p=0.5)
[view source on GitHub]
¶
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
albumentations.augmentations.transforms.MaskDropout.__init__(self, max_objects=1, image_fill_value=0, mask_fill_value=0, always_apply=False, p=0.5)
special
¶
Parameters:
Name | Type | Description |
---|---|---|
max_objects |
|
Maximum number of labels that can be zeroed out. Can be tuple, in this case it's [min, max] |
image_fill_value |
|
Fill value to use when filling image. Can be 'inpaint' to apply inpaining (works only for 3-chahnel images) |
mask_fill_value |
|
Fill value to use when filling mask. |
Targets: image, mask
Image types: uint8, float32
class albumentations.augmentations.transforms.MedianBlur
(blur_limit=7, always_apply=False, p=0.5)
[view source on GitHub]
¶
Blur the input image using a median filter with a random aperture linear size.
Parameters:
Name | Type | Description |
---|---|---|
blur_limit |
int |
maximum aperture linear size for blurring the input image. Must be odd and in range [3, inf). Default: (3, 7). |
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image
Image types: uint8, float32
class albumentations.augmentations.transforms.MotionBlur
[view source on GitHub]
¶
Apply motion blur to the input image using a random-sized kernel.
Parameters:
Name | Type | Description |
---|---|---|
blur_limit |
int |
maximum kernel size for blurring the input image. Should be in range [3, inf). Default: (3, 7). |
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image
Image types: uint8, float32
class albumentations.augmentations.transforms.MultiplicativeNoise
(multiplier=(0.9, 1.1), per_channel=False, elementwise=False, always_apply=False, p=0.5)
[view source on GitHub]
¶
Multiply image to random number or array of numbers.
Parameters:
Name | Type | Description |
---|---|---|
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 |
per_channel |
bool |
If |
elementwise |
bool |
If |
Targets: image
Image types: Any
class albumentations.augmentations.transforms.Normalize
(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225), max_pixel_value=255.0, always_apply=False, p=1.0)
[view source on GitHub]
¶
Divide pixel values by 255 = 2**8 - 1, subtract mean per channel and divide by std per channel.
Parameters:
Name | Type | Description |
---|---|---|
mean |
float, list of float |
mean values |
std |
(float, list of float |
std values |
max_pixel_value |
float |
maximum possible pixel value |
Targets: image
Image types: uint8, float32
class albumentations.augmentations.transforms.OpticalDistortion
(distort_limit=0.05, shift_limit=0.05, interpolation=1, border_mode=4, value=None, mask_value=None, always_apply=False, p=0.5)
[view source on GitHub]
¶
Parameters:
Name | Type | Description |
---|---|---|
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). |
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). |
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. |
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 |
value |
int, float, list of ints, list of float |
padding value if border_mode is cv2.BORDER_CONSTANT. |
mask_value |
int, float,
list of ints,
list of float |
padding value if border_mode is cv2.BORDER_CONSTANT applied for masks. |
Targets: image, mask
Image types: uint8, float32
class albumentations.augmentations.transforms.PadIfNeeded
(min_height=1024, min_width=1024, pad_height_divisor=None, pad_width_divisor=None, border_mode=4, value=None, mask_value=None, always_apply=False, p=1.0)
[view source on GitHub]
¶
Pad side of the image / max if side is less than desired number.
Parameters:
Name | Type | Description |
---|---|---|
min_height |
int |
minimal result image height. |
min_width |
int |
minimal result image width. |
pad_height_divisor |
int |
if not None, ensures image height is dividable by value of this argument. |
pad_width_divisor |
int |
if not None, ensures image width is dividable by value of this argument. |
border_mode |
OpenCV flag |
OpenCV border mode. |
value |
int, float, list of int, list of float |
padding value if border_mode is cv2.BORDER_CONSTANT. |
mask_value |
int, float,
list of int,
list of float |
padding value for mask if border_mode is cv2.BORDER_CONSTANT. |
p |
float |
probability of applying the transform. Default: 1.0. |
Targets: image, mask, bbox, keypoints
Image types: uint8, float32
class albumentations.augmentations.transforms.Posterize
(num_bits=4, always_apply=False, p=0.5)
[view source on GitHub]
¶
Reduce the number of bits for each color channel.
Parameters:
Name | Type | Description |
---|---|---|
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. |
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image
Image types: uint8
class albumentations.augmentations.transforms.RandomBrightness
(limit=0.2, always_apply=False, p=0.5)
[view source on GitHub]
¶
Randomly change brightness of the input image.
Parameters:
Name | Type | Description |
---|---|---|
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). |
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image
Image types: uint8, float32
class albumentations.augmentations.transforms.RandomBrightnessContrast
(brightness_limit=0.2, contrast_limit=0.2, brightness_by_max=True, always_apply=False, p=0.5)
[view source on GitHub]
¶
Randomly change brightness and contrast of the input image.
Parameters:
Name | Type | Description |
---|---|---|
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). |
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). |
brightness_by_max |
Boolean |
If True adjust contrast by image dtype maximum, else adjust contrast by image mean. |
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image
Image types: uint8, float32
class albumentations.augmentations.transforms.RandomContrast
(limit=0.2, always_apply=False, p=0.5)
[view source on GitHub]
¶
Randomly change contrast of the input image.
Parameters:
Name | Type | Description |
---|---|---|
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). |
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image
Image types: uint8, float32
class albumentations.augmentations.transforms.RandomFog
(fog_coef_lower=0.3, fog_coef_upper=1, alpha_coef=0.08, always_apply=False, p=0.5)
[view source on GitHub]
¶
Simulates fog for the image
From https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library
Parameters:
Name | Type | Description |
---|---|---|
fog_coef_lower |
float |
lower limit for fog intensity coefficient. Should be in [0, 1] range. |
fog_coef_upper |
float |
upper limit for fog intensity coefficient. Should be in [0, 1] range. |
alpha_coef |
float |
transparency of the fog circles. Should be in [0, 1] range. |
Targets: image
Image types: uint8, float32
class albumentations.augmentations.transforms.RandomGamma
(gamma_limit=(80, 120), eps=None, always_apply=False, p=0.5)
[view source on GitHub]
¶
Parameters:
Name | Type | Description |
---|---|---|
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). |
eps |
|
Deprecated. |
Targets: image
Image types: uint8, float32
class albumentations.augmentations.transforms.RandomGridShuffle
(grid=(3, 3), always_apply=False, p=0.5)
[view source on GitHub]
¶
Random shuffle grid's cells on image.
Parameters:
Name | Type | Description |
---|---|---|
grid |
[int, int] |
size of grid for splitting image. |
Targets: image, mask
Image types: uint8, float32
class albumentations.augmentations.transforms.RandomRain
(slant_lower=-10, slant_upper=10, drop_length=20, drop_width=1, drop_color=(200, 200, 200), blur_value=7, brightness_coefficient=0.7, rain_type=None, always_apply=False, p=0.5)
[view source on GitHub]
¶
Adds rain effects.
From https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library
Parameters:
Name | Type | Description |
---|---|---|
slant_lower |
|
should be in range [-20, 20]. |
slant_upper |
|
should be in range [-20, 20]. |
drop_length |
|
should be in range [0, 100]. |
drop_width |
|
should be in range [1, 5]. |
drop_color |
list of (r, g, b |
rain lines color. |
blur_value |
int |
rainy view are blurry |
brightness_coefficient |
float |
rainy days are usually shady. Should be in range [0, 1]. |
rain_type |
|
One of [None, "drizzle", "heavy", "torrestial"] |
Targets: image
Image types: uint8, float32
class albumentations.augmentations.transforms.RandomShadow
(shadow_roi=(0, 0.5, 1, 1), num_shadows_lower=1, num_shadows_upper=2, shadow_dimension=5, always_apply=False, p=0.5)
[view source on GitHub]
¶
Simulates shadows for the image
From https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library
Parameters:
Name | Type | Description |
---|---|---|
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]. |
num_shadows_lower |
int |
Lower limit for the possible number of shadows.
Should be in range [0, |
num_shadows_upper |
int |
Lower limit for the possible number of shadows.
Should be in range [ |
shadow_dimension |
int |
number of edges in the shadow polygons |
Targets: image
Image types: uint8, float32
class albumentations.augmentations.transforms.RandomSnow
(snow_point_lower=0.1, snow_point_upper=0.3, brightness_coeff=2.5, always_apply=False, p=0.5)
[view source on GitHub]
¶
Bleach out some pixel values simulating snow.
From https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library
Parameters:
Name | Type | Description |
---|---|---|
snow_point_lower |
float |
lower_bond of the amount of snow. Should be in [0, 1] range |
snow_point_upper |
float |
upper_bond of the amount of snow. Should be in [0, 1] range |
brightness_coeff |
float |
larger number will lead to a more snow on the image. Should be >= 0 |
Targets: image
Image types: uint8, float32
class albumentations.augmentations.transforms.RandomSunFlare
(flare_roi=(0, 0, 1, 0.5), angle_lower=0, angle_upper=1, num_flare_circles_lower=6, num_flare_circles_upper=10, src_radius=400, src_color=(255, 255, 255), always_apply=False, p=0.5)
[view source on GitHub]
¶
Simulates Sun Flare for the image
From https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library
Parameters:
Name | Type | Description |
---|---|---|
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]. |
angle_lower |
float |
should be in range [0, |
angle_upper |
float |
should be in range [ |
num_flare_circles_lower |
int |
lower limit for the number of flare circles.
Should be in range [0, |
num_flare_circles_upper |
int |
upper limit for the number of flare circles.
Should be in range [ |
src_radius |
int |
|
src_color |
int, int, int |
color of the flare |
Targets: image
Image types: uint8, float32
class albumentations.augmentations.transforms.RandomToneCurve
(scale=0.1, always_apply=False, p=0.5)
[view source on GitHub]
¶
Randomly change the relationship between bright and dark areas of the image by manipulating its tone curve.
Parameters:
Name | Type | Description |
---|---|---|
scale |
float |
standard deviation of the normal distribution. Used to sample random distances to move two control points that modify the image's curve. Values should be in range [0, 1]. Default: 0.1 |
Targets: image
Image types: uint8
class albumentations.augmentations.transforms.RGBShift
(r_shift_limit=20, g_shift_limit=20, b_shift_limit=20, always_apply=False, p=0.5)
[view source on GitHub]
¶
Randomly shift values for each channel of the input RGB image.
Parameters:
Name | Type | Description |
---|---|---|
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). |
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). |
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). |
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image
Image types: uint8, float32
class albumentations.augmentations.transforms.Sharpen
(alpha=(0.2, 0.5), lightness=(0.5, 1.0), always_apply=False, p=0.5)
[view source on GitHub]
¶
Sharpen the input image and overlays the result with the original image.
Parameters:
Name | Type | Description |
---|---|---|
alpha |
[float, float] |
range to choose the visibility of the sharpened image. At 0, only the original image is visible, at 1.0 only its sharpened version is visible. Default: (0.2, 0.5). |
lightness |
[float, float] |
range to choose the lightness of the sharpened image. Default: (0.5, 1.0). |
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image
class albumentations.augmentations.transforms.Solarize
(threshold=128, always_apply=False, p=0.5)
[view source on GitHub]
¶
Invert all pixel values above a threshold.
Parameters:
Name | Type | Description |
---|---|---|
threshold |
[int, int] or int, or [float, float] or float |
range for solarizing threshold. |
If |
threshold is a single value, the range will be [threshold, threshold]. Default |
128. |
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image
Image types: any
class albumentations.augmentations.transforms.Superpixels
(p_replace=0.1, n_segments=100, max_size=128, interpolation=1, always_apply=False, p=0.5)
[view source on GitHub]
¶
Transform images parially/completely to their superpixel representation. This implementation uses skimage's version of the SLIC algorithm.
Parameters:
Name | Type | Description |
---|---|---|
p_replace |
float or tuple of float |
Defines for any segment the probability that the pixels within that
segment are replaced by their average color (otherwise, the pixels are not changed).
Examples:
* A probability of |
n_segments |
int, or tuple of int |
Rough target number of how many superpixels to generate (the algorithm
may deviate from this number). Lower value will lead to coarser superpixels.
Higher values are computationally more intensive and will hence lead to a slowdown
* If a single |
max_size |
int or None |
Maximum image size at which the augmentation is performed.
If the width or height of an image exceeds this value, it will be
downscaled before the augmentation so that the longest side matches |
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. |
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image
class albumentations.augmentations.transforms.ToFloat
(max_value=None, always_apply=False, p=1.0)
[view source on GitHub]
¶
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 |
---|---|---|
max_value |
float |
maximum possible input value. Default: None. |
p |
float |
probability of applying the transform. Default: 1.0. |
Targets: image
Image types: any type
class albumentations.augmentations.transforms.ToGray
[view source on GitHub]
¶
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 |
---|---|---|
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image
Image types: uint8, float32
class albumentations.augmentations.transforms.ToSepia
(always_apply=False, p=0.5)
[view source on GitHub]
¶
Applies sepia filter to the input RGB image
Parameters:
Name | Type | Description |
---|---|---|
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image
Image types: uint8, float32
class albumentations.augmentations.transforms.Transpose
[view source on GitHub]
¶
Transpose the input by swapping rows and columns.
Parameters:
Name | Type | Description |
---|---|---|
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image, mask, bboxes, keypoints
Image types: uint8, float32
class albumentations.augmentations.transforms.VerticalFlip
[view source on GitHub]
¶
Flip the input vertically around the x-axis.
Parameters:
Name | Type | Description |
---|---|---|
p |
float |
probability of applying the transform. Default: 0.5. |
Targets: image, mask, bboxes, keypoints
Image types: uint8, float32