问题
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