]> Creatis software - CreaPhase.git/blob - octave_packages/image-1.0.15/im2uint8.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / image-1.0.15 / im2uint8.m
1 ## Copyright (C) 2007  Søren Hauberg
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, or (at your option)
6 ## any later version.
7 ## 
8 ## This program is distributed in the hope that it will be useful, but
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 ## General Public License for more details. 
12 ## 
13 ## You should have received a copy of the GNU General Public License
14 ## along with this file.  If not, see <http://www.gnu.org/licenses/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Function File} @var{im2} = im2uint8(@var{im1})
18 ## Converts the input image to an image of class uint8.
19 ##
20 ## If the input image is of class uint8 the output is unchanged.
21 ## If the input is of class double the result will be multiplied
22 ## by 255 and converted to uint8, and if the input is of class uint16 the
23 ## image will be divided by 257 and converted to uint8.
24 ## @seealso{im2bw, im2uint16, im2double}
25 ## @end deftypefn
26
27 function im2 = im2uint8(im1)
28   ## Input checking
29   if (nargin < 1)
30     print_usage();
31   endif
32   if (!isgray(im1) && !isrgb(im1))
33     error("im2uint8: input must be an image");
34   endif
35   
36   ## Take action depending on the class of the data
37   switch (class(im1))
38     case "double"
39       im2 = uint8(255*im1);
40     case "uint8"
41       im2 = im1;
42     case "uint16"
43       im2 = uint8(im1/257);
44     otherwise
45       error("im2uint8: unsupported image class");
46   endswitch
47 endfunction