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, the pixel itself taking the weight at ConvolutionOptions.Anchor. Sums are computed in double precision at the storage precision of the image (16-bit pixel formats are filtered with 16-bit precision), divided by ConvolutionOptions.Divisor, plus ConvolutionOptions.Bias for the colors, rounded to nearest with ties upward and clamped to the sample range: the result of SVG's feConvolveMatrix, sum / divisor + bias.
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 |
|---|---|
| Anchor | Gets the weight of ConvolutionOptions.Kernel applied to the pixel being computed, as a column and a row of the matrix: the weight at column x and row y reads the pixel x - Anchor.X columns to the right and y - Anchor.Y rows below. Defaults to null: the column Width / 2 and the row Height / 2, rounded down (the middle weight of odd dimensions, and the default of SVG's targetX and targetY and of OpenCV's anchor for even ones). |
| 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. |
| Divisor | Gets the number every sum is divided by, before ConvolutionOptions.Bias is added: each weight of the matrix is divided by it. Defaults to 1. Set it to the sum of the weights to keep the overall brightness with a matrix of integer weights, as the divisor of SVG's feConvolveMatrix. Alpha is divided too. |
| 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. |
Anchor
ConvolutionOptions.csGets the weight of ConvolutionOptions.Kernel applied to the pixel being computed, as a column and a row of the matrix: the weight at column x and row y reads the pixel x - Anchor.X columns to the right and y - Anchor.Y rows below. Defaults to null: the column Width / 2 and the row Height / 2, rounded down (the middle weight of odd dimensions, and the default of SVG's targetX and targetY and of OpenCV's anchor for even ones).
public Point? Anchor { get; init; }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; }Divisor
ConvolutionOptions.csGets the number every sum is divided by, before ConvolutionOptions.Bias is added: each weight of the matrix is divided by it. Defaults to 1. Set it to the sum of the weights to keep the overall brightness with a matrix of integer weights, as the divisor of SVG's feConvolveMatrix. Alpha is divided too.
public double Divisor { 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.