ConvolutionOptions Class

Immutable options for ImageProcessingExtensions.Convolve.

public sealed class ConvolutionOptions

Remarks

Every sample of a pixel is replaced by the weighted sum of the same sample of its neighbors, with the weights of ConvolutionOptions.Kernel. Sums are computed in double precision at the storage precision of the image (16-bit pixel formats are filtered with 16-bit precision), plus ConvolutionOptions.Bias for the colors, rounded to nearest with ties upward and clamped to the sample range.

By default the filter is alpha-aware: colors are premultiplied by alpha while filtering and unpremultiplied afterward, alpha is filtered like the colors, and pixels whose resulting alpha is zero become transparent black. A kernel whose weights add up to zero (edge detection) therefore makes every pixel transparent: set ConvolutionOptions.PreserveAlpha for such kernels.

Constructors

NameDescription
ConvolutionOptions(ConvolutionKernel)Initializes a new instance of the ConvolutionOptions class.

ConvolutionOptions(ConvolutionKernel)

ConvolutionOptions.cs

Initializes a new instance of the ConvolutionOptions class.

public ConvolutionOptions(ConvolutionKernel kernel)

Parameters

kernel ConvolutionKernel
The convolution matrix.

Exceptions

ArgumentNullException
kernel is null.

Properties

NameDescription
BiasGets the value added to every color sum before it is rounded, a fraction of the range of a color: 0.5 adds half of the maximum sample (128 of 255 after rounding, 0.5 for floating-point samples, half the light in ConvolutionWorkingSpace.LinearSrgb). Defaults to 0. It shows the negative sums of a matrix whose weights add up to zero (edge detection, embossing) instead of clamping them to 0: flat areas become mid-gray. Alpha never gets it; with the alpha-aware filter, it is added to the colors once they are divided by the filtered alpha.
EdgeModeGets the pixels read outside the image. Defaults to ConvolutionEdgeMode.Clamp.
KernelGets the convolution matrix.
PreserveAlphaGets a value indicating whether alpha is kept unchanged. Defaults to false: colors are filtered premultiplied by alpha and alpha is filtered too. When true, colors are filtered as stored (the hidden colors of transparent pixels contribute) and the alpha of every pixel is left untouched. It has no effect on pixel formats without alpha.
WorkingSpaceGets the numeric space used for filtering. Defaults to ConvolutionWorkingSpace.Encoded.

Gets the value added to every color sum before it is rounded, a fraction of the range of a color: 0.5 adds half of the maximum sample (128 of 255 after rounding, 0.5 for floating-point samples, half the light in ConvolutionWorkingSpace.LinearSrgb). Defaults to 0. It shows the negative sums of a matrix whose weights add up to zero (edge detection, embossing) instead of clamping them to 0: flat areas become mid-gray. Alpha never gets it; with the alpha-aware filter, it is added to the colors once they are divided by the filtered alpha.

public double Bias { get; init; }

Property value

double

Exceptions

ArgumentException
The value is not a finite number.

Gets the pixels read outside the image. Defaults to ConvolutionEdgeMode.Clamp.

public ConvolutionEdgeMode EdgeMode { get; init; }

Property value

ConvolutionEdgeMode

Exceptions

ArgumentOutOfRangeException
The value is not a defined ConvolutionEdgeMode.

Gets the convolution matrix.

public ConvolutionKernel Kernel { get; }

Property value

ConvolutionKernel

Gets a value indicating whether alpha is kept unchanged. Defaults to false: colors are filtered premultiplied by alpha and alpha is filtered too. When true, colors are filtered as stored (the hidden colors of transparent pixels contribute) and the alpha of every pixel is left untouched. It has no effect on pixel formats without alpha.

public bool PreserveAlpha { get; init; }

Property value

bool

Gets the numeric space used for filtering. Defaults to ConvolutionWorkingSpace.Encoded.

public ConvolutionWorkingSpace WorkingSpace { get; init; }

Property value

ConvolutionWorkingSpace

Exceptions

ArgumentOutOfRangeException
The value is not a defined ConvolutionWorkingSpace.