RGBShift

Targets:
image
volume
Image Types:uint8, float32

Randomly shift values for each channel of the input RGB image.

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_limit
tuple[float, float] | float
[-20,20]

Range for shifting the red channel. Options:

  • If tuple (min, max): Sample shift value from this range
  • If int: Sample shift value from (-r_shift_limit, r_shift_limit)
  • For uint8 images: Values represent absolute shifts in [0, 255]
  • For float images: Values represent relative shifts in [0, 1] Default: (-20, 20)
g_shift_limit
tuple[float, float] | float
[-20,20]

Range for shifting the green channel. Options:

  • If tuple (min, max): Sample shift value from this range
  • If int: Sample shift value from (-g_shift_limit, g_shift_limit)
  • For uint8 images: Values represent absolute shifts in [0, 255]
  • For float images: Values represent relative shifts in [0, 1] Default: (-20, 20)
b_shift_limit
tuple[float, float] | float
[-20,20]

Range for shifting the blue channel. Options:

  • If tuple (min, max): Sample shift value from this range
  • If int: Sample shift value from (-b_shift_limit, b_shift_limit)
  • For uint8 images: Values represent absolute shifts in [0, 255]
  • For float images: Values represent relative shifts in [0, 1] 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_limit=30,  # Will sample red shift from [-30, 30]
...     g_shift_limit=(-20, 20),  # Will sample green shift from [-20, 20]
...     b_shift_limit=(-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)
    • Approximation for faster computation
  • 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