]> Creatis software - CreaPhase.git/blob - octave_packages/image-1.0.15/im2uint16.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / image-1.0.15 / im2uint16.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} = im2uint16(@var{im1})
18 ## Converts the input image to an image of class uint16.
19 ##
20 ## If the input image is of class uint16 the output is unchanged.
21 ## If the input is of class uint8 the result will be converted to uint16
22 ## and multiplied by 257, and if the input is of class double the image will
23 ## be multiplied by 65535 and converted to uint16.
24 ## @seealso{im2bw, im2double, im2uint8}
25 ## @end deftypefn
26
27 function im2 = im2uint16(im1)
28   ## Input checking
29   if (nargin < 1)
30     print_usage();
31   endif
32   if (!isgray(im1) && !isrgb(im1))
33     error("im2uint16: 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 = uint16(65535*im1);
40     case "uint8"
41       im2 = 257*uint16(im1);
42     case "uint16"
43       im2 = im1;
44     otherwise
45       error("im2uint16: unsupported image class");
46   endswitch
47 endfunction