我正准备在 C# 中实现一个高斯滤波器,并且在准备中我正在阅读这方面的文献。但是我有不同的消息来源。
一本书(日文:Practical Image Processing Introduction by Uchimura)指定计算模板的方程为
w(u,v)= (1/2*pi*sigma^2) exp(-(x^2+v^2)/(2*sigma^2)).
我认为这是正确的,尽管作者将 size 和 sigma 链接为SIZE = 3*sigma
.
最后,一本优秀的书(Nixon 和 Aguado 的 Feature Extraction & Image Processing for Computer Vision,第 106 页)给出了正确的等式,但在代码中实现时给出了不同的实现。
w(u,v)= (1/SUM)* exp(-(x^2+v^2)/(2*sigma^2))
其中SUM
是指数的所有值的总和。下面是他们提供的伪代码 - 我认为它接近 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;
尽管正确的方程和代码实现在某种程度上给出了相似的结果,但我想知道为什么在同一本书中实现和方程是不同的。
我的问题是,你们中的任何人都使用过高斯滤波实现吗?实现的方程式是否正确?知道为什么这本书给出了一个更简单的实现吗?