AutoCropOptions Class

public sealed class AutoCropOptions

Remarks

The background is the most frequent color of the one-pixel outer border of the image. A border exists when the border has fewer than AutoCropOptions.ColorThreshold distinct colors, or when AutoCropOptions.BucketThreshold is set and at least that share of the border pixels is as bright as the background. The content is then the bounding box of the pixels that differ from the background by more than AutoCropOptions.ColorThreshold.

Thresholds are expressed on the 8-bit scale whatever the pixel format; comparisons are made at the storage precision (a threshold of 35 is 35 * 257 for 16-bit samples).

Constructors

NameDescription
AutoCropOptions()

AutoCropOptions()

AutoCropOptions.cs
public AutoCropOptions()

No documentation is available.

Properties

NameDescription
AnalyzeWeightsGets a value indicating whether the analysis also computes AutoCropAnalysis.WeightX and AutoCropAnalysis.WeightY, which shift the padded rectangle toward the visually heavier side of the image by padding * weight pixels (truncated, with the weight clamped to [-1, 1], so the content always stays inside the padded rectangle). Defaults to false. It needs one more pass over the pixels.
BucketThresholdGets the minimum share of the border pixels, from 0 to 1, whose luma falls in the same of 11 equal luma buckets as the background color, for the border to be accepted even when it has AutoCropOptions.ColorThreshold distinct colors or more (noisy or compressed backgrounds). Defaults to null: only the number of distinct colors decides. It is not used by the retry.
ColorThresholdGets the color threshold, from 1 to 255 on the 8-bit scale. Defaults to 35. It is both the tolerance of the background test (a pixel is background when its luma-weighted difference from the background color, 0.2126 |dR| + 0.7152 |dG| + 0.0722 |dB|, is at most the threshold and its alpha difference is below the threshold) and the number of distinct border colors (after reduction to 8 bits) from which the border is no longer considered uniform. When no border is found, the detection is retried once with half the threshold (rounded up) on the image without its outer 5% on each side.
DefaultGets the default options: no padding, a color threshold of 35, no bucket threshold, AutoCropPaddingMode.Expand, no weight analysis.
PaddingModeGets what happens when the padding reaches outside the canvas. Defaults to AutoCropPaddingMode.Expand.
PaddingXGets the padding kept on the left and on the right of the content, in pixels. Defaults to 0.
PaddingYGets the padding kept above and below the content, in pixels. Defaults to 0.

AnalyzeWeights

AutoCropOptions.cs

Gets a value indicating whether the analysis also computes AutoCropAnalysis.WeightX and AutoCropAnalysis.WeightY, which shift the padded rectangle toward the visually heavier side of the image by padding * weight pixels (truncated, with the weight clamped to [-1, 1], so the content always stays inside the padded rectangle). Defaults to false. It needs one more pass over the pixels.

public bool AnalyzeWeights { get; init; }

Property value

bool

BucketThreshold

AutoCropOptions.cs

Gets the minimum share of the border pixels, from 0 to 1, whose luma falls in the same of 11 equal luma buckets as the background color, for the border to be accepted even when it has AutoCropOptions.ColorThreshold distinct colors or more (noisy or compressed backgrounds). Defaults to null: only the number of distinct colors decides. It is not used by the retry.

public double? BucketThreshold { get; init; }

Property value

double?

Exceptions

ArgumentOutOfRangeException
The value is not between 0 and 1.

ColorThreshold

AutoCropOptions.cs

Gets the color threshold, from 1 to 255 on the 8-bit scale. Defaults to 35. It is both the tolerance of the background test (a pixel is background when its luma-weighted difference from the background color, 0.2126 |dR| + 0.7152 |dG| + 0.0722 |dB|, is at most the threshold and its alpha difference is below the threshold) and the number of distinct border colors (after reduction to 8 bits) from which the border is no longer considered uniform. When no border is found, the detection is retried once with half the threshold (rounded up) on the image without its outer 5% on each side.

public int ColorThreshold { get; init; }

Property value

int

Exceptions

ArgumentOutOfRangeException
The value is not between 1 and 255.

Gets the default options: no padding, a color threshold of 35, no bucket threshold, AutoCropPaddingMode.Expand, no weight analysis.

public static AutoCropOptions Default { get; }

Property value

AutoCropOptions

Gets what happens when the padding reaches outside the canvas. Defaults to AutoCropPaddingMode.Expand.

public AutoCropPaddingMode PaddingMode { get; init; }

Property value

AutoCropPaddingMode

Exceptions

ArgumentOutOfRangeException
The value is not a defined AutoCropPaddingMode.

Gets the padding kept on the left and on the right of the content, in pixels. Defaults to 0.

public int PaddingX { get; init; }

Property value

int

Exceptions

ArgumentOutOfRangeException
The value is negative.

Gets the padding kept above and below the content, in pixels. Defaults to 0.

public int PaddingY { get; init; }

Property value

int

Exceptions

ArgumentOutOfRangeException
The value is negative.