1

我正准备在 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; 

尽管正确的方程和代码实现在某种程度上给出了相似的结果,但我想知道为什么在同一本书中实现和方程是不同的。

我的问题是,你们中的任何人都使用过高斯滤波实现吗?实现的方程式是否正确?知道为什么这本书给出了一个更简单的实现吗?

4

1 回答 1

3

两种实现都进行了归一化,因此系数之和为 1.0。第二种实现手动计算总和以获得准确的数字,这可能是最好的方法。另一种实现为过滤器的连续版本提供了精确的总和。但是,对滤波器进行离散化仅给出近似值,因此近似和与连续积分不同。

旁注:您可能要记住,高斯在单个像素上是非线性的。在像素中心采样会产生不准确的结果。最好在子像素处进行采样,然后在整个像素上进行平均。

于 2017-08-18T06:14:40.460 回答