The Convolution Effect allows you to produce a range of effects by specifying a set of convolution kernels. A simple explanation is given here but you may wish to refer to other sources for complete descriptions of convolution and how you can use it.

Convolution is a general purpose filter effect for images. It works by determining the value of a central pixel by adding the weighted values of all its neighbors together. The weights applied to each pixel are determined by what is called a convolution kernel.

Syntax

[C#]

static void Convolution(Bitmap bitmap, Kernel[] kernels);

[Visual Basic]

Shared Sub Convolution(bitmap As Bitmap, kernels As Kernel())
Params
Name Description
bitmap The bitmap to process
kernels The kernels to apply. All kernels must have the same Size and Center values.
Notes

None.

Example

[C#]

Effects.Kernel sobel1 = new Effects.Kernel(new Size(3, 3));
sobel1[0, 0] = -1;
sobel1[1, 0] = 0;
sobel1[2, 0] = 1;
sobel1[0, 1] = -2;
sobel1[1, 1] = 0;
sobel1[2, 1] = 2;
sobel1[0, 2] = -1;
sobel1[1, 2] = 0;
sobel1[2, 2] = 1;
Effects.Kernel sobel2 = new Effects.Kernel(new Size(3, 3));
sobel2[0, 0] = 1;
sobel2[1, 0] = 2;
sobel2[2, 0] = 1;
sobel2[0, 1] = 0;
sobel2[1, 1] = 0;
sobel2[2, 1] = 0;
sobel2[0, 2] = -1;
sobel2[1, 2] = -2;
sobel2[2, 2] = -1;
using (Bitmap bm = (Bitmap)Bitmap.FromFile(Server.MapPath("rez/alexander-andrews-vGCErDhrc3E-unsplash.jpg"))) {
  Effects.Convolution(bm, new Effects.Kernel[] { sobel1, sobel2 });
  bm.Save(Server.MapPath("IG8_Effects_Convolution.jpg"));
}


Here we apply a convolution effect - a Sobel Edge Detector. Ouput files are shown below.


alexander-andrews-vGCErDhrc3E-unsplash.jpg


IG8_Effects_Convolution.jpg