comparison inst/bwdist.m @ 218:69bb85145ef5

First revision of bwarea.m and __bwarea.cc
author hauberg
date Thu, 28 Dec 2006 22:42:12 +0000
parents
children 86749dc087db
comparison
equal deleted inserted replaced
217:93ec20b95b4a 218:69bb85145ef5
1 ## Copyright (C) 2006 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 2, or (at your option)
6 ## any later version.
7 ##
8 ## This program is distributed in the hope that it will be useful, but
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 ## General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU General Public License
14 ## along with this file. If not, write to the Free Software Foundation,
15 ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17 ## -*- texinfo -*-
18 ## @deftypefn {Function File} @var{d} = bwdist(@var{bw}, @var{method})
19 ## Computes the distance transform of the binary image @var{bw}.
20 ## The result @var{d} is a matrix of the same size as @var{bw}, where
21 ## each value is the shortest distance to a non-zero pixel in @var{bw}.
22 ##
23 ## @var{method} changes the used distance function. Currently
24 ## the Euclidian distance is the only supported distance function.
25 ## @end deftypefn
26
27 function D = bwdist(bw, method = "euclidian")
28 ## Check input
29 if (nargin == 0)
30 print_usage();
31 endif
32
33 if (!ismatrix(bw) || ndims(bw) != 2)
34 error("bwdist: input must be a 2-dimensional matrix");
35 endif
36
37 if (!ischar(method))
38 error("bwdist: method name must be a string");
39 endif
40
41 ## Do the work
42 bw = (bw != 0);
43 switch (lower(method(1)))
44 case "e"
45 ## Euclidian distance transform
46 D = __bwdist(bw);
47 otherwise
48 error("bwdist: unsupported method '%s'", method);
49 endswitch
50 endfunction