Skip to content
class

RandomCrop

extendsGeometricTransform[Offset]
RandomCrop(height: int, width: int, p: float = 1.0)

Crop a random height x width window (Albumentations RandomCrop).

Samples top uniformly from [0, H - height] and left uniformly from [0, W - width], then applies the same crop to image / mask / boxes / keypoints so every target stays aligned.

Parameters

heightint
Target crop height in pixels (must be <= H).
widthint
Target crop width in pixels (must be <= W).
pfloat= 1.0
Probability of applying the transform.

Examples

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

Used by 1

Constructors

1
dunder

__init__

→None
__init__(height: int, width: int, p: float = 1.0)

Instance methods

1
fn

make_params

→Offset
make_params(img: Tensor)

Sample per-call random parameters for RandomCrop.

Parameters

Image tensor; its spatial size bounds the uniform draw of the crop window's top-left corner.

Returns

Offset

Carries top ~ U[0, H - height] and left ~ U[0, W - width]; the configured height / width are reused as the crop size.

Dunder methods

1