1 ## Copyright (C) 2004 Josep Mones i Teixidor <jmones@puntbarra.com>
2 ## Copyright (C) 2008 Soren Hauberg
3 ## Copyright (C) 2010 Carnë Draug <carandraug+dev@gmail.com>
5 ## This program is free software; you can redistribute it and/or
6 ## modify it under the terms of the GNU General Public License
7 ## as published by the Free Software Foundation; either version 3
8 ## of the License, or (at your option) any later version.
10 ## This program is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ## GNU General Public License for more details.
16 ## @deftypefn {Function File} @var{B} = imdilate (@var{A}, @var{se})
17 ## Perform morphological dilation on a given image.
19 ## The image @var{A} must be a grayscale or binary image, and @var{se} must be a
20 ## structuring element. Both must have the same class, e.g., if @var{A} is a
21 ## logical matrix, @var{se} must also be logical.
23 ## @seealso{imerode, imopen, imclose}
26 function retval = imdilate(im, se)
31 if (!ismatrix(im) || !isreal(im))
32 error("imdilate: first input argument must be a real matrix");
33 elseif (!ismatrix(se) || !isreal(se))
34 error("imdilate: second input argument must be a real matrix");
35 elseif ( !strcmp(class(im), class(se)) )
36 error("imdilate: image and structuring element must have the same class");
40 ## Filtering must be done with the reflection of the structuring element (they
41 ## are not always symmetrical)
42 se = imrotate(se, 180);
44 ## If image is binary/logical, try to use filter2 (much faster)
46 retval = filter2(se,im)>0;
48 retval = ordfiltn(im, sum(se(:)!=0), se, 0);