Table of Contents

Class Contrast<T>

Namespace
AiDotNet.Augmentation.Image
Assembly
AiDotNet.dll

Adjusts the contrast of an image by scaling pixel values around the mean.

public class Contrast<T> : AugmentationBase<T, ImageTensor<T>>, IAugmentation<T, ImageTensor<T>>

Type Parameters

T

The numeric type for calculations.

Inheritance
Contrast<T>
Implements
Inherited Members

Remarks

Contrast adjustment changes the difference between light and dark areas of an image. Higher contrast makes light areas lighter and dark areas darker, while lower contrast makes the image appear more "washed out" or flat.

For Beginners: Think of contrast like the difference between a sunny day (high contrast with bright lights and dark shadows) and a foggy day (low contrast where everything looks similar in brightness). This teaches your model to recognize objects in both crisp and hazy conditions.

When to use:

  • Images from cameras with different quality or settings
  • Scenes with varying lighting conditions
  • Data from different sources with different post-processing

When NOT to use:

  • Tasks where pixel intensity relationships are critical
  • Medical imaging where contrast carries diagnostic information
  • Already preprocessed images with standardized contrast

Constructors

Contrast(double, double, double)

Creates a new contrast augmentation.

public Contrast(double minFactor = 0.8, double maxFactor = 1.2, double probability = 0.5)

Parameters

minFactor double

The minimum contrast factor. Values below 1.0 reduce contrast. Industry standard default is 0.8 (20% reduction at minimum).

maxFactor double

The maximum contrast factor. Values above 1.0 increase contrast. Industry standard default is 1.2 (20% increase at maximum).

probability double

The probability of applying this augmentation (0.0 to 1.0). Industry standard default is 0.5.

Remarks

For Beginners: The factor range of 0.8 to 1.2 creates natural-looking variations. Factor of 0.0 would make all pixels the same gray, while very high factors (like 3.0) would create harsh, high-contrast images.

Properties

MaxFactor

Gets the maximum contrast adjustment factor.

public double MaxFactor { get; }

Property Value

double

Remarks

Values greater than 1.0 increase contrast.

MinFactor

Gets the minimum contrast adjustment factor.

public double MinFactor { get; }

Property Value

double

Remarks

A factor of 1.0 means no change. Values less than 1.0 reduce contrast.

Methods

ApplyAugmentation(ImageTensor<T>, AugmentationContext<T>)

Applies the contrast adjustment to the image.

protected override ImageTensor<T> ApplyAugmentation(ImageTensor<T> data, AugmentationContext<T> context)

Parameters

data ImageTensor<T>
context AugmentationContext<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.