Gaussian Blur Filters

Gaussian Blur Kernel Filter in Python

         The Blur Box image filters use pixel values averaging based on a uniform distribution, the alternative approach employs a pixel-wise average within a specified neighborhood. In contrast to a Blur Box, the Gaussian blur leverages a Gaussian distribution, intricately assigning weights to pixels based on their proximity to the center. This results in a more refined and natural blurring effect, as pixels nearer to the center carry higher weights. The following 5x5 matrix can be used for the Gaussian approximation:

# gaussian blur 5x5 kernel
[
 [1, 4,  6,  4,  1],
 [4, 16, 24, 16, 4],
 [6, 24, 36, 24, 6],
 [4, 16, 24, 16, 4],
 [1, 4,  6,  4,  1],
]

         To maintain the luminosity of the source image, it is imperative to divide all elements by 256, representing the sum of the matrix elements.

Gaussian blur, in contrast to the uniform blurring observed in typical blur filters, tends to yield a visually more appealing and realistic result.

Original image
Gaussian blur
Original vector image
Gaussian blur 5x5 kernel filter in Python
Gaussian blur kernel filter

Python code example

         The provided Python code example serves as an illustration of the Aspose.Imaging Python API's usage. Utilize the `ConvolutionFilter` class, which provides pre-defined kernel filters, including the get_gaussian() method with customizable size and sigma values for Gaussian distribution. Moreover, you retain the flexibility to craft your personalized kernel matrix. Within this example, image templates in raster PNG and as well as vector SVG formats are loaded from the "templates" folder, and a set of filters are applied from the `kernel_filters` list.