0
votes

I read now tons of different explanations of the gaussian blur and I am really confused.

I roughly understand how the gaussian blur works. http://en.wikipedia.org/wiki/Gaussian_blur

I understood that we choose 3*sigma as the maxium size for our mask because the values will get really small.

But my three questions are:

  1. How do I create a gaussian mask with the sigma only?

  2. If I understood it correctly, the mask gives me the weights, then I place the mask on the top left pixel. I multiply the weights for each value of the pixels in the mask. Then I move the mask to the next pixel. I do this for all pixels. Is this correct?

  3. I also know that 1D masks are faster. So I create a mask for x and a mask for y. Lets say my mask would look like this. (3x3)

1 2 1

2 4 2

1 2 1

How would my x and y mask look like?

1
Realize that your 3x3 example is only an approximation.Mark Ransom

1 Answers

2
votes

1- A solution to create a gaussian mask is to setup an N by N matrix, with N=3*sigma (or less if you want a coarser solution), and fill each entry (i,j) with exp(-((i-N/2)^2 + (j-N/2)^2)/(2*sigma^2)). As a comment mentioned, taking N=3*sigma just means that you truncate your gaussian at a "sufficiently small" threshold.

2- yes - you understood correctly. A small detail is that you'll need to normalize by the sum of your weights (ie., divide the result of what you said by the sum of all the elements of your matrix). The other option is that you can build your matrix already normalized, so that you don't need to perform this normalization at the end (the normalized gaussian formula becomes exp(-((i-N/2)^2 + (j-N/2)^2)/(2*sigma^2))/(2*pi*sigma))

3- In your specific case, the 1D version is [1 2 1] (ie, both your x and y masks) since you can obtain the matrix you gave with the multiplication transpose([1 2 1]) * [1 2 1]. In general, you can directly build these 1D gaussians using the 1D gaussian formula which is similar as the one above : exp(-((i-N/2)^2)/(2*sigma^2)) (or the normalized version exp(-((i-N/2)^2)/(2*sigma^2)) / (sigma*sqrt(2*pi)))