changeset 696:2b09f92042d0

imerode: implement erosion with non-flat se
author carandraug
date Wed, 26 Dec 2012 01:32:06 +0000 (2012-12-26)
parents 8c3ca958d9f5
children 25ce2dbcccaa
files inst/imerode.m
diffstat 1 files changed, 15 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/inst/imerode.m
+++ b/inst/imerode.m
@@ -47,13 +47,23 @@
 
   cl = class (im);
   if (isbw (im, "non-logical"))
-    se = getnhood (se);
-    im = filter2 (se, im) == nnz (se);
-    ## once we do implement getsequence for strel objects we should do:
+    if (isflat (se))
+      nhood = getnhood (se);
+    else
+      nhood = getheight (SE);
+    endif
+    ## this is the same as nhood(end:-1:1, end:-1:1) but should work for any
+    ## number of dimensions since the SE needs to be reversed for the convolution
+    nhood = rotdim (nhood, 2, [1 ndims(nhood)]);
+    im    = convn (im, nhood, "same") == nnz (nhood);
+
+    ## once we do implement getsequence for strel objects we should do
+    ## something like:
 #    seq = getsequence (se);
 #    for ii = 1:numel (seq)
-#      cse = getnhood (seq(ii));
-#      im  = filter2 (cse, im) == nnz (cse);
+#      nhood = getnhood (seq(ii));
+#      nhood = rotdim (nhood, 2, [1 ndims(nhood)]);
+#      im    = convn (im, nhood, "same") == nnz (nhood);
 #    endfor
 
   elseif (isgray (im))