ConvolutionOptions Class
Immutable options for ImageProcessingExtensions.Convolve.
public sealed class ConvolutionOptionsRemarks
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
| Name | Description |
|---|---|
| ConvolutionOptions(ConvolutionKernel) | Initializes a new instance of the ConvolutionOptions class. |
ConvolutionOptions(ConvolutionKernel)
ConvolutionOptions.csInitializes a new instance of the ConvolutionOptions class.
public ConvolutionOptions(ConvolutionKernel kernel)Parameters
kernelConvolutionKernel- The convolution matrix.
Exceptions
ArgumentNullExceptionkernelisnull.
Properties
| Name | Description |
|---|---|
| Bias | 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. |
| EdgeMode | Gets the pixels read outside the image. Defaults to ConvolutionEdgeMode.Clamp. |
| Kernel | Gets the convolution matrix. |
| PreserveAlpha | 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. |
| WorkingSpace | Gets 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; }EdgeMode
ConvolutionOptions.csGets the pixels read outside the image. Defaults to ConvolutionEdgeMode.Clamp.
public ConvolutionEdgeMode EdgeMode { get; init; }Kernel
ConvolutionOptions.csPreserveAlpha
ConvolutionOptions.csGets 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
WorkingSpace
ConvolutionOptions.csGets the numeric space used for filtering. Defaults to ConvolutionWorkingSpace.Encoded.
public ConvolutionWorkingSpace WorkingSpace { get; init; }Property value
Exceptions
ArgumentOutOfRangeException- The value is not a defined
ConvolutionWorkingSpace.