Skip to content
class

Affine

extends_WarpTransform
Affine(scale: float | tuple[float, float] = 1.0, translate_percent: float | tuple[float, float] = 0.0, rotate: float | tuple[float, float] = 0.0, shear: float | tuple[float, float] = 0.0, interpolation: int | str | Interpolation = 1, border_mode: int = 4, value: float = 0.0, p: float = 0.5)

General affine: scale / translate / rotate / shear (Albumentations Affine).

Parameters

scalefloat or (float, float)= 1.0
Uniform scale (sampled if a range).
translate_percentfloat or (float, float)= 0.0
Fraction-of-size translation (sampled per axis).
rotatefloat or (float, float)= 0
Rotation-angle range in degrees.
shearfloat or (float, float)= 0
Shear-angle range in degrees (applied to x).
interpolationint | str | Interpolation= 1
As in Rotate.
border_modeint | str | Interpolation= 1
As in Rotate.
valueint | str | Interpolation= 1
As in Rotate.
pint | str | Interpolation= 1
As in Rotate.

Examples

>>> import lucid, lucid.utils.transforms as T
>>> tf = T.Affine(p=1.0)
>>> tuple(tf(T.Image(lucid.rand(3, 32, 32))).data.shape)
(3, 32, 32)

Used by 1

Constructors

1
dunder

__init__

→None
__init__(scale: float | tuple[float, float] = 1.0, translate_percent: float | tuple[float, float] = 0.0, rotate: float | tuple[float, float] = 0.0, shear: float | tuple[float, float] = 0.0, interpolation: int | str | Interpolation = 1, border_mode: int = 4, value: float = 0.0, p: float = 0.5)

Instance methods

1
fn

make_params

→WarpParams
make_params(img: Tensor)

Sample per-call random parameters for Affine.

Parameters

Image tensor; its spatial size is read to anchor the warp and to convert translate_percent into pixel translations.

Returns

WarpParams

Carries the composed (3, 3) matrix (scale, rotate, shear-x, translate, anchored at the image centre) and out_hw equal to the input (H, W).

Notes

The sampled rotation angle is negated when fed to affine_matrix so Affine agrees with Rotate on rotation sign.

Dunder methods

1