]> Creatis software - CreaPhase.git/blob - octave_packages/image-1.0.15/rangefilt.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / image-1.0.15 / rangefilt.m
1 ## Copyright (C) 2008 Søren Hauberg
2 ## 
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.
7 ## 
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.
12 ## 
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
16
17 ## -*- texinfo -*-
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
22 ## an image.
23 ##
24 ## The intensity range of the pixels of a neighbourhood is computed as
25 ##
26 ## @example
27 ## @var{R} = max (@var{x}) - min (@var{x})
28 ## @end example
29 ##
30 ## where @var{x} is the value of the pixels in the neighbourhood,
31 ##
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.
35 ##
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
38 ## can be used.
39 ##
40 ## @seealso{paddarray, entropyfilt, stdfilt}
41 ## @end deftypefn
42
43 function retval = rangefilt (I, domain = true (3), padding = "symmetric", varargin)
44   ## Check input
45   if (nargin == 0)
46     error ("rangefilt: not enough input arguments");
47   endif
48   
49   if (!ismatrix (I))
50     error ("rangefilt: first input must be a matrix");
51   endif
52   
53   if (!ismatrix (domain))
54     error ("rangefilt: second input argument must be a logical matrix");
55   endif
56   domain = (domain > 0);
57   
58   ## Pad image
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));
63   for k = 1:ndims (I)
64     idx {k} = (even (k)+1):size (I, k);
65   endfor
66   I = I (idx {:});
67
68   ## Perform filtering
69   retval = __spatial_filtering__ (I, domain, "range", I, 0);
70
71 endfunction