Class ColorJitter<T>
- Namespace
- AiDotNet.Augmentation.Image
- Assembly
- AiDotNet.dll
Applies random combinations of brightness, contrast, saturation, and hue adjustments.
public class ColorJitter<T> : AugmentationBase<T, ImageTensor<T>>, IAugmentation<T, ImageTensor<T>>
Type Parameters
TThe numeric type for calculations.
- Inheritance
-
AugmentationBase<T, ImageTensor<T>>ColorJitter<T>
- Implements
-
IAugmentation<T, ImageTensor<T>>
- Inherited Members
Remarks
ColorJitter is a powerful composite augmentation that randomly adjusts multiple color properties in a single operation. This simulates the wide variety of color variations that occur in real-world photography due to different cameras, lighting, and environments.
For Beginners: Think of this as applying multiple photo filters randomly. Just like how the same scene looks different when photographed with different phones or in different lighting, ColorJitter creates these natural variations automatically. This is one of the most commonly used augmentations for image classification.
When to use:
- General image classification tasks
- When training data comes from a single camera/source but deployment varies
- To make models robust to different lighting and camera settings
When NOT to use:
- Color is the primary classification feature
- Medical/scientific imaging with calibrated color
- Tasks where specific color accuracy is required
Constructors
ColorJitter(double, double, double, double, double)
Creates a new color jitter augmentation.
public ColorJitter(double brightnessRange = 0.2, double contrastRange = 0.2, double saturationRange = 0.2, double hueRange = 0.1, double probability = 0.8)
Parameters
brightnessRangedoubleThe range for brightness adjustment. The actual factor will be sampled from [1 - brightnessRange, 1 + brightnessRange]. Set to 0.0 to disable. Industry standard default is 0.2 (factors from 0.8 to 1.2).
contrastRangedoubleThe range for contrast adjustment. The actual factor will be sampled from [1 - contrastRange, 1 + contrastRange]. Set to 0.0 to disable. Industry standard default is 0.2 (factors from 0.8 to 1.2).
saturationRangedoubleThe range for saturation adjustment. The actual factor will be sampled from [1 - saturationRange, 1 + saturationRange]. Set to 0.0 to disable. Industry standard default is 0.2 (factors from 0.8 to 1.2).
hueRangedoubleThe range for hue adjustment in degrees. The actual shift will be sampled from [-hueRange, +hueRange]. Set to 0.0 to disable. Industry standard default is 0.1 (about 36 degrees maximum shift).
probabilitydoubleThe probability of applying this augmentation (0.0 to 1.0). Industry standard default is 0.8 (applied to 80% of images).
Remarks
For Beginners: Each range parameter controls how much that property can vary. A brightnessRange of 0.2 means images can be 20% brighter or darker. The hueRange is in degrees (0-1 representing 0-360 degrees) - use small values like 0.1 to avoid unnatural color shifts.
Properties
BrightnessRange
Gets the brightness adjustment range (0.0 = no change possible).
public double BrightnessRange { get; }
Property Value
ContrastRange
Gets the contrast adjustment range (0.0 = no change possible).
public double ContrastRange { get; }
Property Value
HueRange
Gets the hue adjustment range in degrees (0.0 = no change possible).
public double HueRange { get; }
Property Value
SaturationRange
Gets the saturation adjustment range (0.0 = no change possible).
public double SaturationRange { get; }
Property Value
Methods
ApplyAugmentation(ImageTensor<T>, AugmentationContext<T>)
Applies the color jitter to the image.
protected override ImageTensor<T> ApplyAugmentation(ImageTensor<T> data, AugmentationContext<T> context)
Parameters
dataImageTensor<T>contextAugmentationContext<T>
Returns
- ImageTensor<T>
GetParameters()
Gets the parameters of this augmentation.
public override IDictionary<string, object> GetParameters()
Returns
- IDictionary<string, object>
A dictionary of parameter names to values.