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{BW}= im2bw (@var{I},threshold)
18 ## @deftypefnx {Function File} @var{BW}= im2bw (@var{X},@var{cmap},threshold)
19 ## Converts image data types to a black-white (binary) image.
20 ## The treshold value should be in the range [0,1].
23 ## Author: Kai Habel <kai.habel@gmx.de>
24 ## Date: 19. March 2000
26 function BW = im2bw (img, a, b)
27 if (nargin < 2 || nargin > 3)
28 usage("im2bw: number of arguments must be 2 or 3");
31 ## Convert img to gray scale
35 error("im2bw: two input arguments must be given when the image is a color image");
38 elseif (isind (img) && ismatrix(a) && columns (a) == 3)
39 img = ind2gray (img, a);
41 error("im2bw: three input arguments must be given when the image is indexed");
46 error("im2bw: two input arguments must be given when the image is gray scale");
50 error ("im2bw: first input argument must be an image");
53 ## Do the thresholding
56 error("im2bw: threshold must be in the interval [0, 1]");
59 case {"double", "single"}
64 BW = (img >= 65535*t);
66 error("im2bw: unsupport image class");
69 error ("im2bw: threshold value must be scalar");