Smoothing

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

function y = smoothing(x,sigma)

sigma2 = sigma^2;
[nx,ny] = size(x);
M = ceil(3*sigma);
if(nx==1 || ny==1)
X = -M:M;
kernel = 1.0/(sqrt(2*pi)*sigma)*exp(-X.^2/(2*sigma2));
y = convn(padarray(x(:),M,'circular'),kernel(:),'valid');
y = reshape(y,nx,ny);
else
[X,Y] = meshgrid(-M:M);
kernel = 1.0/(sqrt(2*pi)*sigma)^2*exp(-(X.^2+Y.^2)/(2*sigma2));
y = conv2(padarray(x,[M,M],'circular'),kernel,'valid');
end

You might also like