comparison inst/isbw.m @ 507:a60411e31d36

isbw: check sample of image first to speed up computation
author carandraug
date Mon, 05 Dec 2011 03:59:44 +0000
parents 5dd8356bd17c
children 9135e5461550
comparison
equal deleted inserted replaced
506:3b5c14635553 507:a60411e31d36
42 elseif (strcmpi (logic, "logical")) 42 elseif (strcmpi (logic, "logical"))
43 ## this is the matlab compatible way (before they removed the function) 43 ## this is the matlab compatible way (before they removed the function)
44 bool = islogical (BW); 44 bool = islogical (BW);
45 45
46 ## the following block is just temporary to keep backwards compatibility 46 ## the following block is just temporary to keep backwards compatibility
47 if (!islogical (BW) && all (all ((BW == 1) + (BW == 0)))) 47 if (!islogical (BW) && is_bw_nonlogical (BW))
48 persistent warned = false; 48 persistent warned = false;
49 if (! warned) 49 if (! warned)
50 warned = true; 50 warned = true;
51 warning ("isbw: image is not logical matrix and therefore not binary but all values are either 0 and 1.") 51 warning ("isbw: image is not logical matrix and therefore not binary but all values are either 0 and 1.")
52 warning ("isbw: future versions of this function will return true. Consider using the call isbw (img, \"non-logical\").") 52 warning ("isbw: future versions of this function will return true. Consider using the call isbw (img, \"non-logical\").")
54 bool = true; 54 bool = true;
55 endif 55 endif
56 ## end of temporary block for backwards compatibility 56 ## end of temporary block for backwards compatibility
57 57
58 elseif (strcmpi (logic, "non-logical")) 58 elseif (strcmpi (logic, "non-logical"))
59 bool = all (all ((BW == 1) + (BW == 0))); 59 ## to speed this up, we can look at a sample of the image first
60 bool = is_bw_nonlogical (BW(1:ceil (rows (BW) /100), 1:ceil (columns (BW) /100)));
61 if (bool)
62 ## sample was true, we better make sure it's real
63 bool = is_bw_nonlogical (BW);
64 endif
60 endif 65 endif
61 66
62 endfunction 67 endfunction
68
69 function bool = is_bw_nonlogical (BW)
70 bool = all (all ((BW == 1) + (BW == 0)));
71 endfunction