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