forked from somponnat/Somponnat_SingleCellAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filterGauss2D.m
29 lines (25 loc) · 896 Bytes
/
filterGauss2D.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function [out, G] = filterGauss2D(image, sigma, borderCondition)
% filterGauss2D : filters an image with a 2-D Gaussian mask
%
% [out, G] = filterGauss2D(image, sigma, borderCondition);
%
% INPUT: image : 2-D input array
% sigma : standard deviation of the Gaussian
% borderCondition : input for 'padarrayXT'. Default: 'symmetric'
% Options: 'symmetric', 'replicate', 'circular', 'antisymmetric', or a constant value
%
% OUTPUT: out : filtered image
% G : Gaussian mask
%
% Francois Aguet, added 01/21/2010
if nargin < 3 || isempty(borderCondition)
borderCondition = 'symmetric';
end
w = ceil(3*sigma); % cutoff radius of the gaussian kernel
x = -w:w;
g = exp(-x.^2/(2*sigma^2));
g = g/sum(g);
out = conv2(g', g, padarrayXT(image, [w w], borderCondition), 'valid');
if (nargout>1)
G = g'*g;
end