changeset 507:a60411e31d36

isbw: check sample of image first to speed up computation
author carandraug
date Mon, 05 Dec 2011 03:59:44 +0000
parents 3b5c14635553
children b5a03a336f63
files inst/isbw.m
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/inst/isbw.m
+++ b/inst/isbw.m
@@ -44,7 +44,7 @@
     bool = islogical (BW);
 
     ## the following block is just temporary to keep backwards compatibility
-    if (!islogical (BW) && all (all ((BW == 1) + (BW == 0))))
+    if (!islogical (BW) && is_bw_nonlogical (BW))
       persistent warned = false;
       if (! warned)
         warned = true;
@@ -56,7 +56,16 @@
     ## end of temporary block for backwards compatibility
 
   elseif (strcmpi (logic, "non-logical"))
-    bool = all (all ((BW == 1) + (BW == 0)));
+    ## to speed this up, we can look at a sample of the image first
+    bool = is_bw_nonlogical (BW(1:ceil (rows (BW) /100), 1:ceil (columns (BW) /100)));
+      if (bool)
+        ## sample was true, we better make sure it's real
+        bool = is_bw_nonlogical (BW);
+      endif
   endif
 
 endfunction
+
+function bool = is_bw_nonlogical (BW)
+  bool = all (all ((BW == 1) + (BW == 0)));
+endfunction