X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=octave_packages%2Fimage-1.0.15%2Fimerode.m;fp=octave_packages%2Fimage-1.0.15%2Fimerode.m;h=97b4be495f96fcbb81861df8ec444e8c56f73602;hb=f5f7a74bd8a4900f0b797da6783be80e11a68d86;hp=0000000000000000000000000000000000000000;hpb=1705066eceaaea976f010f669ce8e972f3734b05;p=CreaPhase.git diff --git a/octave_packages/image-1.0.15/imerode.m b/octave_packages/image-1.0.15/imerode.m new file mode 100644 index 0000000..97b4be4 --- /dev/null +++ b/octave_packages/image-1.0.15/imerode.m @@ -0,0 +1,48 @@ +## Copyright (C) 2004 Josep Mones i Teixidor +## Copyright (C) 2008 Soren Hauberg +## Copyright (C) 2011 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. + +## -*- texinfo -*- +## @deftypefn {Function File} @var{B} = imerode (@var{A}, @var{se}) +## Perform morphological erosion on a given image. +## +## The image @var{A} must be a grayscale or binary image, and @var{se} must be a +## structuring element. Both must have the same class, e.g., if @var{A} is a +## logical matrix, @var{se} must also be logical. +## +## @seealso{imdilate, imopen, imclose} +## @end deftypefn + +function retval = imerode(im, se) + ## Checkinput + if (nargin != 2) + print_usage(); + endif + if (!ismatrix(im) || !isreal(im)) + error("imerode: first input argument must be a real matrix"); + elseif (!ismatrix(se) || !isreal(se)) + error("imerode: second input argument must be a real matrix"); + elseif ( !strcmp(class(im), class(se)) ) + error("imerode: image and structuring element must have the same class"); + endif + + ## Perform filtering + ## If image is binary/logical, try to use filter2 (much faster) + if (islogical(im)) + thr = sum(se(:)); + retval = filter2(se,im) == thr; + else + retval = ordfiltn(im, 1, se, 0); + endif + +endfunction