From: <car...@us...> - 2011-12-05 04:41:06
|
Revision: 9270 http://octave.svn.sourceforge.net/octave/?rev=9270&view=rev Author: carandraug Date: 2011-12-05 04:40:59 +0000 (Mon, 05 Dec 2011) Log Message: ----------- isind: * big rewrite of function based on code from isgray * now returns false if argument is empty matrix * improved help text * upgrade license to GPLv3+ Modified Paths: -------------- trunk/octave-forge/main/image/inst/isind.m Modified: trunk/octave-forge/main/image/inst/isind.m =================================================================== --- trunk/octave-forge/main/image/inst/isind.m 2011-12-05 04:20:50 UTC (rev 9269) +++ trunk/octave-forge/main/image/inst/isind.m 2011-12-05 04:40:59 UTC (rev 9270) @@ -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,26 +15,49 @@ ## along with this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} @var{bool}= isind (@var{X}) -## Returns true for an index image. All index values must -## be intergers and greater than or equal to 1. +## @deftypefn {Function File} @var{bool} = isind (@var{img}) +## Return true if @var{img} is a RGB image. +## +## A variable is considereed to be an indexed image if it is 2-dimensional, +## non-sparse matrix and: +## @itemize @bullet +## @item is of class double and all values are integers greater than or equal to 1; +## @item is of class uint8 or uint16. +## @end itemize +## +## Note that indexed time-series image have 4 dimensions (NxMx1xtime) but +## isind will still return false. +## @seealso{isbw, isgray, isrgb} ## @end deftypefn -## Author: Kai Habel <kai...@gm...> -## Date: 20/03/2000 +function bool = isind (img) -function ret = isind (X) + if (nargin != 1) + print_usage; + endif - if nargin != 1 - usage ("isind(X)"); + bool = false; + if (ismatrix (img) && ndims (img) == 2 && !issparse (img) && isreal (img) && !isempty (img)) + switch (class (img)) + case "double" + ## to speed this up, we can look at a sample of the image first + bool = is_ind_double (img(1:ceil (rows (img) /100), 1:ceil (columns (img) /100))); + if (bool) + ## sample was true, we better make sure it's real + bool = is_ind_double (img); + endif + case {"uint8", "uint16"} + bool = true; + endswitch endif - ret = isreal (X) && length (size (X)) == 2 ... - && all ( X(:) == floor (X(:)) ) && all ( X(:) >= 1 ); +endfunction +function bool = is_ind_double (img) + bool = all (img(:) == fix (img(:))) && all (img(:) >= 1); endfunction -%!assert(isind([])) +%!fail(isind([])) ## should fail for empty matrix %!assert(isind(1:10)) %!assert(!isind(0:10)) %!assert(isind(1)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |