## Kernel

The kernel is a small mask used to apply filters to an image. These masks have the shape of a square matrix, which is why they are also called convolution matrices.

Let’s consider matrix A, which represents the matrix containing the grey values ​​of all the pixels in the original image, and matrix B representing the kernel matrix. Now let’s superimpose matrix B to matrix A, so that the centre of matrix B corresponds to the pixel of matrix A to be processed.

The value of the target image (matrix C) is calculated as the sum of all the elements of the matrix resulting from the Hadamard product between matrices A and B.

Example:

By applying a 3x3 blur filter

 1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9

we can obtain this result:

Sample image
Blurred sample image

Particularly useful kernels are derivative filters. Let’s analyse two Sobel filters:

 1 0 -1 2 0 -2 1 0 -1
 1 2 1 0 0 0 -1 -2 -1

These two filters represent, respectively, the derivatives (gradients) along abscissas Gx and along ordinates Gy of the image. If one calculates an additional matrix that represents the gradient module:

sqrt(G_x^2+G_y^2)
Sample image
Derivative of the sample image

Clearly, this process represents the preliminary step to extract the edges of the image.

Next →