Edge Detection Filters

Edge Detection Custom Kernel Filter in Python

         Crafting a custom kernel filter for edge detection echoes the characteristics of the Sharpen filter, albeit with a distinctive point: the sum of matrix elements totals zero. Consequently, the resulting image takes on an almost entirely black appearance, punctuated only by pixels deviating from their surroundings. These exceptional pixels typically mark the boundaries between diverse areas or edges.

         In this illustrative scenario, the central pixel's value is compared to its neighboring pixels. You have the flexibility to define a custom kernel, finely tuned to identify edges either horizontally, vertically or both.

# edge detection custom kernel
[
    [  0, -1,  0,],
    [ -1,  4, -1,],
    [  0, -1,  0,],
]

         In the end, the application of the filter culminates in preserving only the contours of the image set on a black background.

Original image
Edge detection
Original vector image
Edge detection 3x3 custom kernel filter in Python
Edge detection kernel filter

Python code example

         The provided Python code example showcases the utilization of the Aspose.Imaging Python API. Utilize the `ConvolutionFilter` class, which provides pre-defined kernel filters, alongside the option to incorporate a `custom_kernel` matrix. In this instance, image templates in raster PNG and as well as vector SVG formats are loaded from the "templates" folder, and a range of filters are applied from a predefined list.