SafeRotate
_WarpTransformSafeRotate(limit: float | tuple[float, float] = 90, interpolation: int | str | Interpolation = 1, border_mode: int = 4, value: float = 0.0, p: float = 0.5)Rotate by a random angle, expanding the canvas to keep all content (Albumentations SafeRotate).
Like Rotate but enlarges the output canvas so the full
rotated rectangle fits without clipping. The new size is
with sampled per call from limit. The affine
matrix is built as "rotate about the old center, then translate
into the centre of the new canvas" — so straight rotations
(multiples of 90°) preserve pixel positions exactly within their
new canvas, and content never leaves the frame.
Parameters
limitfloat or (float, float)= 90a is treated as (-a, a).0=nearest, 1=bilinear).border_modeint= 40 is constant fill with value; other modes mirror /
reflect the boundary.valuefloat= 0.0border_mode == 0.pfloat= 0.5Examples
>>> import lucid
>>> import lucid.utils.transforms as T
>>> tf = T.SafeRotate(limit=(45, 45), p=1.0)
>>> out = tf(T.Image(lucid.rand(3, 24, 32))).data
>>> out.shape[0] # channels preserved
3
>>> out.shape[-1] >= 32 # width expanded to fit rotated content
TrueUsed by 1
Constructors
1Instance methods
1Sample per-call random parameters for SafeRotate.
Parameters
imgTensorReturns
WarpParamsCarries the composed (3, 3) matrix (rotate about the
old centre, then translate into the centre of the new
canvas) and out_hw equal to the expanded
(new_h, new_w).
Notes
new_w = ceil(W*|cos| + H*|sin|) and
new_h = ceil(W*|sin| + H*|cos|) so no rotated content is
clipped.