X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=octave_packages%2Fimage-1.0.15%2Fisrgb.m;fp=octave_packages%2Fimage-1.0.15%2Fisrgb.m;h=887077a1b1761dfd6286242232946cfa9fb2d64b;hb=f5f7a74bd8a4900f0b797da6783be80e11a68d86;hp=0000000000000000000000000000000000000000;hpb=1705066eceaaea976f010f669ce8e972f3734b05;p=CreaPhase.git diff --git a/octave_packages/image-1.0.15/isrgb.m b/octave_packages/image-1.0.15/isrgb.m new file mode 100644 index 0000000..887077a --- /dev/null +++ b/octave_packages/image-1.0.15/isrgb.m @@ -0,0 +1,80 @@ +## Copyright (C) 2004 Josep Mones i Teixidor +## +## 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 +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; If not, see . + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{flag} = } isrgb (@var{A}) +## Returns true if parameter is a RGB image. +## +## @code{flag=isrgb(A)} returns 1 if @var{A} is a RGB image and 0 if +## not. +## +## To the decide @code{isrgb} uses the follow algorithm: +## @itemize @bullet +## @item +## If @var{A} is of class double then it checks if all values are +## between 0 and 1, and if size is m-by-n-by-3. +## @item +## If @var{A} is of class uint16, uint8 or logical then it checks is m-by-n-by-3. +## @end itemize +## +## @strong{Compatibility notes:} +## +## Information needed on whether MATLAB accepts logical arrays as RGB +## images (now this functions accepts them if they are m-by-n-by-3 arrays. +## +## @end deftypefn + +## TODO: Check if logical arrays should be considered RGB + +## Author: Josep Mones i Teixidor + +function flag = isrgb(A) + if (nargin!=1) + usage("flag=isrgb(A)"); + endif + + if(ismatrix(A)) + flag=1; + s=size(A); + if(length(s)!=3 || s(3)!=3) + flag=0; ## false if not m-by-n-by-3 + elseif(strcmp(typeinfo(A),"matrix") && (any(A(:)<0) || any(A(:)>1))) + flag=0; ## false if class double but items are <0 or >1 + endif + else + flag=0; + endif +endfunction + + +%!demo +%! isrgb(rand(1,2,3)) +%! # A 1-by-2-by-3 double matrix with elements between 0 and 1 is a RGB image. + + +%!# Non-matrix +%!assert(isrgb("this is not a RGB image"),0); + +%!# Double matrix tests +%!assert(isrgb(rand(5,5)),0); +%!assert(isrgb(rand(5,5,1,5)),0); +%!assert(isrgb(rand(5,5,3,5)),0); +%!assert(isrgb(rand(5,5,3)),1); +%!assert(isrgb(ones(5,5,3)),1); +%!assert(isrgb(ones(5,5,3)+.0001),0); +%!assert(isrgb(zeros(5,5,3)-.0001),0); + +%!# Logical +%!assert(isrgb(logical(round(rand(5,5,3)))),1);