Skip to content
class

RandomBrightnessContrast

extendsPhotometricTransform[BCParams]
RandomBrightnessContrast(brightness_limit: float | tuple[float, float] = 0.2, contrast_limit: float | tuple[float, float] = 0.2, p: float = 0.5)

Randomly perturb brightness and contrast jointly (Albumentations RandomBrightnessContrast).

Samples a brightness offset and a contrast multiplier independently from their limit ranges, then applies img * (1 + c) + b in one pass and clips to [0, 1]. Equivalent to chaining RandomBrightness and RandomContrast but cheaper (one fused expression, one clip).

Parameters

brightness_limitfloat or (float, float)= 0.2
Additive brightness offset range. A scalar v is interpreted as the symmetric range (-v, v).
contrast_limitfloat or (float, float)= 0.2
Multiplicative contrast offset range (multiplier is 1 + sampled_value). Scalar v expands to (-v, v).
pfloat= 0.5
Probability of applying the transform.

Examples

>>> import lucid
>>> import lucid.utils.transforms as T
>>> tf = T.RandomBrightnessContrast(brightness_limit=0.2, contrast_limit=0.2, p=1.0)
>>> out = tf(T.Image(lucid.rand(3, 32, 32))).data
>>> tuple(out.shape)
(3, 32, 32)

Used by 1

Constructors

1
dunder

__init__

→None
__init__(brightness_limit: float | tuple[float, float] = 0.2, contrast_limit: float | tuple[float, float] = 0.2, p: float = 0.5)

Instance methods

1
fn

make_params

→BCParams
make_params(img: Tensor)

Sample per-call random parameters for RandomBrightnessContrast.

Parameters

Image tensor; not inspected, carried through for dispatch.

Returns

BCParams

Carries brightness (additive offset) and contrast (multiplier delta), each drawn uniformly from their respective limit ranges.

Dunder methods

1