Gaussian Blur Filters

Gaussian Blur Kernel Filter in Java

         Diverging from typical Blur Box image filters, which employ an averaging filter, the simple average applied to pixel values in a defined neighborhood results in a uniform and straightforward blurring effect. In such scenario, each pixel contributes equally to its neighboring pixels.

         In contrast, Gaussian blur utilizes a Gaussian distribution to ascertain the weights of pixels within the neighborhood. This implies that pixels closer to the center hold higher weights, leading to a smoother and more natural blurring effect. To simulate the Gaussian distribution, the following 3x3 matrix can be employed:

// gaussian blur 3x3 kernel matrix
{
  {1, 2, 1,},
  {2, 4, 2,},
  {1, 2, 1,},
};

         To maintain the brightness of the source image, all elements are divided by 16, a value that corresponds to the sum of the matrix elements.

// gaussian blur 3x3 kernel matrix /16
{
  { 0.0625, 0.125,  0.0625,},
  { 0.125,   0.25,   0.125,},
  { 0.0625, 0.125,  0.0625,},
};

         Gaussian blur filter tends to yield a visually appealing and smooth result, surpassing the uniform blurring effect produced by blur box filters.

Original image
Gaussian blur
Original photo image
Gaussian blur kernel filter in Java
Gaussian blur kernel filter

Java code example

         The provided Java code example demonstrates the utilization of the Aspose.Imaging for Java API. Utilize the `ConvolutionFilter` class, which provides pre-defined kernel filters, including the GetGaussian() method with adjustable size and sigma value for the Gauss distribution. Moreover, you retain the flexibility to craft your personalized kernel matrix. Within this example, image templates in PNG and SVG formats are loaded from the "templates" folder, and a set of filters are applied from a predefined list.