changeset 430:e6fcf4a6e06c

Faster and easier bug fix for bug when using non-symmetrical SE. Only need to rotate the SE before the filtering
author carandraug
date Fri, 13 Aug 2010 15:59:54 +0000
parents 9acda5798f6f
children e29d66cabc4f
files inst/imdilate.m
diffstat 1 files changed, 3 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/inst/imdilate.m
+++ b/inst/imdilate.m
@@ -30,21 +30,10 @@
     error("imdilate: second input argument must be a real matrix");
   endif
 
-  if (isinteger(im))
-    padding = intmax(class(im));
-  elseif (islogical(im))
-    padding = logical(1);
-  elseif (isreal(im))
-    padding = Inf;
-  else
-    error("Unexpected class for the image. Must be logical, integer ou real matrix")
-  endif
-
   ## Perform filtering
-  ## Dilation of A by B is the erosion of A's complement by the reflection of B
-  ## Since erosion will be performed in the complement, padding must also be the
-  ## complement of zero
+  ## Filtering must be done with the reflection of the structuring element (they
+  ## are not always symmetrical)
   se      = imrotate(se, 180);
-  retval  = !ordfiltn(!im, 1, se, padding);
+  retval  = ordfiltn(im, sum(se(:)!=0), se, 0);
 
 endfunction