ThresholdOptions Class
Immutable options of a binarization (ImageProcessingExtensions.Threshold): how the threshold of each pixel is chosen, and the two colors of the result.
public sealed class ThresholdOptionsRemarks
Every pixel is compared by its luminance: the Rec. 709 luma of its stored (encoded) samples at the storage precision, the value ImageProcessingExtensions.Grayscale stores (a gray pixel is its own luminance). A pixel whose luminance is greater than its threshold gets ThresholdOptions.UpperColor, any other pixel gets ThresholdOptions.LowerColor. The thresholds are on the scale of the samples, from 0 to max, the largest sample value (255 for 8-bit pixel formats, 65,535 for 16-bit ones); the levels of these options are fractions of it.
The windows of the adaptive methods (ThresholdMethod.Mean and ThresholdMethod.Sauvola) are squares of ThresholdOptions.WindowSize pixels centered on each pixel, which read the pixels outside the frame as ThresholdOptions.EdgeMode says. Their sums are exact integers; the means, the deviations and the thresholds are IEEE doubles, so the result is the same on every platform.
Constructors
| Name | Description |
|---|---|
| ThresholdOptions() |
ThresholdOptions()
ThresholdOptions.cspublic ThresholdOptions()No documentation is available.
Properties
| Name | Description |
|---|---|
| Default | Gets the default options: Otsu's method on each frame, which becomes black (below the threshold) and white (above it). |
| EdgeMode | Gets the pixels the windows of the adaptive methods read outside the frame. Defaults to ConvolutionEdgeMode.Mirror. With ConvolutionEdgeMode.Zero, the outside pixels count as black pixels of the window. Ignored by ThresholdMethod.Otsu and ThresholdMethod.Fixed. |
| Level | Gets the threshold of ThresholdMethod.Fixed, a fraction of the sample range: a pixel whose luminance is greater than Level * max gets ThresholdOptions.UpperColor. Defaults to 0.5, which puts the 8-bit levels from 128 up in the upper class. Ignored by the other methods. |
| LowerColor | Gets the color of the pixels whose luminance is not greater than their threshold, alpha included. Defaults to opaque black. The pixel format must store it exactly (see ImageProcessingExtensions.Threshold). |
| Method | Gets how the thresholds are chosen. Defaults to ThresholdMethod.Otsu. |
| Offset | Gets what ThresholdMethod.Mean subtracts from the mean of the window, a fraction of the sample range: the threshold is mean - Offset * max. Defaults to 0. A positive offset keeps the pixels slightly darker than their surroundings, such as the noise of a blank background, in the upper class. Ignored by the other methods. |
| SauvolaK | Gets the sensitivity k of ThresholdMethod.Sauvola, from 0 to 1: the larger it is, the further below the mean the threshold of a window with little contrast falls. Defaults to 0.2. Ignored by the other methods. |
| SauvolaR | Gets the dynamic range R of the standard deviation of ThresholdMethod.Sauvola, a fraction of the sample range: R = SauvolaR * max. Defaults to 0.5 (127.5 for 8-bit samples, the value of the original paper). Ignored by the other methods. |
| ShareHistogramAcrossFrames | Gets a value indicating whether ThresholdMethod.Otsu chooses one threshold from the histogram of every frame of an image and its poster frame together, so that the frames of an animation get the same threshold and do not flicker. Defaults to false: each frame gets the threshold of its own histogram. Ignored when one frame is binarized, and by the other methods. |
| UpperColor | Gets the color of the pixels whose luminance is greater than their threshold, alpha included. Defaults to opaque white. The pixel format must store it exactly (see ImageProcessingExtensions.Threshold). |
| WindowSize | Gets the width and the height, in pixels, of the window of the adaptive methods: an odd number from 3 to 20,001. Defaults to 15. Choose a window larger than the strokes to keep (about twice the height of a line of text, for a document). Ignored by ThresholdMethod.Otsu and ThresholdMethod.Fixed. |
Default
ThresholdOptions.csGets the default options: Otsu's method on each frame, which becomes black (below the threshold) and white (above it).
public static ThresholdOptions Default { get; }Property value
EdgeMode
ThresholdOptions.csGets the pixels the windows of the adaptive methods read outside the frame. Defaults to ConvolutionEdgeMode.Mirror. With ConvolutionEdgeMode.Zero, the outside pixels count as black pixels of the window. Ignored by ThresholdMethod.Otsu and ThresholdMethod.Fixed.
public ConvolutionEdgeMode EdgeMode { get; init; }Level
ThresholdOptions.csGets the threshold of ThresholdMethod.Fixed, a fraction of the sample range: a pixel whose luminance is greater than Level * max gets ThresholdOptions.UpperColor. Defaults to 0.5, which puts the 8-bit levels from 128 up in the upper class. Ignored by the other methods.
public double Level { get; init; }LowerColor
ThresholdOptions.csGets the color of the pixels whose luminance is not greater than their threshold, alpha included. Defaults to opaque black. The pixel format must store it exactly (see ImageProcessingExtensions.Threshold).
public Rgba64 LowerColor { get; init; }Property value
Method
ThresholdOptions.csGets how the thresholds are chosen. Defaults to ThresholdMethod.Otsu.
public ThresholdMethod Method { get; init; }Offset
ThresholdOptions.csGets what ThresholdMethod.Mean subtracts from the mean of the window, a fraction of the sample range: the threshold is mean - Offset * max. Defaults to 0. A positive offset keeps the pixels slightly darker than their surroundings, such as the noise of a blank background, in the upper class. Ignored by the other methods.
public double Offset { get; init; }SauvolaK
ThresholdOptions.csGets the sensitivity k of ThresholdMethod.Sauvola, from 0 to 1: the larger it is, the further below the mean the threshold of a window with little contrast falls. Defaults to 0.2. Ignored by the other methods.
public double SauvolaK { get; init; }SauvolaR
ThresholdOptions.csGets the dynamic range R of the standard deviation of ThresholdMethod.Sauvola, a fraction of the sample range: R = SauvolaR * max. Defaults to 0.5 (127.5 for 8-bit samples, the value of the original paper). Ignored by the other methods.
public double SauvolaR { get; init; }UpperColor
ThresholdOptions.csGets the color of the pixels whose luminance is greater than their threshold, alpha included. Defaults to opaque white. The pixel format must store it exactly (see ImageProcessingExtensions.Threshold).
public Rgba64 UpperColor { get; init; }Property value
WindowSize
ThresholdOptions.csGets the width and the height, in pixels, of the window of the adaptive methods: an odd number from 3 to 20,001. Defaults to 15. Choose a window larger than the strokes to keep (about twice the height of a line of text, for a document). Ignored by ThresholdMethod.Otsu and ThresholdMethod.Fixed.
public int WindowSize { get; init; }Property value
Exceptions
ArgumentOutOfRangeException- The value is even, less than 3 or greater than 20,001.