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