高斯滤波器的实现 [英] Gaussian Filter implemetation

查看:181
本文介绍了高斯滤波器的实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正准备在C#中实现高斯滤波器,并正在准备阅读有关此的文献.但是我有不同意见.

I am preparing to implement a Gaussian Filter in C#, and in preparation I am reading literature on this. However I have disagreeing sources.

一本书(日语:Uchimura的《实用图像处理入门》)指定计算模板的公式为

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)). 

我认为这是正确的,尽管作者将size和sigma链接为SIZE = 3*sigma.

I think that is correct, although the author links size and sigma as SIZE = 3*sigma.

最后,一本非常出色的书(Nixon和Aguado着,《计算机视觉的特征提取和图像处理》,第106页)给出了正确的方程式,但是当用代码实现时,方程式却有所不同.

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)) 

其中,SUM是所有指数值的总和.下面是他们提供的伪代码-我认为它接近MATLAB.

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?

推荐答案

两个实现都在规范化,因此系数之和为1.0.第二种实现是手动计算总和以获得确切的数字,这可能是最好的方法.另一种实现方式为过滤器的连续版本提供了精确的总和.但是,离散化滤波器只能给出一个近似值,因此近似和与连续积分并不相同.

Both implementations are normalizing so that the sum of the coefficients is 1.0. The second implementation computes the sum manually to get an exact figure and is probably the best way to go. The other implementation gives an exact sum for a continuous version of the filter. However, discretizing the filter only gives an approximation so the approximated sum is not the same as the continuous integral.

侧面说明:您可能要记住,高斯在单个像素上是非线性的.在像素中心采样将得出不准确的结果.最好在子像素处进行采样,然后对整个像素进行平均.

Side note: you might want to keep in mind that the Gaussian is non-linear across a single pixel. Sampling at the pixel centers will give an inaccurate result. It is better to sample at the sub-pixel and then average over the entire pixel.

这篇关于高斯滤波器的实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆