← Back to all transforms
RGBShift
Description
Randomly shift values for each channel of the input RGB image. Args: r_shift_limit ((int, int) or int): range for changing values for the red channel. If r_shift_limit is a single int, the range will be (-r_shift_limit, r_shift_limit). Default: (-20, 20). g_shift_limit ((int, int) or int): range for changing values for the green channel. If g_shift_limit is a single int, the range will be (-g_shift_limit, g_shift_limit). Default: (-20, 20). b_shift_limit ((int, int) or int): range for changing values for the blue channel. If b_shift_limit is a single int, the range will be (-b_shift_limit, b_shift_limit). Default: (-20, 20). p (float): probability of applying the transform. Default: 0.5. Targets: image Image types: uint8, float32 Note: - For uint8 images, the shift values represent absolute pixel values in the range [0, 255]. For example, a shift of 20 for a uint8 image would add 20 to the corresponding channel. - For float32 images, the shift values represent fractions of the full value range [0, 1]. For example, a shift of 0.1 for a float32 image would add 0.1 to the corresponding channel. - The shift values are applied independently to each channel. - After applying the shift, values are clipped to the valid range for the image dtype: [0, 255] for uint8 and [0, 1] for float32. Examples: >>> import numpy as np >>> import albumentations as A >>> # Shift RGB channels for uint8 image >>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8) >>> transform = A.RGBShift(r_shift_limit=30, g_shift_limit=30, b_shift_limit=30, p=1.0) >>> shifted_image = transform(image=image)['image'] >>> # Shift RGB channels for float32 image >>> image = np.random.rand(100, 100, 3).astype(np.float32) >>> transform = A.RGBShift(r_shift_limit=0.1, g_shift_limit=0.1, b_shift_limit=0.1, p=1.0) >>> shifted_image = transform(image=image)['image']
Parameters
- r_shift_limit: int | tuple[int, int] | float | tuple[float, float] (default: (-20, 20))
- g_shift_limit: int | tuple[int, int] | float | tuple[float, float] (default: (-20, 20))
- b_shift_limit: int | tuple[int, int] | float | tuple[float, float] (default: (-20, 20))
- p: float (default: 0.5)
Targets
- Image
Try it out
ⓘ
Original Image:
Result:
Transform result will appear here