I was working with Gaussian kernels recently. Exactly what a Gaussian kernel is, is probably best explained with an example. Here is one:

0.0030 0.0133 0.0219 0.0133 0.0030
0.0133 0.0596 0.0983 0.0596 0.0133
0.0219 0.0983 0.1621 0.0983 0.0219
0.0133 0.0596 0.0983 0.0596 0.0133
0.0030 0.0133 0.0219 0.0133 0.0030

This is a 5 x 5 Gaussian kernel. (There are other types of kernels in addition to Gaussian kernels). Notice the value in the center, 0.1621, is largest, and the values get smaller as you move away from the center, and the values are radially symmetric. The spread of the values is determined by a specified standards deviation; here I used 1.0. The values in a Gaussian kernel correspond to the Gaussian function. It’s not immediately obvious, but the values in the kernel sum to 1.0, subject to rounding error.

If you haven’t seen a Gaussian kernel before, your reaction is probably something along the lines of, “What are kernels good for anyway?” As it turns out, Gaussian kernels are used by many algorithms, especially those that work with images.

I wanted to graph a Gaussian kernel. In 2-D, the Gaussian function when graphed is the famous bell-shaped curve. In 3-D you get the image below. Note that the terms 2-D and 3-D are a bit confusing: for a Gaussian function of one variable (“1-D” so to speak), you graph in 2-D. And for a Gaussian function of two variables, you graph in 3-D.

To create this graph I used SciLab, which is a free program that is similar to the very expensive MatLab. Here are the five commands I issued:

-->[x,y]=meshgrid(-2.8:.15:2.8, -2.8:.15:2.8);
-->z=exp(-(x.^2+y.^2)/2);
-->g=scf();
-->g.color_map=jetcolormap(64);
-->surf(x,y,z);

The first command sets up a matrix of (x,y) values from -2.8 to +2.8, 0.15 units apart. The second command is the definition of the Gaussian function of two variables. Note the use of the .^ operator rather than the ^ operator. The third through fifth commands create the graph.

### Like this:

Like Loading...

*Related*

Hi James, thanks for sharing this one!

Here’s our implementation: http://ilnumerics.net/ilcc.php?ilc=i93ca0b

You can also download an executable file to your local machine π