简体   繁体   English

高斯滤波器的特殊选择

[英]fspecial alternatives for Gaussian filter

I am attempting to use a MATLAB script that requires the use of the Image Processing Toolbox function fspecial() . 我正在尝试使用需要使用图像处理工具箱函数fspecial()的MATLAB脚本。

I do not have the Image Processing Toolbox, but do have the Signal Processing Toolbox which contains suite of tools for the creation of filters. 我没有图像处理工具箱,但是有信号处理工具箱,其中包含用于创建滤镜的工具套件。 Sadly, I am largely ignorant on filter creation and am looking to see if I can get some help determining if I can replicate the following line of code using the filter creation tools in the Signal Processing Toolbox: 令人遗憾的是,我对滤波器的创建一无所知,并希望了解我是否可以得到一些帮助,以确定是否可以使用信号处理工具箱中的滤波器创建工具来复制以下代码行:

fspecial('gaussian', [5 1], 0.75)

fspecial() creates a set of user-specified two-dimensional filter functions, and provides a set of default values. fspecial()创建一组用户指定的二维过滤器函数,并提供一组默认值。

The following function will produce the equivalent 2D Gaussian function. 以下函数将产生等效的2D高斯函数。 It is also the implementation in fspecial when run with the option 'gaussian'. 当使用选项'gaussian'.运行时,它也是fspecial的实现'gaussian'.

You can call it by h = gaussian2D([5 1], 0.75); 您可以通过h = gaussian2D([5 1], 0.75);来调用它h = gaussian2D([5 1], 0.75); , for your example. ,例如。

%% 2D Gaussian filter
function h = gaussian2D(siz, std)

% create the grid of (x,y) values
siz = (siz-1)./2;
[x,y] = meshgrid(-siz(2):siz(2),-siz(1):siz(1));

% analytic function
h = exp(-(x.*x + y.*y)/(2*std*std));

% truncate very small values to zero
h(h<eps*max(h(:))) = 0;

% normalize filter to unit L1 energy 
sumh = sum(h(:));
if sumh ~= 0
    h = h/sumh;
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM