]> Creatis software - CreaPhase.git/blob - octave_packages/image-1.0.15/isgray.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / image-1.0.15 / isgray.m
1 ## Copyright (C) 2000  Kai Habel
2 ##
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.
7 ##
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.
12 ##
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/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Function File} @var{bool}= isgray (@var{I})
18 ## Returns true for an gray-scale intensity image. An variable is a gray scale image
19 ## if it is 2-dimensional matrix, and
20 ## @itemize @bullet
21 ## @item is of class double and all values are in the range [0, 1], or
22 ## @item is of class uint8 or uint16.
23 ## @end itemize
24 ## @end deftypefn
25
26 ## Author:      Kai Habel <kai.habel@gmx.de>
27 ## Date:        20/03/2000
28
29 function bool = isgray (I)
30
31   if (nargin != 1)
32     print_usage ();
33   endif
34
35   bool = false;
36   if (ismatrix(I) && ndims(I) == 2)
37     switch(class(I))
38     case "double"
39       bool = all((I(:) >= 0 & I(:) <= 1) | isnan(I(:)));
40     case {"uint8", "uint16"}
41       bool = true;
42     endswitch
43   endif
44
45 endfunction