X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Fimage-1.0.15%2Fmmgradm.m;fp=octave_packages%2Fimage-1.0.15%2Fmmgradm.m;h=4b12d9bb35a59d1e61bf6ae81efb9e3a75fd6619;hp=0000000000000000000000000000000000000000;hb=c880e8788dfc484bf23ce13fa2787f2c6bca4863;hpb=1705066eceaaea976f010f669ce8e972f3734b05 diff --git a/octave_packages/image-1.0.15/mmgradm.m b/octave_packages/image-1.0.15/mmgradm.m new file mode 100644 index 0000000..4b12d9b --- /dev/null +++ b/octave_packages/image-1.0.15/mmgradm.m @@ -0,0 +1,50 @@ +## Copyright (C) 2010 Carnë Draug +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, see . + +## -*- texinfo -*- +## @deftypefn {Function File} @var{grad} = mmgradm(@var{A}, @var{se}) +## @deftypefnx {Function File} @var{grad} = mmgradm(@var{A}, @var{se_dil}, @var{se_ero}) +## Calculates the morphological gradient @var{grad} of a given image @var{A}. +## +## In the first form, the same structuring element @var{se} is used for dilation +## and erosion. In the second form, @var{se_dil} and @var{se_ero} are the +## corresponding structuring elements used for dilation and erosion +## +## The image @var{A} must be a grayscale or a binary image. +## +## The morphological gradient of a image corresponds to its erosion subtracted +## to its dilation. +## +## @seealso{imerode, imdilate, imopen, imclose, imtophat} +## @end deftypefn + +function grad = mmgradm (im, se_dil, se_ero) + + ## sanity checks + if (nargin == 1) + error ("Structuring element must be specified"); + elseif (nargin == 2) # if only one SE is specified, use it for both erosion and dilation + se_ero = se_dil; + elseif (nargin == 3) + # all is good + else + print_usage; + endif + + dilated = imdilate (im, se_dil); + eroded = imerode (im, se_ero); + + grad = dilated - eroded; +endfunction