clear;close all;clc
% 高斯滤波器参数
s1 = 15; s2 = 20;
sigma = 15;
% 按公式编写
[x, y]=meshgrid(-((s2-1)/2):(s2/2),(-((s1-1)/2):(s1/2)));
gauss=exp(-(x.^2+y.^2)/(2*sigma*sigma));
G1=gauss/sum(gauss(:));
% Matlab 自带
G2 = fspecial(‘gaussian‘,[s1,s2],sigma);
isequal(G1,G2)
figure
subplot(1,2,1);mesh(G1);title(‘按公式编写‘)
subplot(1,2,2);mesh(G2);title(‘Matlab 自带‘)
ans =
logical
1
原文:https://www.cnblogs.com/gshang/p/14771801.html