X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Fimage-1.0.15%2Fimdilate.m;fp=octave_packages%2Fimage-1.0.15%2Fimdilate.m;h=fd597da38318669d1f35a8fe0140c60fc7f09b3d;hp=0000000000000000000000000000000000000000;hb=f5f7a74bd8a4900f0b797da6783be80e11a68d86;hpb=1705066eceaaea976f010f669ce8e972f3734b05 diff --git a/octave_packages/image-1.0.15/imdilate.m b/octave_packages/image-1.0.15/imdilate.m new file mode 100644 index 0000000..fd597da --- /dev/null +++ b/octave_packages/image-1.0.15/imdilate.m @@ -0,0 +1,51 @@ +## Copyright (C) 2004 Josep Mones i Teixidor +## Copyright (C) 2008 Soren Hauberg +## 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. + +## -*- texinfo -*- +## @deftypefn {Function File} @var{B} = imdilate (@var{A}, @var{se}) +## Perform morphological dilation 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{imerode, imopen, imclose} +## @end deftypefn + +function retval = imdilate(im, se) + ## Checkinput + if (nargin != 2) + print_usage(); + endif + if (!ismatrix(im) || !isreal(im)) + error("imdilate: first input argument must be a real matrix"); + elseif (!ismatrix(se) || !isreal(se)) + error("imdilate: second input argument must be a real matrix"); + elseif ( !strcmp(class(im), class(se)) ) + error("imdilate: image and structuring element must have the same class"); + endif + + ## Perform filtering + ## Filtering must be done with the reflection of the structuring element (they + ## are not always symmetrical) + se = imrotate(se, 180); + + ## If image is binary/logical, try to use filter2 (much faster) + if (islogical(im)) + retval = filter2(se,im)>0; + else + retval = ordfiltn(im, sum(se(:)!=0), se, 0); + endif + +endfunction