Skip to content

Documentation for all Available Warping Transformations

BarrelDistortion

Bases: WarpTransform

Applies a barrel distortion effect by distorting the radial distance from the center using a polynomial approximation.

Note: We use an an approximation of the polynomial radial distortion model to invert the original barrel formulas. see https://stackoverflow.com/questions/6199636/formulas-for-barrel-pincushion-distortion

Transformation
r' = r * (1 + strength * r^2)
x' = r' * cos(theta)
y' = r' * sin(theta)

Parameters:

Name Type Description Default
strength float

The strength of the barrel distortion effect.

0.5

generate_warp_field

generate_warp_field(height, width)

Generates the warp field for the barrel distortion.

Parameters:

Name Type Description Default
height int

The height of the image.

required
width int

The width of the image.

required

Returns:

Type Description
Tensor

The grid for warping the image.

Bulge

Bases: WarpTransform

Applies a bulge distortion effect by radially distorting the coordinates outward.

Transformation
r' = r^strength
x' = r' * cos(theta)
y' = r' * sin(theta)

Parameters:

Name Type Description Default
strength float

The strength of the bulge distortion effect. Must be greater than or equal to 1.0.

1.0

generate_warp_field

generate_warp_field(height, width)

Generates the warp field for the bulge distortion.

Parameters:

Name Type Description Default
height int

The height of the image.

required
width int

The width of the image.

required

Returns:

Type Description
Tensor

The grid for warping the image.

Compression

Bases: Stretching

Applies a compression effect along the specified axis.

Transformation
x' = x * (1 + strength)  (if axis = 'horizontal')
y' = y * (1 + strength)  (if axis = 'vertical')

Parameters:

Name Type Description Default
strength float

The strength of the stretching effect. Should be >=0.

0.5
axis str

The axis along which to apply the stretching effect ('horizontal' or 'vertical').

'horizontal'

Fisheye

Bases: WarpTransform

Applies a fisheye distortion effect by stretching the magnitude of the coordinates based on a power function.

Transformation

r' = r^{1 + strength}
x' = r' cos(theta)
y' = r' sin(theta)
where r and theta are the polar form coordinate of x,y and k the strength.

Parameters:

Name Type Description Default
strength float

The strength of the distorsion. Identity function for strenght = 0.0.

0.5

generate_warp_field

generate_warp_field(height, width)

Generates the warp field for the fisheye distortion.

Parameters:

Name Type Description Default
height int

The height of the image.

required
width int

The width of the image.

required

Returns:

Type Description
Tensor

The grid for warping the image.

Implosion

Bases: Bulge

Applies an implosion distortion effect by radially distorting the coordinates inward.

Transformation
r' = r^strength
x' = r' * cos(theta)
y' = r' * sin(theta)

Parameters:

Name Type Description Default
strength float

The strength of the implosion distortion effect. Must be between 0.0 and 1.0.

0.5

Perspective

Bases: WarpTransform

pylint: disable=C0301

Applies a random perspective wrap as defined here: https://pytorch.org/vision/main/_modules/torchvision/transforms/transforms.html#RandomPerspective https://pytorch.org/vision/main/_modules/torchvision/transforms/functional.html#perspective

Transformation

Picks random end points for perspective warp and uses current corners as start points to generate the warping matrix. Given the warping coefficients (a, b, c, d, e, f, g, h) we have the following association:

x' = (ax + by + c) / (gx + hy + 1)
y' = (dx + ey + f) / (gx + hy + 1)

Parameters:

Name Type Description Default
strength float

The strength of the perspective distortion effect.

0.5

generate_warp_field

generate_warp_field(height, width)

Generates the warp field for the shear distortion.

Parameters:

Name Type Description Default
height int

The height of the image.

required
width int

The width of the image.

required

Returns:

Type Description
Tensor

The grid for warping the image.

Pinch

Bases: WarpTransform

Applies a pinch distortion effect by pinching it towards the user.

Transformation
pinch_factor = sin(pi/2 * r)^(-strength)
x' = x' * pinch_factor
y' = y' * pinch_factor

Parameters:

Name Type Description Default
strength float

The strength of the pinch distortion effect. Must be between 0.0 and 1.0.

0.5

generate_warp_field

generate_warp_field(height, width)

Generates the warp field for the pinch distortion.

Parameters:

Name Type Description Default
height int

The height of the image.

required
width int

The width of the image.

required

Returns:

Type Description
Tensor

The grid for warping the image.

Pincushion

Bases: BarrelDistortion

Applies a pincushion distortion effect, which is the inverse of barrel distortion.

Transformation
r' = r * (1 - strength * r^2)
x' = r' * cos(theta)
y' = r' * sin(theta)

Parameters:

Name Type Description Default
strength float

The strength of the pincushion distortion effect.

0.5

Punch

Bases: Pinch

Applies a punch distortion effect which is opposite of pinch and pushes image away from the user.

Transformation
punch_factor = sin(pi/2 * r)^(strength)
x' = x' * punch_factor
y' = y' * punch_factor

Parameters:

Name Type Description Default
strength float

The strength of the punch distortion effect. Must be between 0.0 and 1.0.

0.5

Shear

Bases: WarpTransform

Applies a shear distortion effect. Implemented as defined here: https://en.wikipedia.org/wiki/Shear_mapping

Transformation
x' = x + strength*y (if axis = 'horizontal')
y' = strength*x + y (if axis = 'vertical')

Parameters:

Name Type Description Default
strength float

The strength of the shear distortion effect. Also defined as the cotangent of the shear angle. Positive for right/top leaning, negative for left/bottom leaning shear.

0.5
axis

The axis along which to apply the shearing effect ('horizontal' or 'vertical').

'horizontal'

generate_warp_field

generate_warp_field(height, width)

Generates the warp field for the shear distortion.

Parameters:

Name Type Description Default
height int

The height of the image.

required
width int

The width of the image.

required

Returns:

Type Description
Tensor

The grid for warping the image.

Spherize

Bases: WarpTransform

Applies a spherical distortion effect by mapping the coordinates onto a sphere.

Transformation
r' = sin(r * strength * pi/2) / (strength * pi/2)
x' = r' * cos(theta)
y' = r' * sin(theta)

Parameters:

Name Type Description Default
strength float

The strength of the spherical distortion effect.

0.5

generate_warp_field

generate_warp_field(height, width)

Generates the warp field for the spherize distortion.

Parameters:

Name Type Description Default
height int

The height of the image.

required
width int

The width of the image.

required

Returns:

Type Description
Tensor

The grid for warping the image.

Stretching

Bases: WarpTransform

Applies a stretching effect along the specified axis.

Transformation
x' = x * (1 - strength)  (if axis = 'horizontal')
y' = y * (1 - strength)  (if axis = 'vertical')

Parameters:

Name Type Description Default
strength float

The strength of the stretching effect.

0.5
axis str

The axis along which to apply the stretching effect ('horizontal' or 'vertical').

'horizontal'

generate_warp_field

generate_warp_field(height, width)

Generates the warp field for the stretching distortion.

Parameters:

Name Type Description Default
height int

The height of the image.

required
width int

The width of the image.

required

Returns:

Type Description
Tensor

The grid for warping the image.

Swirl

Bases: WarpTransform

Applies a swirl distortion effect by rotating the coordinates around the center based on their radial distance from the center.

Transformation
theta' = theta + (radius - r) * strength
x' = r' * cos(theta')
y' = r' * sin(theta')

Parameters:

Name Type Description Default
strength float

The strength of the swirl effect. Higher values result in a stronger swirl.

1.0
radius float

The maximum distance from the center where the swirl effect is applied.

1.0

generate_warp_field

generate_warp_field(height, width)

Generates the warp field for the swirl distortion.

Parameters:

Name Type Description Default
height int

The height of the image.

required
width int

The width of the image.

required

Returns:

Type Description
Tensor

The grid for warping the image.

Twirl

Bases: WarpTransform

Applies a twirl distortion effect by rotating the coordinates around the center with an angle proportional to their radial distance from the center.

Transformation
theta' = theta + strength * r
x' = r * cos(theta')
y' = r * sin(theta')

Parameters:

Name Type Description Default
strength float

The strength of the twirl effect.

0.5

generate_warp_field

generate_warp_field(height, width)

Generates the warp field for the twirl distortion.

Parameters:

Name Type Description Default
height int

The height of the image.

required
width int

The width of the image.

required

Returns:

Type Description
Tensor

The grid for warping the image.

Wave

Bases: WarpTransform

Applies a wave distortion effect along the specified axis.

Transformation
y' = y + strength * amplitude * sin(2 * pi * frequency * x + phase)  (if axis = 'horizontal')
x' = x + strength * amplitude * sin(2 * pi * frequency * y + phase)  (if axis = 'vertical')

Parameters:

Name Type Description Default
strength float

The strength of the distortion as defined by the scaling of the amplitude.

1
amplitude float

The amplitude of the wave.

0.1
frequency float

The frequency of the wave.

1.0
phase float

The phase shift of the wave.

0.0
axis str

The axis along which to apply the wave effect ('horizontal' or 'vertical').

'horizontal'

generate_warp_field

generate_warp_field(height, width)

Generates the warp field for the wave distortion.

Parameters:

Name Type Description Default
height int

The height of the image.

required
width int

The width of the image.

required

Returns:

Type Description
Tensor

The grid for warping the image.