• AlbumentationsAlbumentations
All TransformsGet LicenseDocumentationNews & Insights
Report IssueJoin Discord...

RGBShift

Targets:
image
Image Types:uint8, float32

Shift R, G, B with separate ranges. Specialized AdditiveNoise with constant uniform shifts. Params: r_shift_range, g_shift_range, b_shift_range.

A specialized version of AdditiveNoise that applies constant uniform shifts to RGB channels. Each channel (R,G,B) can have its own shift range specified.

Arguments
r_shift_range
tuple[float, float]
[-20,20]

Range (min, max) for shifting the red channel, sampled per image. For uint8 images values are absolute shifts in [0, 255]; for float images they are relative shifts in [0, 1]. Default: (-20, 20)

g_shift_range
tuple[float, float]
[-20,20]

Range (min, max) for shifting the green channel, sampled per image. Same units as r_shift_range. Default: (-20, 20)

b_shift_range
tuple[float, float]
[-20,20]

Range (min, max) for shifting the blue channel, sampled per image. Same units as r_shift_range. Default: (-20, 20)

p
float
0.5

Probability of applying the transform. Default: 0.5.

Examples
>>> import numpy as np
>>> import albumentations as A

# Shift RGB channels of uint8 image
>>> transform = A.RGBShift(
...     r_shift_range=(-30, 30),  # Will sample red shift from [-30, 30]
...     g_shift_range=(-20, 20),  # Will sample green shift from [-20, 20]
...     b_shift_range=(-10, 10),  # Will sample blue shift from [-10, 10]
...     p=1.0,
... )
>>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
>>> shifted = transform(image=image)["image"]

# Same effect using AdditiveNoise
>>> transform = A.AdditiveNoise(
...     noise_type="uniform",
...     spatial_mode="constant",  # One value per channel
...     noise_params={
...         "ranges": [(-30/255, 30/255), (-20/255, 20/255), (-10/255, 10/255)]
...     },
...     p=1.0
... )
Notes
  • Values are shifted independently for each channel
  • For uint8 images:
    • Input ranges like (-20, 20) represent pixel value shifts
    • A shift of 20 means adding 20 to that channel
    • Final values are clipped to [0, 255]
  • For float32 images:
    • Input ranges like (-0.1, 0.1) represent relative shifts
    • A shift of 0.1 means adding 0.1 to that channel
    • Final values are clipped to [0, 1]
See Also
  • AdditiveNoise: More general noise transform with various options:
    • Different noise distributions (uniform, gaussian, laplace, beta)
    • Spatial modes (constant, per-pixel, shared)
  • RandomToneCurve: For non-linear color transformations
  • RandomBrightnessContrast: For combined brightness and contrast adjustments
  • PlankianJitter: For color temperature adjustments
  • HueSaturationValue: For HSV color space adjustments
  • ColorJitter: For combined brightness, contrast, saturation adjustments