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)
Interface
Instructions
1. Kernal - Edit the 5x5 textbox grid to add in your convolution values OR
2. Dropdown - Select a pre-created filter using the dropdown menu to help you get started
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.
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:
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:
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:
Continue with all other 3x3 blocks in the image using original values. For
example the next image block could be
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:
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.
|