Geometric functional transforms (augmentations.geometric.functional)¶
def
albumentations.augmentations.geometric.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[float, float, float, float] |
A bounding box |
d |
int |
dimension. 0 for vertical flip, 1 for horizontal, -1 for transpose |
rows |
int |
Image rows. |
cols |
int |
Image cols. |
Returns:
Type | Description |
---|---|
Tuple[float, float, float, float] |
A bounding box |
Exceptions:
Type | Description |
---|---|
ValueError |
if value of |
def
albumentations.augmentations.geometric.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[float, float, float, float] |
A bounding box |
rows |
int |
Image rows. |
cols |
int |
Image cols. |
Returns:
Type | Description |
---|---|
Tuple[float, float, float, float] |
A bounding box |
def
albumentations.augmentations.geometric.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[float, float, float, float] |
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[float, float, float, float] |
tuple: A bounding box tuple (x_min, y_min, x_max, y_max). |
def
albumentations.augmentations.geometric.functional.bbox_rotate (bbox, angle, method, rows, cols)
[view source on GitHub]¶
Rotates a bounding box by angle degrees.
Parameters:
Name | Type | Description |
---|---|---|
bbox |
Tuple[float, float, float, float] |
A bounding box |
angle |
float |
Angle of rotation in degrees. |
method |
str |
Rotation method used. Should be one of: "largest_box", "ellipse". Default: "largest_box". |
rows |
int |
Image rows. |
cols |
int |
Image cols. |
Returns:
Type | Description |
---|---|
Tuple[float, float, float, float] |
A bounding box |
References: https://arxiv.org/abs/2109.13488
def
albumentations.augmentations.geometric.functional.bbox_shift_scale_rotate (bbox, angle, scale, dx, dy, rotate_method, rows, cols, **
kwargs)
[view source on GitHub]¶
Rotates, shifts and scales a bounding box. Rotation is made by angle degrees, scaling is made by scale factor and shifting is made by dx and dy.
Parameters:
Name | Type | Description |
---|---|---|
bbox |
tuple |
A bounding box |
angle |
int |
Angle of rotation in degrees. |
scale |
int |
Scale factor. |
dx |
int |
Shift along x-axis in pixel units. |
dy |
int |
Shift along y-axis in pixel units. |
rotate_method(str) |
Rotation method used. Should be one of: "largest_box", "ellipse". Default: "largest_box". |
|
rows |
int |
Image rows. |
cols |
int |
Image cols. |
Returns:
Type | Description |
---|---|
|
A bounding box |
def
albumentations.augmentations.geometric.functional.bbox_transpose (bbox, axis, rows, cols)
[view source on GitHub]¶
Transposes a bounding box along given axis.
Parameters:
Name | Type | Description |
---|---|---|
bbox |
Tuple[float, float, float, float] |
A bounding box |
axis |
int |
0 - main axis, 1 - secondary axis. |
rows |
int |
Image rows. |
cols |
int |
Image cols. |
Returns:
Type | Description |
---|---|
Tuple[float, float, float, float] |
A bounding box tuple |
Exceptions:
Type | Description |
---|---|
ValueError |
If axis not equal to 0 or 1. |
def
albumentations.augmentations.geometric.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[float, float, float, float] |
A bounding box |
rows |
int |
Image rows. |
cols |
int |
Image cols. |
Returns:
Type | Description |
---|---|
Tuple[float, float, float, float] |
tuple: A bounding box |
def
albumentations.augmentations.geometric.functional.elastic_transform (img, alpha, sigma, alpha_affine, interpolation=1, border_mode=4, value=None, random_state=None, approximate=False, same_dxdy=False)
[view source on GitHub]¶
Elastic deformation of images as described in [Simard2003]_ (with modifications). Based on https://gist.github.com/ernestum/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.geometric.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/ernestum/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.geometric.functional.from_distance_maps (distance_maps, inverted, if_not_found_coords, threshold=None)
[view source on GitHub]¶
Convert outputs of to_distance_maps()
to KeypointsOnImage
.
This is the inverse of to_distance_maps
.
Parameters:
Name | Type | Description |
---|---|---|
distance_maps |
ndarray |
The distance maps. |
inverted |
bool |
Whether the given distance maps were generated in inverted mode
(i.e. :func: |
if_not_found_coords |
Union[Sequence[int], dict] |
Coordinates to use for keypoints that cannot be found in
|
threshold |
Optional[float] |
The search for keypoints works by searching for the
argmin (non-inverted) or argmax (inverted) in each channel. This
parameters contains the maximum (non-inverted) or minimum (inverted) value to accept in order to view a hit
as a keypoint. Use |
nb_channels |
None, int |
Number of channels of the image on which the keypoints are placed.
Some keypoint augmenters require that information. If set to |
def
albumentations.augmentations.geometric.functional.grid_distortion (img, num_steps=10, xsteps=(), ysteps=(), interpolation=1, border_mode=4, value=None)
[view source on GitHub]¶
Perform a grid distortion of an input image.
Reference: http://pythology.blogspot.sg/2014/03/interpolation-on-regular-distorted-grid.html
def
albumentations.augmentations.geometric.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[float, float, float, float] |
A keypoint |
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[float, float, float, float] |
A keypoint |
Exceptions:
Type | Description |
---|---|
ValueError |
if value of |
def
albumentations.augmentations.geometric.functional.keypoint_hflip (keypoint, rows, cols)
[view source on GitHub]¶
Flip a keypoint horizontally around the y-axis.
Parameters:
Name | Type | Description |
---|---|---|
keypoint |
Tuple[float, float, float, float] |
A keypoint |
rows |
int |
Image height. |
cols |
int |
Image width. |
Returns:
Type | Description |
---|---|
Tuple[float, float, float, float] |
A keypoint |
def
albumentations.augmentations.geometric.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[float, float, float, float] |
A keypoint |
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[float, float, float, float] |
tuple: A keypoint |
Exceptions:
Type | Description |
---|---|
ValueError |
if factor not in set {0, 1, 2, 3} |
def
albumentations.augmentations.geometric.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 |
angle |
float |
Rotation angle. |
rows |
int |
Image height. |
cols |
int |
Image width. |
Returns:
Type | Description |
---|---|
tuple |
A keypoint |
def
albumentations.augmentations.geometric.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[float, float, float, float] |
A keypoint |
scale_x |
float |
Scale coefficient x-axis. |
scale_y |
float |
Scale coefficient y-axis. |
Returns:
Type | Description |
---|---|
Tuple[float, float, float, float] |
A keypoint |
def
albumentations.augmentations.geometric.functional.keypoint_transpose (keypoint)
[view source on GitHub]¶
Rotate a keypoint by angle.
Parameters:
Name | Type | Description |
---|---|---|
keypoint |
Tuple[float, float, float, float] |
A keypoint |
Returns:
Type | Description |
---|---|
Tuple[float, float, float, float] |
A keypoint |
def
albumentations.augmentations.geometric.functional.keypoint_vflip (keypoint, rows, cols)
[view source on GitHub]¶
Flip a keypoint vertically around the x-axis.
Parameters:
Name | Type | Description |
---|---|---|
keypoint |
Tuple[float, float, float, float] |
A keypoint |
rows |
int |
Image height. |
cols |
int |
Image width. |
Returns:
Type | Description |
---|---|
Tuple[float, float, float, float] |
tuple: A keypoint |
def
albumentations.augmentations.geometric.functional.optical_distortion (img, k=0, dx=0, dy=0, interpolation=1, border_mode=4, value=None)
[view source on GitHub]¶
Barrel / pincushion distortion. Unconventional augment.
Reference: | https://stackoverflow.com/questions/6199636/formulas-for-barrel-pincushion-distortion | https://stackoverflow.com/questions/10364201/image-transformation-in-opencv | https://stackoverflow.com/questions/2477774/correcting-fisheye-distortion-programmatically | http://www.coldvision.io/2017/03/02/advanced-lane-finding-using-opencv/
def
albumentations.augmentations.geometric.functional.py3round (number)
[view source on GitHub]¶
Unified rounding in all python versions.
def
albumentations.augmentations.geometric.functional.rotation2DMatrixToEulerAngles (matrix, y_up=False)
[view source on GitHub]¶
Parameters:
Name | Type | Description |
---|---|---|
matrix |
ndarray |
Rotation matrix |
y_up |
bool |
is Y axis looks up or down |
def
albumentations.augmentations.geometric.functional.to_distance_maps (keypoints, height, width, inverted=False)
[view source on GitHub]¶
Generate a (H,W,N)
array of distance maps for N
keypoints.
The n
-th distance map contains at every location (y, x)
the
euclidean distance to the n
-th keypoint.
This function can be used as a helper when augmenting keypoints with a method that only supports the augmentation of images.
Parameters:
Name | Type | Description |
---|---|---|
keypoint |
keypoint coordinates |
|
height |
int |
image height |
width |
int |
image width |
inverted |
bool |
If |
Returns:
Type | Description |
---|---|
ndarray |
(H, W, N) ndarray
A |