1 ## Copyright (C) 2007 Søren Hauberg
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)
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.
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/>.
17 ## @deftypefn {Function File} @var{im2} = im2double(@var{im1})
18 ## Converts the input image to an image of class double.
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}
27 function im2 = im2double(im1)
32 if (!isgray(im1) && !isrgb(im1))
33 error("im2double: input must be an image");
36 ## Take action depending on the class of the data
41 im2 = double(im1) / 255;
43 im2 = double(im1) / (pow2(16)-1);
45 error("im2double: unsupported image class");