Skip to content
class

RandomContrast

extendsPhotometricTransform[ScalarParams]
RandomContrast(limit: float | tuple[float, float] = 0.2, p: float = 0.5)

Randomly perturb contrast only (Albumentations RandomContrast).

Samples a contrast factor uniformly from limit, multiplies the image by 1 + factor, and clips to [0, 1]. Equivalent to the contrast leg of RandomBrightnessContrast — included as a standalone class for parity with the Albumentations API.

Parameters

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.RandomContrast(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__(limit: float | tuple[float, float] = 0.2, p: float = 0.5)

Instance methods

1
fn

make_params

→ScalarParams
make_params(img: Tensor)

Sample per-call random parameters for RandomContrast.

Parameters

Image tensor; not inspected, carried through for dispatch.

Returns

ScalarParams

Carries value — the contrast delta drawn uniformly from limit; the effective multiplier is 1 + value.

Dunder methods

1