1 ## Copyright (C) 2008 Soren Hauberg
3 ## This program is free software; you can redistribute it and/or
4 ## modify it under the terms of the GNU General Public License
5 ## as published by the Free Software Foundation; either version 2
6 ## of the License, or (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.
14 ## @deftypefn {Function File} @var{bw2} = bwhitmiss (@var{bw1}, @var{se1}, @var{se1})
15 ## @deftypefnx{Function File} @var{bw2} = bwhitmiss (@var{bw1}, @var{interval})
16 ## Perform the binary hit-miss operation.
18 ## If two structuring elements @var{se1} and @var{se1} are given, the hit-miss
19 ## operation is defined as
21 ## bw2 = erode(bw1, se1) & erode(!bw1, se2);
23 ## If instead an 'interval' array is given, two structuring elements are computed
26 ## se1 = (interval == 1)
27 ## se2 = (interval == -1)
29 ## and then the operation is defined as previously.
33 function bw = bwhitmiss(im, varargin)
35 if (nargin != 2 && nargin != 3)
38 if (!ismatrix(im) || !isreal(im))
39 error("bwhitmiss: first input argument must be a real matrix");
42 ## Get structuring elements
43 if (nargin == 2) # bwhitmiss (im, interval)
44 interval = varargin{1};
45 if (!isreal(interval))
46 error("bwhitmiss: second input argument must be a real matrix");
48 if (!all( (interval(:) == 1) | (interval(:) == 0) | (interval(:) == -1) ))
49 error("bwhitmiss: second input argument can only contain the values -1, 0, and 1");
51 se1 = (interval == 1);
52 se2 = (interval == -1);
53 else # bwhitmiss (im, se1, se2)
56 if (!all((se1(:) == 1) | (se1(:) == 0)) || !all((se2(:) == 1) | (se2(:) == 0)))
57 error("bwhitmiss: structuring elements can only contain zeros and ones.");
62 bw = erode(im, se1) & erode(!im, se2);