C# Класс AForge.Imaging.Filters.Convolution

Convolution filter.

The filter implements convolution operator, which calculates each pixel of the result image as weighted sum of the correspond pixel and its neighbors in the source image. The weights are set by convolution kernel. The weighted sum is divided by Divisor before putting it into result image and also may be thresholded using Threshold value.

Convolution is a simple mathematical operation which is fundamental to many common image processing filters. Depending on the type of provided kernel, the filter may produce different results, like blur image, sharpen it, find edges, etc.

The filter accepts 8 and 16 bpp grayscale images and 24, 32, 48 and 64 bpp color images for processing. Note: depending on the value of ProcessAlpha property, the alpha channel is either copied as is or processed with the kernel.

Sample usage:

// define emboss kernel int[,] kernel = { { -2, -1, 0 }, { -1, 1, 1 }, { 0, 1, 2 } }; // create filter Convolution filter = new Convolution( kernel ); // apply the filter filter.ApplyInPlace( image );

Initial image:

Result image:

Наследование: BaseUsingCopyPartialFilter
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
Convolution ( int kernel ) : System

Initializes a new instance of the Convolution class.

Using this constructor (specifying only convolution kernel), division factor will be calculated automatically summing all kernel values. In the case if kernel's sum equals to zero, division factor will be assigned to 1.

Convolution ( int kernel, int divisor ) : System

Initializes a new instance of the Convolution class.

Защищенные методы

Метод Описание
Convolution ( ) : System

Initializes a new instance of the Convolution class.

ProcessFilter ( UnmanagedImage source, UnmanagedImage destination, Rectangle rect ) : void

Process the filter on the specified image.

Приватные методы

Метод Описание
Process16bppImage ( ushort baseSrc, ushort baseDst, int srcStride, int dstStride, int startX, int startY, int stopX, int stopY ) : void
Process24bppImage ( byte src, byte dst, int srcStride, int dstStride, int srcOffset, int dstOffset, int startX, int startY, int stopX, int stopY, int pixelSize ) : void
Process32bppImage ( byte src, byte dst, int srcStride, int dstStride, int srcOffset, int dstOffset, int startX, int startY, int stopX, int stopY ) : void
Process48bppImage ( ushort baseSrc, ushort baseDst, int srcStride, int dstStride, int startX, int startY, int stopX, int stopY, int pixelSize ) : void
Process64bppImage ( ushort baseSrc, ushort baseDst, int srcStride, int dstStride, int startX, int startY, int stopX, int stopY ) : void
Process8bppImage ( byte src, byte dst, int srcStride, int dstStride, int srcOffset, int dstOffset, int startX, int startY, int stopX, int stopY ) : void

Описание методов

Convolution() защищенный метод

Initializes a new instance of the Convolution class.
protected Convolution ( ) : System
Результат System

Convolution() публичный метод

Initializes a new instance of the Convolution class.

Using this constructor (specifying only convolution kernel), division factor will be calculated automatically summing all kernel values. In the case if kernel's sum equals to zero, division factor will be assigned to 1.

Invalid kernel size is specified. Kernel must be /// square, its width/height should be odd and should be in the [3, 25] range.
public Convolution ( int kernel ) : System
kernel int Convolution kernel.
Результат System

Convolution() публичный метод

Initializes a new instance of the Convolution class.
Invalid kernel size is specified. Kernel must be /// square, its width/height should be odd and should be in the [3, 25] range. Divisor can not be equal to zero.
public Convolution ( int kernel, int divisor ) : System
kernel int Convolution kernel.
divisor int Divisor, used used to divide weighted sum.
Результат System

ProcessFilter() защищенный метод

Process the filter on the specified image.
protected ProcessFilter ( UnmanagedImage source, UnmanagedImage destination, Rectangle rect ) : void
source UnmanagedImage Source image data.
destination UnmanagedImage Destination image data.
rect System.Drawing.Rectangle Image rectangle for processing by the filter.
Результат void