← Back to all transforms

# ColorJitter

## Description

Randomly changes the brightness, contrast, saturation, and hue of an image. 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. Args: brightness (tuple[float, float] | float): How much to jitter brightness. If float: The brightness factor is chosen uniformly from [max(0, 1 - brightness), 1 + brightness]. If tuple: The brightness factor is sampled from the range specified. Should be non-negative numbers. Default: (0.8, 1.2) contrast (tuple[float, float] | float): How much to jitter contrast. If float: The contrast factor is chosen uniformly from [max(0, 1 - contrast), 1 + contrast]. If tuple: The contrast factor is sampled from the range specified. Should be non-negative numbers. Default: (0.8, 1.2) saturation (tuple[float, float] | float): How much to jitter saturation. If float: The saturation factor is chosen uniformly from [max(0, 1 - saturation), 1 + saturation]. If tuple: The saturation factor is sampled from the range specified. Should be non-negative numbers. Default: (0.8, 1.2) hue (float or tuple of float (min, max)): How much to jitter hue. If float: The hue factor is chosen uniformly from [-hue, hue]. Should have 0 <= hue <= 0.5. If tuple: The hue factor is sampled from the range specified. Values should be in range [-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 Targets: image Image types: uint8, float32 Note: - The order of application for these color transformations is random for each image. - The ranges for brightness, contrast, and saturation are applied as multiplicative factors. - The range for hue is applied as an additive factor. Example: >>> import numpy as np >>> import albumentations as A >>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8) >>> transform = A.ColorJitter(brightness=0.2, contrast=0.2, saturation=0.2, hue=0.1, p=1.0) >>> result = transform(image=image) >>> jittered_image = result['image'] References: - https://pytorch.org/vision/stable/transforms.html#torchvision.transforms.ColorJitter - https://docs.opencv.org/3.4/de/d25/imgproc_color_conversions.html

## Parameters

- brightness: float | tuple[float, float] (default: (0.8, 1.2))
- contrast: float | tuple[float, float] (default: (0.8, 1.2))
- saturation: float | tuple[float, float] (default: (0.8, 1.2))
- hue: float | tuple[float, float] (default: (-0.5, 0.5))
- p: float (default: 0.5)

## Targets

- Image

## Try it out

ⓘ

### Original Image:

### Result:

Transform result will appear here