Skip to content
class

CenterCrop

extends_NoParamsGeometricTransform[Empty]
CenterCrop(height: int, width: int, offset: Literal['round', 'floor'] = 'round', p: float = 1.0)

Crop a centred height x width window (Albumentations CenterCrop).

Computes a deterministic crop centred on the input — top-left at (round((H - height) / 2), round((W - width) / 2)) — and applies the same offsets to mask / boxes / keypoints so every target stays aligned.

Parameters

heightint
Target crop height in pixels.
widthint
Target crop width in pixels.
offset(round, floor)= "round"
Where the window sits when the margin is odd. "round" is the default and matches Albumentations and the reference vision package; "floor" matches Hugging Face's fast processors, and a checkpoint published through one expects that placement.
pfloat= 1.0
Probability of applying the transform.

Examples

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

Used by 2

Constructors

1
dunder

__init__

→None
__init__(height: int, width: int, offset: Literal['round', 'floor'] = 'round', p: float = 1.0)

Instance methods

1
fn

make_params

→Emptyfrom _NoParams
make_params(img: Tensor)

Dunder methods

1