comparison main/image/grayslice.m @ 0:6b33357c7561 octave-forge

Initial revision
author pkienzle
date Wed, 10 Oct 2001 19:54:49 +0000
parents
children 06b69b2ad388
comparison
equal deleted inserted replaced
-1:000000000000 0:6b33357c7561
1 ## Copyright (C) 2000 Kai Habel
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 2 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
17 ## -*- texinfo -*-
18 ## @deftypefn {Function File} {@var{X} =} grayslice (@var{I},@var{n})
19 ## @deftypefnx {Function File} {@var{X} =} grayslice (@var{I},@var{v})
20 ## creates an indexed image @var{X} from an intensitiy image @var{I}
21 ## using multiple threshold levels.
22 ## A scalar integer value @var{n} sets the levels to
23 ## @example
24 ##
25 ## @group
26 ## 1 2 n-1
27 ## -, -, ..., ---
28 ## n n n
29 ## @end group
30 ## @end example
31 ##
32 ## X = grayslice(I,5);
33 ##
34 ## For irregular threshold values a real vector @var{v} can be used.
35 ## The values must be in the range [0,1].
36 ##
37 ## @group
38 ## X = grayslice(I,[0.1,0.33,0.75,0.9])
39 ## @end group
40 ##
41 ## @end deftypefn
42 ## @seealso{im2bw}
43
44 ## Author: Kai Habel <kai.habel@gmx.de>
45 ## Date: 03. August 2000
46
47 function X = grayslice (I, v)
48
49 if (nargin != 2)
50 usage ("grayslice(...) number of arguments must be 1 or 2");
51 endif
52
53 if (is_scalar(v) && (fix(v) == v))
54
55 v = (1:v - 1) / v;
56
57 elseif (is_vector(v))
58
59 if (any (v < 0) || (any (v > 1)))
60 error ("slice vector must be in range [0,1]")
61 endif
62 v = [0,v,1];
63 else
64
65 usage("second argument");
66
67 endif
68
69 [r, c] = size (I);
70 [m, n] = sort ([v(:); I(:)]);
71 lx = length (v);
72 o = cumsum (n <= lx);
73 idx = o (find(n>lx));
74 [m, n] = sort (I(:));
75 [m, n] = sort (n);
76 X = reshape (idx(n), r, c);
77
78 endfunction