# How to discretize and normalize an $n*n$ Gaussian kernel?

A 3x3 Gaussian kernel is usually shown as

$$\frac{1}{16} \begin{bmatrix}1 & 2 & 1\\ 2 & 4 & 2\\ 1 & 2 & 1\end{bmatrix}$$

But where does that actually come from?

• "usually"? By whom? Also the title does not match the body of the question, since the body is only about the $3\times3$ kernel. – Rahul Apr 19 at 16:35
• It doesn't take long to do a google search to confirm this is usually how it's represented - google.com/search?q=3x3+gaussian+kernel&tbm=isch This is pretty commonly written out without really an explanation on how this number was 'achieved'. This post tries to explain that and not just show magical numbers to someone learning it. – Amir Omidi Apr 19 at 17:00
• The body is about a $3*3$ kernel, but this applies for any n sized kernel using the pascal approximation. – Amir Omidi Apr 19 at 17:01
• It's unfortunate that there are many people who put incorrect images on the internet. The correct way to parametrize a Gaussian kernel is not by its size but by its standard deviation $\sigma$; the 2D array it is discretized into is then truncated at about $3\sigma$ to keep the computational cost finite. – Rahul Apr 19 at 18:13

$$\frac{1}{4} \begin{bmatrix}1\\ 2\\ 1\end{bmatrix} \circ \frac{1}{4} \begin{bmatrix}1 & 2 & 1\\ 1 & 2 & 1\\ 1 & 2 & 1\end{bmatrix} = \frac{1}{16} \begin{bmatrix}1 & 2 & 1\\ 2 & 4 & 2\\ 1 & 2 & 1\end{bmatrix}$$
The value of $$\frac{1}{4}$$ is actually just one over the sum of the pascal row.
This approximation can apply to any $$n * n$$ kernel, and will give a discretized and normalized matrix.