1## Copyright (C) 2000 Kai Habel <kai.habel@gmx.de> 2## Copyright (C) 2011, 2015 Carnë Draug <carandraug+dev@gmail.com> 3## 4## This program is free software; you can redistribute it and/or modify 5## it under the terms of the GNU General Public License as published by 6## the Free Software Foundation; either version 3 of the License, or 7## (at your option) any later version. 8## 9## This program is distributed in the hope that it will be useful, 10## but WITHOUT ANY WARRANTY; without even the implied warranty of 11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12## GNU General Public License for more details. 13## 14## You should have received a copy of the GNU General Public License 15## along with this program; if not, see <http://www.gnu.org/licenses/>. 16 17## -*- texinfo -*- 18## @deftypefn {Function File} {} isind (@var{img}) 19## Return true if @var{img} is an indexed image. 20## 21## A variable can be considered an indexed image if it is a non-sparse, 22## real array of size @nospell{MxNx1xK}, and: 23## 24## @itemize @bullet 25## @item of class double with all integers above zero; 26## @item of class uint8 or uint16. 27## @end itemize 28## 29## @emph{Note}: despite their suggestive names, the functions isbw, 30## isgray, isind, and isrgb, are ambiguous since it is not always possible 31## to distinguish between those image types. For example: an uint8 matrix 32## can be both a grayscale and indexed image; a grayscale image may have 33## values outside the range [0 1]. They are good to dismiss input as an 34## invalid image type, but not for identification. 35## 36## @seealso{ind2gray, ind2rgb, isbw, isgray, isindex, isrgb} 37## @end deftypefn 38 39function bool = isind (img) 40 41 if (nargin != 1) 42 print_usage; 43 endif 44 45 bool = false; 46 if (isimage (img) && ndims (img) < 5 && size (img, 3) == 1) 47 if (isfloat (img)) 48 bool = isindex (img); 49 elseif (any (isa (img, {"uint8", "uint16"}))) 50 bool = true; 51 endif 52 endif 53 54endfunction 55 56%!assert (isind ([]), false); 57%!assert (isind (1:10), true); 58%!assert (isind (0:10), false); 59%!assert (isind (1), true); 60%!assert (isind (0), false); 61%!assert (isind ([1.3 2.4]), false); 62%!assert (isind ([1 2; 3 4]), true); 63%!assert (isind (randi (100, 10, 10, 1, 4)), true); 64%!assert (isind (randi (100, 10, 10, 3, 4)), false); 65%!assert (isind (randi (100, 10, 10, 1, 4, 2)), false); 66