]> Creatis software - CreaPhase.git/blob - octave_packages/image-1.0.15/mmgradm.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / image-1.0.15 / mmgradm.m
1 ## Copyright (C) 2010 CarnĂ« Draug <carandraug+dev@gmail.com>
2 ##
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.
7 ##
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.
12 ##
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/>.
15
16 ## -*- texinfo -*-
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}.
20 ##
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
24 ##
25 ## The image @var{A} must be a grayscale or a binary image.
26 ##
27 ## The morphological gradient of a image corresponds to its erosion subtracted
28 ## to its dilation.
29 ##
30 ## @seealso{imerode, imdilate, imopen, imclose, imtophat}
31 ## @end deftypefn
32
33 function grad = mmgradm (im, se_dil, se_ero)
34
35   ## sanity checks
36   if (nargin == 1)
37     error ("Structuring element must be specified");
38   elseif (nargin == 2)              # if only one SE is specified, use it for both erosion and dilation
39     se_ero  = se_dil;
40   elseif (nargin == 3)
41     # all is good
42   else
43     print_usage;
44   endif
45
46   dilated   = imdilate  (im, se_dil);
47   eroded    = imerode   (im, se_ero);
48
49   grad      = dilated - eroded;
50 endfunction