Edge Detection Filters
Edge Detection Custom Kernel Filter
The custom kernel filter for edge detection shares similarities with the Sharpen filter but with a notable distinction: the total sum of matrix elements equals zero. Consequently, the resulting image appears almost black, except for pixels that deviate from their neighbors. These pixels typically reside at the boundaries between distinct areas or edges.
In this example, the central pixel value is compared to its surrounding pixels. It is possible to define a custom kernel to specifically identify edges in either horizontal or vertical directions.
// edge detection kernel
double[,] customKernel = new double[,]
{
{ -1, -1, -1,}
{ -1, 8, -1,},
{ -1, -1, -1,},
}
Ultimately, applying the filter results in retaining only the contours of the image against a black background.
C# code example
The following C# code example illustrates the usage of the Aspose.Imaging .NET API. You can employ the `ConvolutionFilter` class, which offers predefined kernel filters, as well as custom kernel matrix. In this example, image templates in PNG and SVG formats are loaded from the "templates" folder, and filters are applied from a predefined list.