3
$\begingroup$

I'd like to know what the parameters for the two-dimensional gaussian distributions are, which create this (I think) quite common image-processing filter: $$ h_\sigma(x,y)= \left[ \matrix { 1&2&1\\ 2&4&2\\ 1&2&1 } \right] $$ The two-dimensional gaussian equation looks like: $h_\sigma(x,y)= A\cdot e^{-\frac{x^2+y^2}{2\sigma^2}}$, where $A = \frac{1}{{2\pi}\sigma^2}$, but I think $A$ is not important as it is only a factor, isn't it?

With $\sigma=1$ I get: $$h_{\sigma=1}(x,y)= \left[ \matrix { h(-1,-1)=0.3679&h(0,-1)=0.6065&h(1,-1)=0.3679\\ h(-1,0)=0.6065&h(0,0)=1.0&h(1,0)=0.6065\\ h(-1,1)=0.3679&h(0,1)=0.6065&h(1,1)=0.3679 } \right] $$ As you see, I think the entries in the filter-matrix correspond to sampling values of the gaussian function from [-1|-1] to [1|1]. I hope that is at least right.

Multiplied $h_{\sigma=1}(x,y)$ with $4$, and then rounded gives me my desired filter, but I don't think that is the correct way, is it?

$$\mbox{round}(4\cdot h_{\sigma=1}(x,y))= \mbox{round}(4\cdot \left[ \matrix { 0.3679&0.6065&0.3679\\ 0.6065&1.0&0.6065\\ 0.3679&0.6065&0.3679 } \right] )= $$ $$ h_{\sigma=1}(x,y)= \mbox{round}( \left[ \matrix { 1.4716&2.4260&1.4716\\ 2.4260&4.0&2.4260\\ 1.4716&2.4260&1.4716 } \right] )= $$ $$ \left[ \matrix { 1&2&1\\ 2&4&2\\ 1&2&1 } \right] =h_\sigma(x,y) $$

There must be a better solution, or mathematical explanation for creating that matrix? I especially dislike the rounding operation, as the values are all close to $.5$ and not to $.0$ which should results in a huge error...

My question in other words: How do I determine the filter from scratch...

$\endgroup$
2
  • $\begingroup$ I don't know of any explanation other than "it's kind of like a Gaussian", but that would be even more true if there were a "3" in the center rather than the "4". I don't think you're going to get a particularly good Gaussian approximation with integers. Does en.wikipedia.org/wiki/… or dsp.stackexchange.com/questions/2255/… help? $\endgroup$ Jun 10, 2013 at 13:39
  • $\begingroup$ Actually, it's not a very good Gaussian. You would typically want a discrete kernel of size about $\lfloor 6 \sigma + 1 \rfloor$. So to get away with just 3x3 you need $\sigma < 0.583$. That gives you a 3x3 kernel with a center about 19x greater than the corners. $\endgroup$ Jun 10, 2013 at 14:13

1 Answer 1

5
$\begingroup$

The filter you referenced is known as a Binomial filter. It is an approximation to a Gaussian, but for smaller filters it's a very crude one. The design is oriented more toward efficiency than accuracy. Rather than sampling a Gaussian directly, the idea behind the approximation is based on the Central Limit Theorem. In this case, it means that a small moving average filter $[ 1 \space 1 ]$ convolved with itself over and over will become more and more Gaussian. It also happens to yield the rows of Pascal's Triangle. The coefficients for larger filters are given by the following formula:

$$ {N \choose k} = \frac{N!}{(N - n)!\space N!}. $$

For example, for $N = 5$, taking the outer product of the corresponding row of Pascal's triangle with itself yields

$$ \begin{bmatrix} 1 \\ 4 \\ 6 \\ 4 \\ 1 \end{bmatrix}\begin{bmatrix} 1 & 4 & 6 & 4 & 1 \end{bmatrix} = \begin{bmatrix} 1 & 4 & 6 & 4 & 1 \\ 4 & 16 & 24 & 16 & 4 \\ 6 & 24 & 36 & 24 & 6 \\ 4 & 16 & 24 & 16 & 4 \\ 1 & 4 & 6 & 4 & 1 \end{bmatrix}. $$

The paper I referenced in the first link has the following diagram which shows how the quality of the approximation increases with increasing filter order: enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.