1 ## Copyright (C) 2000 Kai Habel
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.
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, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {@var{X} =} grayslice (@var{I},@var{n})
18 ## @deftypefnx {Function File} {@var{X} =} grayslice (@var{I},@var{v})
19 ## creates an indexed image @var{X} from an intensitiy image @var{I}
20 ## using multiple threshold levels.
21 ## A scalar integer value @var{n} sets the levels to
31 ## X = grayslice(I,5);
33 ## For irregular threshold values a real vector @var{v} can be used.
34 ## The values must be in the range [0,1].
37 ## X = grayslice(I,[0.1,0.33,0.75,0.9])
43 ## Author: Kai Habel <kai.habel@gmx.de>
44 ## Date: 03. August 2000
46 function X = grayslice (I, v)
49 usage ("grayslice(...) number of arguments must be 1 or 2");
52 if (is_scalar(v) && (fix(v) == v))
58 if (any (v < 0) || (any (v > 1)))
59 error ("slice vector must be in range [0,1]")
64 usage("second argument");
69 [m, n] = sort ([v(:); I(:)]);
75 X = reshape (idx(n), r, c);