changeset 432:1f41e9b97823

Speed boost for imdilate function when using binary images (using code from dilate function)
author carandraug
date Mon, 16 Aug 2010 00:51:07 +0000
parents e29d66cabc4f
children 9841304a5595
files inst/imdilate.m
diffstat 1 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/inst/imdilate.m
+++ b/inst/imdilate.m
@@ -1,4 +1,5 @@
 ## Copyright (C) 2008 Soren Hauberg
+## Copyright (C) 2010 Carnë Draug <carandraug+dev@gmail.com>
 ## 
 ## This program is free software; you can redistribute it and/or
 ## modify it under the terms of the GNU General Public License
@@ -34,6 +35,17 @@
   ## Filtering must be done with the reflection of the structuring element (they
   ## are not always symmetrical)
   se      = imrotate(se, 180);
-  retval  = ordfiltn(im, sum(se(:)!=0), se, 0);
+
+  ## If image is logical, try to use filter2 from signal package. If it is not,
+  ## or filter2 function is not available, use slower version ordfiltn
+  try
+    if (islogical(im))
+      retval=filter2(se,im)>0;    # This line comes from the function dilate, copyright by Josep Mones i Teixidor
+    else
+      error;
+    endif
+  catch
+    retval  = ordfiltn(im, sum(se(:)!=0), se, 0);
+  end_try_catch
 
 endfunction