Sub topic 6
Photometric Transforms: Color, Contrast, Noise, and Blur
Assume you know Python, pixel arrays, supervised image classification, and the difference between training and validation data. This chapter focuses on photometric transforms. A photometric transform changes pixel values without moving objects to new locations.
Photometric augmentation helps a model ignore harmless changes in lighting, camera settings, and image quality. For example, a cat should usually remain a cat after a small brightness change. During training, the model sees several visual versions of the same labeled example. This reduces overfitting, because the model is less likely to memorize exact pixel patterns.
Choosing label-preserving changes
A transform is label-preserving when the target label should stay the same after the transform. The right strength depends on the data collection process and the task.
| Transform | What changes | Typical useful variation |
|---|---|---|
| Brightness | Overall light level | Indoor or outdoor exposure |
| Contrast | Difference between dark and light pixels | Camera or lighting differences |
| Saturation | Color intensity | Different cameras or illumination |
| Hue | Basic color position | Mild color cast |
| Noise | Small random pixel changes | Sensor noise or compression |
| Blur | Fine image detail | Motion, focus, or resolution changes |
Brightness multiplies or shifts pixel values. Contrast moves values away from or toward their average. Saturation controls how vivid colors appear. Hue changes the color family, such as shifting red toward orange. Large hue or saturation changes can alter the class when color is part of the label.
Noise adds random variation. Gaussian noise is a common model, but real camera noise may depend on brightness. Blur removes high-frequency detail. A small blur can model focus problems, while strong blur can destroy the evidence needed for classification.
Applying transforms in a pipeline
Libraries usually apply photometric transforms to a PIL image or an unsigned 8-bit tensor before conversion to a normalized floating-point tensor. Normalization changes the numeric range for the model, so transforms that expect ordinary pixel values should generally come first.
from torchvision import transforms
train_tf = transforms.Compose([
transforms.RandomResizedCrop(224),
transforms.RandomHorizontalFlip(),
transforms.ColorJitter(
brightness=0.2,
contrast=0.2,
saturation=0.2,
hue=0.05,
),
transforms.RandomGrayscale(p=0.05),
transforms.ToTensor(),
transforms.Normalize(
mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225],
),
])ColorJitter samples a new setting for each image. Its values are ranges around the original image, not fixed replacements. RandomGrayscale occasionally removes color, which is useful only when shape and texture still identify the class.
A deterministic evaluation pipeline should resize, crop, convert, and normalize without random color, noise, or blur. Otherwise, validation scores can change between runs and become difficult to compare.
Order, strength, and failure modes
The order of photometric operations affects the result. Adding noise and then applying strong contrast can amplify the noise. Blurring before downsampling may look different from blurring after downsampling. Keep the pipeline simple until you have inspected its outputs.
Use a transform only when its variation occurs in the target environment. For example, grayscale augmentation is a poor choice for a task where color identifies the class. Artificial color shifts can also harm medical or scientific images when pixel intensity has physical meaning.
Inspect batches of augmented images before training. Check that objects remain visible, colors remain plausible, and the image still deserves its original label.
Exercise
A traffic-sign classifier uses color to distinguish red stop signs from blue signs. Should you use strong hue shifts and frequent grayscale conversion?
Show answer
No. Those transforms can change the evidence that defines the label. Use mild brightness and contrast changes, and validate any color transform with visual inspection and a controlled experiment.