I have been reading this http://homepages.inf.ed.ac.uk/rbf/HIPR2/gsmooth.htm and I am having trouble to perform the seperability.

So I kinda did it in paper. Lets say y Gaussian function is G(X,Y), then seperating them will become G(X)G(Y), and then I will need to calculate the 1D component for X and 1D component for Y. Then I can pass over my image twice using the two components each time.

I do have a couple of questions though (one of them is more general):

1 - When I calculate the 2D Gaussian why do I need to normalize it by dividing each pixel of the template with the sum of the template?

2 - Do I need to do the same for the 1D components aswell?

3 - In the link it says:

Figure 4 shows the 1-D x component kernel that would be used to produce the full kernel shown in Figure 3 (after scaling by 273, rounding and truncating one row of pixels around the boundary because they mostly have the value 0. This reduces the 7x7 matrix to the 5x5 shown above.). The y component is exactly the same but is oriented vertically.

Why scale the 1D component by 273? 273 is the sum of the 2D template not the 1D. And how does he truncate 1 row? The 1D X component is 1 row by itself...

Thanks I hope my questions make sense.

  1. Normalization is not "required". It only serves to have scale-consistent results, which a not so useful for visualization, but mostly for measurements: if the Gaussian kernel is "sum normalized", the result of the filtering of a constant image is the same constant image. Constant images are "invariant" for smoothing.
  2. You need (or not) to do that for exactly the same reason as above. As it is separable, you can, if you want, normalize first on the 1D sum on the rows, second on the sum onn the columns.
  3. They do not scale the 1D component: the 1D kernel g1d7 $[ 0.006 , 0.061 ,0.242 , 0.383 , 0.242 , 0.061 , 0.006]$ has almost $1$ average. They do a tensor product of $x$ ($x'. x$) to build a $7\times 7$ kernel, and only keep the center kernel with $273$ normalization.

So, here is, in pseudo-code with Matlab syntax, a sequence of operations that leads to the $5\times 5$ array g2d5ci from Figure 3.

% 1D 7-tap Gaussian kernel
g1d7 = [0.006,0.061,.242,.383,.242,.061,0.006]';

% 2D 7-tap Gaussian kernel, normalized to 1
g2d7 = g1d7*g1d7';g2d7 =g2d7/sum(g2d7(:));

% 2D 5-tap Gaussian kernel cropped from the central 5x5 part of g2d7, normalized to 1
g2d5c = g2d7(2:6,2:6);g2d5c =g2d5c/sum(g2d5c(:));

% 2D 5-tap Gaussian kernel with integer values
g2d5ci = round(273*g2d5c);

The 1D kernel is not obtained by sampling the Gaussian, but by integrating it over sub-intervals. For instance, instead of computing $g(x) = \frac{1}{\sqrt{2\pi}\sigma}\exp\left({-\frac{x^2}{2\sigma^2}}\right)$ at $t=3$, you integrate it over the interval $[-3.5,-2.5]$.

The result is in the following figure (pretty close, isn't?):Gaussian kernel discretization via integration

The Matlab code goes like this:

increment = 0.001;sigma = 1;
time = [-3.5+increment/2:increment:3.5-increment/2]';
data = exp(-0.5*(time/sigma).^2)/(sigma*sqrt(2*pi));
data7 = reshape(data,length(data)/7,7);
data7p = sum(data7)';
data7p = data7p/sum(data7p);

figure(1);clf;hold on
legend('Gaussian kernel','Given values','Recomputed values')
axis tight
  • $\begingroup$ The 1D component values are calculated by G(X) for x right? that is (e^(-x^2/2s^2))2*pi*s^2 where s is the gaussian deviation? for x = 0 I am getting different result than 0.3830... What am I doing wrong? $\endgroup$ – user15860 Mar 4 '16 at 23:34
  • $\begingroup$ also, sorry for the questions, what do you mean by "only keep the center kernel with 273 normalization"? $\endgroup$ – user15860 Mar 4 '16 at 23:36
  • $\begingroup$ I have the derivation starting from the 1D kernel. $\endgroup$ – Laurent Duval Mar 5 '16 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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