1 ## Copyright (C) 2010 Carnë Draug <carandraug+dev@gmail.com>
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 3 of the License, or
6 ## (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.
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} @var{grad} = mmgradm(@var{A}, @var{se})
18 ## @deftypefnx {Function File} @var{grad} = mmgradm(@var{A}, @var{se_dil}, @var{se_ero})
19 ## Calculates the morphological gradient @var{grad} of a given image @var{A}.
21 ## In the first form, the same structuring element @var{se} is used for dilation
22 ## and erosion. In the second form, @var{se_dil} and @var{se_ero} are the
23 ## corresponding structuring elements used for dilation and erosion
25 ## The image @var{A} must be a grayscale or a binary image.
27 ## The morphological gradient of a image corresponds to its erosion subtracted
30 ## @seealso{imerode, imdilate, imopen, imclose, imtophat}
33 function grad = mmgradm (im, se_dil, se_ero)
37 error ("Structuring element must be specified");
38 elseif (nargin == 2) # if only one SE is specified, use it for both erosion and dilation
46 dilated = imdilate (im, se_dil);
47 eroded = imerode (im, se_ero);
49 grad = dilated - eroded;