C# Class Accord.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:

Inheritance: BaseUsingCopyPartialFilter
Afficher le fichier Open project: accord-net/framework Class Usage Examples

Méthodes publiques

Méthode Description
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.

Méthodes protégées

Méthode Description
Convolution ( ) : System

Initializes a new instance of the Convolution class.

ProcessFilter ( UnmanagedImage sourceData, UnmanagedImage destinationData, Rectangle rect ) : void

Process the filter on the specified image.

Private Methods

Méthode Description
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

Method Details

Convolution() protected méthode

Initializes a new instance of the Convolution class.
protected Convolution ( ) : System
Résultat System

Convolution() public méthode

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.
Résultat System

Convolution() public méthode

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.
Résultat System

ProcessFilter() protected méthode

Process the filter on the specified image.
protected ProcessFilter ( UnmanagedImage sourceData, UnmanagedImage destinationData, Rectangle rect ) : void
sourceData UnmanagedImage Source image data.
destinationData UnmanagedImage Destination image data.
rect System.Drawing.Rectangle Image rectangle for processing by the filter.
Résultat void