fspecial alternatives for Gaussian filter

余生颓废 提交于 2019-12-11 15:11:13

问题


I am attempting to use a MATLAB script that requires the use of the Image Processing Toolbox function fspecial().

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)

回答1:


fspecial() creates a set of user-specified two-dimensional filter functions, and provides a set of default values.

The following function will produce the equivalent 2D Gaussian function. It is also the implementation in fspecial when run with the option 'gaussian'.

You can call it by 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


来源:https://stackoverflow.com/questions/15442712/fspecial-alternatives-for-gaussian-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!