I am preparing to implement a Gaussian Filter in C#, and in preparation I am reading literature on this. However I have disagreeing sources.
One book (Japanese text: Practical Image Processing Introduction by Uchimura) specifies that the equation to calculate the template is
w(u,v)= (1/2*pi*sigma^2) exp(-(x^2+v^2)/(2*sigma^2)).
I think that is correct, although the author links size and sigma as SIZE = 3*sigma
.
Finally an excellent book (Feature Extraction & Image Processing for Computer Vision by Nixon and Aguado, p.106) gives the correct equation, but when implementing it in code gives a different implementation.
w(u,v)= (1/SUM)* exp(-(x^2+v^2)/(2*sigma^2))
where SUM
is the sum of all values of the exponentials. Below is the pseudo code they provide - I think it is close to MATLAB.
function template=gaussian_template(winsize,sigma)
%Template for Gaussian averaging
%Usage:[template]=gaussian_template(number, number)
%Parameters: winsize-size of template (odd, integer)
% sigma-variance of Gaussian function
%Author: Mark S. Nixon
%centre is half of window size
centre=floor(winsize/2)+1;
%we'll normalise by the total sum
sum=0;
%so work out the coefficients and the running total
for i=1:winsize
for j=1:winsize
template(j,i)=exp(-(((j-centre)*(j-centre))+((i-centre)*(i-centre)))/(2*sigma*sigma))
sum=sum+template(j,i);
end
end
%and then normalise
template=template/sum;
Although the correct equation and the code implementation give similar results to some degree, I am wondering why in the same book the implementation and the equation are different.
My question is, have any of you worked with Gaussian filtering implementations, and is the equation correct to implement? Any idea why the book gives a simpler implementation?