Introduction

This tutorial is about a unique Filter that comes with most image editing programs such as GIMP or Photoshop, but most users don’t even know where to begin when it comes to using it! While not necessarily restricted to the old school realm, this filter is super easy to customize, and experimenting can produce all kinds of unexpected results. The filter we are going to look at in this tutorial is called the Convolution Matrix.

Convolution Matrix

The Convolution Matrix allows you to ‘create’ your own custom filters by entering values into a grid, or matrix. When using a Convolution Matrix filter, most image editing programs will present you with either a 3×3 or a 5×5 grid where you can enter various numerical values. Typically, by default the grid will be filled with zeroes, which will not affect the image in any way. Some programs offer additional options, like the ability to affect certain RGB channels in an image, or even applying the filter using different blending modes, but the overall output is relatively the same.

Convolution Matrix in GIMP

For the most part, the main difference may be some naming conventions. For example, the Bias value in the first example image has the same effect as the Offset value in the second image, despite having different names. This is a rather fun filter to experiment with, once you’ve gained an idea of what is actually happening when you apply it.

Convolution Matrix

To start using the Convolution Matrix filter in GIMP, select Filters -> Generic -> Convolution Matrix to bring up the filter options window. You should see a grid of numbers, a Divisor value, and an Offset value, followed by some options to select certain RGB channels. The way this Filter works is by looking at each individual pixel in a source image one by one, then applying a mathematical operation to produce a new brightness value for each pixel. The grid itself is usually referred to as the Kernel Matrix. It is here that you can enter certain number values which will have an effect on the image, and these number values are called the Kernel. Let’s begin by attempting to break down exactly what happens when you enter values into the grid.

Example from GIMP Help Page

You can think of your image as a series of pixels arranged in a grid of rows and columns. Looking at the example above, taken directly from the GIMP documentation, the grid on the left represents the Source Image, and each of the numbers is a pixel value in that image. The grid in the center represents the Kernel that will be applied to the image, while the grid on the right represents the final calculated pixel value that is returned and applied to the image. The pixel value from the source image (left) is multiplied by the value from the corresponding square in the Kernel (center) which gives a resulting brightness value (right) The result is then divided by the Divisor and totaled with the Offset value.

We will refer to the value in the red box above as the Evaluated Pixel, and the value from the center grid as the Kernel Value. The green box represents the area that will be affected by the Kernel, and calculations are performed starting from the top left, working over to the right before moving down to the next row of pixels, much like reading a book from line to line.

40 42 46
46 50 55
52 57 58

Source Image

0 1 0
0 0 0
0 0 0

Kernel

If we use the values from the example image above, the value of the Evaluated Pixel (50) in the source image is multiplied by the Kernel Value (0). Subsequently, each of the pixels surrounding the Evaluated Pixel will be multiplied by their corresponding Matrix Values in the Kernel. Wherever there is no value at all, or a value of 0, no operation will be performed at all, and a result of 0 will be returned for that square in the grid.

(40*0) (42*1) (46*0)
(46*0) (50*0) (55*0)
(52*0) (56*0) (58*0)

As the calculations are performed on the values surrounding the Evaluated Pixel using the example Kernel, every result will be 0 except for the upper middle box, where there is a 1. This will give us a value of 42 (42×1=42) in the top row.

0 42 0
0  0
0  0  0

These values are then totaled up, divided by the Divisor value, and then the Offset value is added to the result. If we add up all the values from the example above (0+42+0+0+0+0+0+0+0) the result is 42, which is then divided by the Divisor value of 1. As a final step, the Bias or Offset value is added to the result in order to calculate new brightness values. Presuming our Divisor was set to 1 and the Offset was set to 0, our final result should still be 42. This final result becomes the new pixel value for the Evaluated Pixel at the center of the grid.

0  0  0
0 42 0
0  0  0

In GIMP, if you have the Normalize option selected, the software will do some calculations and attempt to retain the original brightness of the image. Otherwise, you may need to change the Divisor or Offset values to prevent the image from becoming too light. By using this particular Kernel, the source image would be shifted downward by 1 pixel. It would be next to impossible to see the changes in a static example image, so I have prepared a GIF animation to show you what actually happens.

Shifting Down by 1 Pixel

Another small set of handy functions to take note of (if you are using GIMP) are the Flip Matrix and Rotate Matrix buttons. These will do exactly what they say and flip or rotate the positions of all the values you have currently entered into the grid. This makes it easier to test directional effects at different angles, such as gradients, embossing, or motion blurs.

3×3 Kernels

While the math going on behind the scenes may not be simple to explain, it is much more helpful to see examples of different Kernels and how they would affect your final image. We have already looked at a Kernel that can be used to shift an image down by one pixel, so let’s take a look at a list of examples and see what types of operations you can perform with the Convolution Matrix filter, starting with Kernels for a 3×3 matrix. Keep in mind most of these examples also use a Divisor of 1 and Normalize turned on unless otherwise specified, but feel free to change the Divisor or Offset values as well as turning the Normalize setting off to get different results.

  • Shift Up – Shifts the entire image upwards by one pixel; this is the opposite of the example given in the section above. Moving the 1 to any other position around the Central Value will shift the image in that direction.

0  0  0
0  0  0
0  1  0

Shift Up Kernel
  • Box Blur – Produces a standard blur effect, where each pixel is set to be equal to the average of the pixels surrounding it. If Normalize is turned off, set the Divisor value to 9 for this effect. This produces a uniform blur in all directions.

1  1  1
1  1  1
1  1  1

Box Blur Kernel
  • Smooth w/ Blur – A less pronounced blur effect, this can make an image appear smoother without removing too much detail.

0  1  0
1  4  1
0  1  0

Smooth Kernel
  • Sharpen – Increases the detail in an image by using a higher value in the center with lower values around the outside. The -1 values can be shifted around the edge of the Kernel.

0  -1  0
-1  5  -1
0  -1  0

Sharpen Kernel
  • Sharpen (Heavy) – Increases the detail in an image by using a higher value in the center with lower values around the outside. This version produces more pronounced edges.

-1  -2  -1
-2  13  -2
-1  -2  -1

Sharpen (Heavy) Kernel
  • Focus – Similar to sharpen, enhances the detail in the image using lower values around the outside edge. The -1 values can be shifted around the edge of the Kernel.

-1  0  -1
0  7  0
-1  0  -1

Focus Kernel
  • Edge Detect – Used to extract the structure or discontinuities between the light and dark areas of an image. If you are using GIMP, be sure to turn off the Normalize option.

 -1  -1  -1
-1  8  -1
-1  -1  -1

Edge Detect Kernel
  • Edge Detect (Light) – Produces an out of focus image with exaggerated edges.

0  1  0
1 -3  1
0  1  0

Edge Detect (Light) Kernel
  • Edge Detect (Sobel) – An alternate method of edge detection, as well as being applied in an upward direction. The Kernel values can be rotated to change the angle. If you are using GIMP, be sure to turn off the Normalize option. 

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

Edge Detect (Sobel) Kernel
  • Edge Enhance – Similar to Edge Detect, but darkens the image and shows only the lighter edges. The direction of the enhance operation is determined by the position of the -1 value in the grid.

 0  0  0
-1  1  0
 0  0  0

Edge Enhance Kernel
  • Emboss – Produces a raised relief of the source image. The values in the Kernel can be rotated to change the angle of the emboss effect.

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

Emboss Kernel
  • Emboss (Light) – Produces a less intense relief effect. The values in the Kernel can be rotated to change the angle of the emboss effect.

1  0  0
0  1  0
 0  0  -1

Light Emboss Kernel
  • Emboss (Dark) – Produces a darker relief effect. The Divisor value has been set to 6 for this effect. The values in the Kernel can be rotated to change the angle of the emboss effect.

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

Emboss (Dark) Kernel
  • Bump Mask – Useful for producing bump masks for texture work. Set the Offset value to 1 and the Divisor to 0.5 for this effect. This can also be desaturated and converted into a black and white mask.

1  0  0
 0  0  0
0  0  -1

Bump Mask Kernel
  • Negative – Inverts the color in the image completely, producing a negative version of the image.

0  0  0
 0  -1  0
0  0  0

Negative Kernel

There are lots of different techniques and filter types to be discovered simply by experimenting, and it is probably easier to experiment with the 3×3 Kernel grid to start with. Continue reading to learn about using more complex 5×5 Kernels!

5×5 Kernels

In most cases, you can simply use 3×3 Kernels to perform many basic filter operations and image adjustments, but sometimes you may wish to perform more complex operations. By enlarging the Kernel Matrix, operations can be applied to a wider range of pixels in the image allowing for some more complex effects. This is where the 5×5 Kernels come into play! Keep in mind, not every tool with a Convolution Matrix filter has a 5×5 grid, but all the tools mentioned in this tutorial is perfectly capable of using 5×5 Kernels.

  • Gradient Emboss – Shifts the colors of the image using a gradient value range, giving a colorful embossed effect. The gradient direction runs from the negative values to the positive values in the grid, and rotating the values in the grid will rotate the direction of the gradient.

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

Gradient Emboss Kernel
  • Sharpen – Increases the detail and enhances the edges in an image.

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

Sharpen Kernel
  • Radial Blur – Blurs the image in both the horizontal and vertical directions producing a movement effect. This blurs the image in an outward diagonal direction.

9  0  3  0  9
0  0  0  0  0
3  0  1  0  3
0  0  0  0  0
9  0  3  0  9

Radial Blur Kernel
  • Motion Blur – Blurs the image in the direction specified by the position of the values in the grid. Rotate the position of the values to change the angle of the blur.

3  0  0  0  0
0  2  0  0  0
0  0  1  0  0
0  0  0  2  0
0  0  0  0  3

Motion Blur Kernel
  • Emboss – Embosses the image in the direction of the negative values to positive values in the kernel. Rotate the position of the values to change the angle of the emboss.

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

Emboss Kernel

Hopefully this helps you get started with your experiments using Convolution Matrix Filters, even if you only use this as a page to reference different Kernels for your own image editing. While many of these techniques can be found as existing filters in GIMP or Photoshop, the Convolution Matrix Filter allows you to experiment far more, and there are certain things (particular types of embossing, for example) that you cannot do with standard filters. Sometimes the results can have a bit of a grainy appearance, which tends to look great for old school graphics. There are also several Emboss filter types that are incredibly useful for making textures for 3D objects.

*This Tutorial will be expanded over time!