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

ColorJitter

Targets:
image
Image Types:uint8, float32

Randomly jitter brightness/contrast/saturation/hue in random order. Separate _range per effect. Strong color augmentation for classification and detection.

This transform is similar to torchvision's ColorJitter but with some differences due to the use of OpenCV instead of Pillow. The main differences are:

  1. OpenCV and Pillow use different formulas to convert images to HSV format.
  2. This implementation uses value saturation instead of uint8 overflow as in Pillow.

These differences may result in slightly different output compared to torchvision's ColorJitter.

Arguments
brightness_range
tuple[float, float]
[0.8,1.2]

Range for the brightness factor, sampled per image. Both ends should be non-negative. Default: (0.8, 1.2)

contrast_range
tuple[float, float]
[0.8,1.2]

Range for the contrast factor, sampled per image. Both ends should be non-negative. Default: (0.8, 1.2)

saturation_range
tuple[float, float]
[0.8,1.2]

Range for the saturation factor, sampled per image. Both ends should be non-negative. Default: (0.8, 1.2)

hue_range
tuple[float, float]
[-0.5,0.5]

Range for the hue factor, sampled per image. Values should be in [-0.5, 0.5]. Default: (-0.5, 0.5)

p (float): Probability of applying the transform. Should be in the range [0, 1]. Default: 0.5

Examples
>>> import numpy as np
>>> import albumentations as A
>>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
>>> transform = A.ColorJitter(
...     brightness_range=(0.8, 1.2),
...     contrast_range=(0.8, 1.2),
...     saturation_range=(0.8, 1.2),
...     hue_range=(-0.1, 0.1),
...     p=1.0,
... )
>>> result = transform(image=image)
>>> jittered_image = result['image']
Notes
  • The order of application for these color transformations is random for each image.
  • The ranges for brightness_range, contrast_range, and saturation_range are applied as multiplicative factors.
  • The range for hue_range is applied as an additive factor.
References
  • ColorJitterhttps://pytorch.org/vision/stable/generated/torchvision.transforms.ColorJitter.html
  • Color Conversionshttps://docs.opencv.org/3.4/de/d25/imgproc_color_conversions.html