1 ## Copyright (C) 2008 Søren Hauberg
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 3 of the License, or
6 ## (at your option) any later version.
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ## GNU General Public License for more details.
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; if not, write to the Free Software
15 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 ## @deftypefn {Function File} {@var{S} =} stdfilt (@var{im})
19 ## @deftypefnx{Function File} {@var{S} =} stdfilt (@var{im}, @var{domain})
20 ## @deftypefnx{Function File} {@var{S} =} stdfilt (@var{im}, @var{domain}, @var{padding}, ...)
21 ## Computes the local standard deviation in a neighbourhood around each pixel in
24 ## The standard deviation of the pixels of a neighbourhood is computed as
27 ## @var{S} = sqrt ((sum (@var{x} - @var{mu}).^2)/(@var{N}-1))
30 ## where @var{mu} is the mean value of the pixels in the neighbourhood,
31 ## @var{N} is the number of pixels in the neighbourhood. So, an unbiased estimator
34 ## The neighbourhood is defined by the @var{domain} binary mask. Elements of the
35 ## mask with a non-zero value are considered part of the neighbourhood. By default
36 ## a 3 by 3 matrix containing only non-zero values is used.
38 ## At the border of the image, extrapolation is used. By default symmetric
39 ## extrapolation is used, but any method supported by the @code{padarray} function
40 ## can be used. Since extrapolation is used, one can expect a lower deviation near
43 ## @seealso{std2, paddarray, entropyfilt}
46 function retval = stdfilt (I, domain = true (3), padding = "symmetric", varargin)
49 error ("stdfilt: not enough input arguments");
53 error ("stdfilt: first input must be a matrix");
56 if (!ismatrix (domain))
57 error ("stdfilt: second input argument must be a logical matrix");
59 domain = (domain > 0);
62 pad = floor (size (domain)/2);
63 I = padarray (I, pad, padding, varargin {:});
64 even = (round (size (domain)/2) == size (domain)/2);
65 idx = cell (1, ndims (I));
67 idx {k} = (even (k)+1):size (I, k);
72 retval = __spatial_filtering__ (I, domain, "std", I, 0);