1 ## Copyright (C) 2004 Josep Mones i Teixidor
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ## GNU General Public License for more details.
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {@var{flag} = } isrgb (@var{A})
18 ## Returns true if parameter is a RGB image.
20 ## @code{flag=isrgb(A)} returns 1 if @var{A} is a RGB image and 0 if
23 ## To the decide @code{isrgb} uses the follow algorithm:
26 ## If @var{A} is of class double then it checks if all values are
27 ## between 0 and 1, and if size is m-by-n-by-3.
29 ## If @var{A} is of class uint16, uint8 or logical then it checks is m-by-n-by-3.
32 ## @strong{Compatibility notes:}
34 ## Information needed on whether MATLAB accepts logical arrays as RGB
35 ## images (now this functions accepts them if they are m-by-n-by-3 arrays.
39 ## TODO: Check if logical arrays should be considered RGB
41 ## Author: Josep Mones i Teixidor <jmones@puntbarra.com>
43 function flag = isrgb(A)
45 usage("flag=isrgb(A)");
51 if(length(s)!=3 || s(3)!=3)
52 flag=0; ## false if not m-by-n-by-3
53 elseif(strcmp(typeinfo(A),"matrix") && (any(A(:)<0) || any(A(:)>1)))
54 flag=0; ## false if class double but items are <0 or >1
64 %! # A 1-by-2-by-3 double matrix with elements between 0 and 1 is a RGB image.
68 %!assert(isrgb("this is not a RGB image"),0);
70 %!# Double matrix tests
71 %!assert(isrgb(rand(5,5)),0);
72 %!assert(isrgb(rand(5,5,1,5)),0);
73 %!assert(isrgb(rand(5,5,3,5)),0);
74 %!assert(isrgb(rand(5,5,3)),1);
75 %!assert(isrgb(ones(5,5,3)),1);
76 %!assert(isrgb(ones(5,5,3)+.0001),0);
77 %!assert(isrgb(zeros(5,5,3)-.0001),0);
80 %!assert(isrgb(logical(round(rand(5,5,3)))),1);