Color Jitter
Randomly changes the brightness, contrast, saturation, and hue of your images
This data augmentation tool adds brightness, contrast, saturation, and hue to your sample images.

Parameters

Brightness

It sets the brightness of the transformed image.

Contrast

In visual perception, contrast refers to the difference of color and brightness of objects in the same field of view.
โ€‹
The left part of the image has lower contrast than the right part.

Saturation

Color saturation refers to the intensity and the purity of a color as displayed in the image. If the image is highly saturated then the colors are more intense and vivid.
โ€‹
Original image
โ€‹
Saturated image

Hue

Hue is one of the main indication of the appearance of the color itself. It refers to the attribute of the visible light due to which it is differentiated from or similar to primary colors: red, green, and blue. Usually, colors with the same hue are distinguished with adjectives referring to their lightness or colorfulness, such as with "light blue", "pastel blue", etc.
The augmentation randomly picks a different "shift" to change the hue of the sample images.
โ€‹
Original image shifted in different colors.

Code Implementation

1
import albumentations as albu
2
from PIL import Image
3
import numpy as np
4
โ€‹
5
โ€‹
6
transform =albu.ColorJitter(brightness=0.2, contrast=0.2, saturation=0.2, hue=0.2, p=0.5)
7
โ€‹
8
โ€‹
9
image = np.array(Image.open('/some/image/file/path'))
10
image = transform(image=image)['image']
11
โ€‹
12
โ€‹
13
# Now the image is transformed and ready to be accepted by the model
14
โ€‹
Copied!

Further Resources

Last modified 3mo ago