# Convolution Filter

Convolution filters are a great way to process images for certain features. Features are defined by an n by m matrix that is applied to the image in the following way: (grayscale only for purposes of example)

## Instructions

1. Kernel - Edit the 11 x 11 textbox grid to add in your convolution values OR

3. Divisor/Bias - Specify the divisor and/or bias. The result of the kernal above will be divided by the divisor to help keep the pixel within the 0 to 255 range. The bias will be added to the result to also keep it within the positive 0 to 255 range.

4. Import/Export - Import or export the filter settings to a space/newline delimited text file. This can be handy to keep filters that you find useful and/or to bulk edit a particular filter within a text editor.

## Example

 Source Sharpen More

An example small grayscale image (10x10):

 34 22 77 48 237 205 29 212 107 41 50 150 77 158 233 251 112 165 47 229 93 0 77 219 43 56 42 113 140 94 32 19 44 30 36 94 151 101 28 84 10 90 48 73 63 148 159 183 99 22 192 70 27 88 20 230 53 34 38 106 239 202 196 205 50 123 192 88 41 37 230 174 14 22 127 100 189 186 214 187 227 86 195 6 53 168 46 166 36 249 215 165 237 110 125 191 191 94 123 8

An example convolution filter for line detection:

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

The row=2, column=2 pixel and its neighborhood from the image above: The row=2, column=2 pixel and its neighborhood from the image above:

 34 22 77 50 150 77 93 0 77

To apply the convolution filter multiply the filter values with the image data block. Work with each pixel and its 3x3 neighborhood:

 -1*34 -1*22 -1*77 -1*50 8*150 -1*77 -1*93 -1*0 -1*77

Then sum all the values:
(-34)+(-22)+(-77)+
(-50)+(1200)+(-77)+
(-93)+(0)+(-77) = 770

Divide by the divisor and add the bias.
(770/divisor)+bias=770 (in this example divisor=1, bias=0)

If the new pixel value is > 255 set it to 255
If the new pixel value is < 0 set it to 0

The new pixel value is 255. Store that in a new image:

 34 22 77 50 255 77 93 0 77

Continue with all other 3x3 blocks in the image using original values. For example the next image block could be

 22 77 48 150 77 158 0 77 219

Note the 3x3 "window" is shifted to the right by one and that the new pixel value is NOT used but stored as a second new image.

Most of the image is processed in this manner. Image borders create problems and are ignored.

Many other filters can easily be defined for other purposes

Blur:

 1 1 1 1 2 1 1 1 1 2 4 2 1 1 1 1 2 1

Sharpen:

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

Edge Enhancement:

 0 0 0 0 -1 0 -1 0 0 -1 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0

Find Edges:

 0 1 0 -1 -1 -1 1 -2 1 1 -4 1 -1 8 -1 -2 4 -2 0 1 0 -1 -1 -1 1 -2 1

Emboss:

 -2 -1 0 -1 1 1 0 1 2
The convolution matrix is displayed in the convolution interface. Changing any number will alter the matrix and change the image as a result of applying that matrix.

Select a matrix from the pull down menu which will populate the matrix with those values.

 Convolution Related Forum Posts Last post Posts Views None