annotate inst/bwhitmiss.m @ 857:75d6748324de

New functions imgradient and imgradientxy (patch #8265) * imgradient.m, imgradientxy.m: new function files. * INDEX: update list of functions. * NEWS: update list of new functinos for next release.
author Brandon Miles <brandon.miles7@gmail.com>
date Sun, 05 Jan 2014 07:27:06 +0000
parents c6be7812523a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
709
c6be7812523a maint: fix Søren's name
carandraug
parents: 628
diff changeset
1 ## Copyright (C) 2008 Søren Hauberg <soren@hauberg.org>
628
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
2 ##
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
3 ## This program is free software; you can redistribute it and/or modify it under
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
4 ## the terms of the GNU General Public License as published by the Free Software
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
5 ## Foundation; either version 3 of the License, or (at your option) any later
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
6 ## version.
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
7 ##
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
11 ## details.
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
12 ##
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
13 ## You should have received a copy of the GNU General Public License along with
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
15
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
16 ## -*- texinfo -*-
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
17 ## @deftypefn {Function File} @var{bw2} = bwhitmiss (@var{bw1}, @var{se1}, @var{se1})
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
18 ## @deftypefnx{Function File} @var{bw2} = bwhitmiss (@var{bw1}, @var{interval})
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
19 ## Perform the binary hit-miss operation.
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
20 ##
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
21 ## If two structuring elements @var{se1} and @var{se1} are given, the hit-miss
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
22 ## operation is defined as
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
23 ## @example
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
24 ## bw2 = erode(bw1, se1) & erode(!bw1, se2);
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
25 ## @end example
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
26 ## If instead an 'interval' array is given, two structuring elements are computed
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
27 ## as
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
28 ## @example
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
29 ## se1 = (interval == 1)
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
30 ## se2 = (interval == -1)
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
31 ## @end example
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
32 ## and then the operation is defined as previously.
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
33 ## @seealso{bwmorph}
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
34 ## @end deftypefn
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
35
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
36 function bw = bwhitmiss(im, varargin)
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
37 ## Checkinput
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
38 if (nargin != 2 && nargin != 3)
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
39 print_usage();
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
40 endif
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
41 if (!ismatrix(im) || !isreal(im))
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
42 error("bwhitmiss: first input argument must be a real matrix");
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
43 endif
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
44
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
45 ## Get structuring elements
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
46 if (nargin == 2) # bwhitmiss (im, interval)
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
47 interval = varargin{1};
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
48 if (!isreal(interval))
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
49 error("bwhitmiss: second input argument must be a real matrix");
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
50 endif
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
51 if (!all( (interval(:) == 1) | (interval(:) == 0) | (interval(:) == -1) ))
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
52 error("bwhitmiss: second input argument can only contain the values -1, 0, and 1");
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
53 endif
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
54 se1 = (interval == 1);
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
55 se2 = (interval == -1);
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
56 else # bwhitmiss (im, se1, se2)
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
57 se1 = varargin{1};
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
58 se2 = varargin{2};
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
59 if (!all((se1(:) == 1) | (se1(:) == 0)) || !all((se2(:) == 1) | (se2(:) == 0)))
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
60 error("bwhitmiss: structuring elements can only contain zeros and ones.");
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
61 endif
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
62 endif
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
63
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
64 ## Perform filtering
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
65 bw = erode(im, se1) & erode(!im, se2);
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
66
22009b99ee6b image: fix dos line ending style
carandraug
parents: 561
diff changeset
67 endfunction