From: <car...@us...> - 2011-12-05 00:47:26
|
Revision: 9262 http://octave.svn.sourceforge.net/octave/?rev=9262&view=rev Author: carandraug Date: 2011-12-05 00:47:20 +0000 (Mon, 05 Dec 2011) Log Message: ----------- isbw: IMPORTANT COMMIT BREAKS COMPATIBILITY * isbw is now matlab compatible and returns true if image is logical, non sparse matrix * new option `non-logical' was added to return to old behaviour * new help text to reflect changes * upgrade license to GPLv3+ Modified Paths: -------------- trunk/octave-forge/main/image/inst/isbw.m Modified: trunk/octave-forge/main/image/inst/isbw.m =================================================================== --- trunk/octave-forge/main/image/inst/isbw.m 2011-12-04 19:25:51 UTC (rev 9261) +++ trunk/octave-forge/main/image/inst/isbw.m 2011-12-05 00:47:20 UTC (rev 9262) @@ -1,8 +1,9 @@ -## Copyright (C) 2000 Kai Habel +## Copyright (C) 2000 Kai Habel <kai...@gm...> +## Copyright (C) 2011 Carnë Draug <car...@gm...> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or +## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, @@ -14,25 +15,45 @@ ## along with this program; If not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} @var{bool}= isbw (@var{BW}) -## Returns true for a black-white (binary) image. -## All values must be either 0 or 1 +## @deftypefn {Function File} @var{bool} = isbw (@var{img}) +## @deftypefnx {Function File} @var{bool} = isbw (@var{img}, @var{logic}) +## Return true if @var{img} is a black-white image. +## +## The optional argument @var{logic} must be the string `logical' or +## `non-logical'. The first defines a black and white image as a logical matrix, +## while the second defines it as a matrix comprised of the values 1 and 0 +## only. Defaults to `logical'. +## +## @seealso{isgray, isind, islogical, isrgb} ## @end deftypefn -## Author: Kai Habel <kai...@gm...> -## Date: 20/03/2000 +function bool = isbw (BW, logic = "logical") + ## this function has been removed from version 7.3 (R2011b) of + ## matlab's image processing toolbox + if (nargin < 1 || nargin > 2) + print_usage; + elseif (!ischar (logic) && any (strcmpi (logic, {"logical", "non-logical"}))) + error ("second argument must either be a string 'logical' or 'non-logical'") + endif -function bool = isbw (BW) + ## an image cannot be a sparse matrix + if (!ismatrix (BW) || issparse (BW)) + bool = false; + elseif (strcmpi (logic, "logical")) + ## this is the matlab compatible way (before they removed the function) + bool = islogical (BW); - bool = 0; - if !(nargin == 1) - usage ("isbw(BW)"); - endif + ## the following block is just temporary since we are not being backwards compatible + if (!islogical (BW) && all (all ((BW == 1) + (BW == 0)))) + persistent warned = false; + if (! warned) + warned = true; + warning ("isbw: image is not logical matrix and therefore not binary but all values are either 0 and 1.") + warning ("isbw: old versions of the function would return true. Use the call isbw (img, \"non-logical\") instead.") + endif + endif - if !(ismatrix(BW)) - return; + elseif (strcmpi (logic, "non-logical")) + bool = all (all ((BW == 1) + (BW == 0))); endif - - bool = all (all ((BW == 1) + (BW == 0))); - endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2011-12-05 00:53:14
|
Revision: 9263 http://octave.svn.sourceforge.net/octave/?rev=9263&view=rev Author: carandraug Date: 2011-12-05 00:53:07 +0000 (Mon, 05 Dec 2011) Log Message: ----------- isbw: made function still return true for non-logical matrix of 1 and 0 but issue warning. This will be changed again in future Modified Paths: -------------- trunk/octave-forge/main/image/inst/isbw.m Modified: trunk/octave-forge/main/image/inst/isbw.m =================================================================== --- trunk/octave-forge/main/image/inst/isbw.m 2011-12-05 00:47:20 UTC (rev 9262) +++ trunk/octave-forge/main/image/inst/isbw.m 2011-12-05 00:53:07 UTC (rev 9263) @@ -43,17 +43,20 @@ ## this is the matlab compatible way (before they removed the function) bool = islogical (BW); - ## the following block is just temporary since we are not being backwards compatible + ## the following block is just temporary to keep backwards compatibility if (!islogical (BW) && all (all ((BW == 1) + (BW == 0)))) persistent warned = false; if (! warned) warned = true; warning ("isbw: image is not logical matrix and therefore not binary but all values are either 0 and 1.") - warning ("isbw: old versions of the function would return true. Use the call isbw (img, \"non-logical\") instead.") + warning ("isbw: future versions of this function will return true. Consider using the call isbw (img, \"non-logical\").") endif + bool = true; endif + ## end of temporary block for backwards compatibility elseif (strcmpi (logic, "non-logical")) bool = all (all ((BW == 1) + (BW == 0))); endif + endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2011-12-05 03:59:50
|
Revision: 9267 http://octave.svn.sourceforge.net/octave/?rev=9267&view=rev Author: carandraug Date: 2011-12-05 03:59:44 +0000 (Mon, 05 Dec 2011) Log Message: ----------- isbw: check sample of image first to speed up computation Modified Paths: -------------- trunk/octave-forge/main/image/inst/isbw.m Modified: trunk/octave-forge/main/image/inst/isbw.m =================================================================== --- trunk/octave-forge/main/image/inst/isbw.m 2011-12-05 01:22:06 UTC (rev 9266) +++ trunk/octave-forge/main/image/inst/isbw.m 2011-12-05 03:59:44 UTC (rev 9267) @@ -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 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-09-02 02:33:20
|
Revision: 10942 http://octave.svn.sourceforge.net/octave/?rev=10942&view=rev Author: carandraug Date: 2012-09-02 02:33:14 +0000 (Sun, 02 Sep 2012) Log Message: ----------- isbw: fix bug when input image has more than 2D. Modified Paths: -------------- trunk/octave-forge/main/image/inst/isbw.m Modified: trunk/octave-forge/main/image/inst/isbw.m =================================================================== --- trunk/octave-forge/main/image/inst/isbw.m 2012-09-02 02:31:53 UTC (rev 10941) +++ trunk/octave-forge/main/image/inst/isbw.m 2012-09-02 02:33:14 UTC (rev 10942) @@ -62,7 +62,7 @@ endfunction function bool = is_bw_nonlogical (BW) - bool = all (all ((BW == 1) + (BW == 0))); + bool = all ((BW == 1)(:) + (BW == 0)(:)); endfunction %!shared a This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |