AutoLevelsOptions Class

Immutable options of a contrast stretch (ImageProcessingExtensions.AutoLevels).

public sealed class AutoLevelsOptions

Remarks

The stretch finds the low level lo, the smallest level v such that more than AutoLevelsOptions.LowPercentile percent of the counted samples are at most v, and the high level hi, the largest level v such that more than 100 - AutoLevelsOptions.HighPercentile percent of them are at least v. A level v then becomes round((v - lo) * max / (hi - lo)), clamped to the sample range, where max is the largest sample value (255 or 65,535). With the default percentiles, lo and hi are the darkest and the brightest levels present. When hi is not above lo, nothing changes.

The histograms have one bin per sample level: 256 for 8-bit pixel formats, 65,536 for 16-bit ones. Fully transparent pixels are not counted, but they are remapped like the others.

Constructors

NameDescription
AutoLevelsOptions()

AutoLevelsOptions()

AutoLevelsOptions.cs
public AutoLevelsOptions()

No documentation is available.

Properties

NameDescription
ColorModeGets the samples that are stretched. Defaults to HistogramColorMode.Luminance, which keeps the hues; HistogramColorMode.PerChannel stretches each channel from its own levels, which also removes a color cast.
DefaultGets the default options: the luminance of each frame is stretched from its darkest to its brightest level.
HighPercentileGets the percentile of the high level: 100 - HighPercentile percent of the samples may be brighter than it and become the largest sample value. Defaults to 100.
LowPercentileGets the share of the samples, in percent, that may be darker than the low level and become 0. Defaults to 0. It must be less than AutoLevelsOptions.HighPercentile, which the operation checks.
ShareHistogramAcrossFramesGets a value indicating whether every frame of an image, and its poster frame, is stretched with the levels of all of them together, so that the frames of an animation get the same mapping and do not flicker. Defaults to false: each frame is stretched alone. Ignored when one frame is stretched.

Gets the samples that are stretched. Defaults to HistogramColorMode.Luminance, which keeps the hues; HistogramColorMode.PerChannel stretches each channel from its own levels, which also removes a color cast.

public HistogramColorMode ColorMode { get; init; }

Property value

HistogramColorMode

Exceptions

ArgumentOutOfRangeException
The value is not a defined HistogramColorMode.

Gets the default options: the luminance of each frame is stretched from its darkest to its brightest level.

public static AutoLevelsOptions Default { get; }

Property value

AutoLevelsOptions

HighPercentile

AutoLevelsOptions.cs

Gets the percentile of the high level: 100 - HighPercentile percent of the samples may be brighter than it and become the largest sample value. Defaults to 100.

public double HighPercentile { get; init; }

Property value

double

Exceptions

ArgumentOutOfRangeException
The value is not greater than 0 and at most 100.

Gets the share of the samples, in percent, that may be darker than the low level and become 0. Defaults to 0. It must be less than AutoLevelsOptions.HighPercentile, which the operation checks.

public double LowPercentile { get; init; }

Property value

double

Exceptions

ArgumentOutOfRangeException
The value is not at least 0 and less than 100.

ShareHistogramAcrossFrames

AutoLevelsOptions.cs

Gets a value indicating whether every frame of an image, and its poster frame, is stretched with the levels of all of them together, so that the frames of an animation get the same mapping and do not flicker. Defaults to false: each frame is stretched alone. Ignored when one frame is stretched.

public bool ShareHistogramAcrossFrames { get; init; }

Property value

bool