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{R} =} rangefilt (@var{im})
19 ## @deftypefnx{Function File} {@var{R} =} rangefilt (@var{im}, @var{domain})
20 ## @deftypefnx{Function File} {@var{R} =} rangefilt (@var{im}, @var{domain}, @var{padding}, ...)
21 ## Computes the local intensity range in a neighbourhood around each pixel in
24 ## The intensity range of the pixels of a neighbourhood is computed as
27 ## @var{R} = max (@var{x}) - min (@var{x})
30 ## where @var{x} is the value of the pixels in the neighbourhood,
32 ## The neighbourhood is defined by the @var{domain} binary mask. Elements of the
33 ## mask with a non-zero value are considered part of the neighbourhood. By default
34 ## a 3 by 3 matrix containing only non-zero values is used.
36 ## At the border of the image, extrapolation is used. By default symmetric
37 ## extrapolation is used, but any method supported by the @code{padarray} function
40 ## @seealso{paddarray, entropyfilt, stdfilt}
43 function retval = rangefilt (I, domain = true (3), padding = "symmetric", varargin)
46 error ("rangefilt: not enough input arguments");
50 error ("rangefilt: first input must be a matrix");
53 if (!ismatrix (domain))
54 error ("rangefilt: second input argument must be a logical matrix");
56 domain = (domain > 0);
59 pad = floor (size (domain)/2);
60 I = padarray (I, pad, padding, varargin {:});
61 even = (round (size (domain)/2) == size (domain)/2);
62 idx = cell (1, ndims (I));
64 idx {k} = (even (k)+1):size (I, k);
69 retval = __spatial_filtering__ (I, domain, "range", I, 0);