changeset 233:43491fb0ef0d

New functions: im2double, im2uint8, and im2uint16
author hauberg
date Sun, 14 Jan 2007 18:48:54 +0000
parents 25e4c5428492
children fef531f1e536
files INDEX inst/im2double.m inst/im2uint16.m inst/im2uint8.m
diffstat 4 files changed, 147 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/INDEX
+++ b/INDEX
@@ -70,6 +70,9 @@
  gray2ind 
  grayslice 
  im2bw 
+ im2double
+ im2uint8
+ im2uint16
  ind2gray 
  ind2rgb 
  isbw 
new file mode 100644
--- /dev/null
+++ b/inst/im2double.m
@@ -0,0 +1,48 @@
+## Copyright (C) 2007  Søren Hauberg
+## 
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+## 
+## This program is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details. 
+## 
+## You should have received a copy of the GNU General Public License
+## along with this file.  If not, write to the Free Software Foundation,
+## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} @var{im2} = im2double(@var{im1})
+## Converts the input image to an image of class double.
+##
+## If the input image is of class double the output is unchanged.
+## If the input is of class uint8 the result will be converted to doubles
+## and divided by 255, and if the input is of class uint16 the image will
+## be converted to doubles and divided by 65535.
+## @seealso{im2bw, im2uint16, im2uint8}
+## @end deftypefn
+
+function im2 = im2double(im1)
+  ## Input checking
+  if (nargin < 1)
+    print_usage();
+  endif
+  if (!isgray(im1) && !isrgb(im1))
+    error("im2double: input must be an image");
+  endif
+  
+  ## Take action depending on the class of the data
+  switch (class(im1))
+    case "double"
+      im2 = im1;
+    case "uint8"
+      im2 = double(im1)/255;
+    case "uint16"
+      im2 = double(im1)(pow2(16)-1);
+    otherwise
+      error("im2double: unsupported image class");
+  endswitch
+endfunction
new file mode 100644
--- /dev/null
+++ b/inst/im2uint16.m
@@ -0,0 +1,48 @@
+## Copyright (C) 2007  Søren Hauberg
+## 
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+## 
+## This program is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details. 
+## 
+## You should have received a copy of the GNU General Public License
+## along with this file.  If not, write to the Free Software Foundation,
+## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} @var{im2} = im2uint16(@var{im1})
+## Converts the input image to an image of class uint16.
+##
+## If the input image is of class uint16 the output is unchanged.
+## If the input is of class uint8 the result will be converted to uint16
+## and multiplied by 257, and if the input is of class double the image will
+## be multiplied by 65535 and converted to uint16.
+## @seealso{im2bw, im2double, im2uint8}
+## @end deftypefn
+
+function im2 = im2uint16(im1)
+  ## Input checking
+  if (nargin < 1)
+    print_usage();
+  endif
+  if (!isgray(im1) && !isrgb(im1))
+    error("im2uint16: input must be an image");
+  endif
+  
+  ## Take action depending on the class of the data
+  switch (class(im1))
+    case "double"
+      im2 = uint16(65535*im1);
+    case "uint8"
+      im2 = 257*uint16(im1);
+    case "uint16"
+      im2 = im1;
+    otherwise
+      error("im2uint16: unsupported image class");
+  endswitch
+endfunction
new file mode 100644
--- /dev/null
+++ b/inst/im2uint8.m
@@ -0,0 +1,48 @@
+## Copyright (C) 2007  Søren Hauberg
+## 
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+## 
+## This program is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details. 
+## 
+## You should have received a copy of the GNU General Public License
+## along with this file.  If not, write to the Free Software Foundation,
+## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} @var{im2} = im2uint8(@var{im1})
+## Converts the input image to an image of class uint8.
+##
+## If the input image is of class uint8 the output is unchanged.
+## If the input is of class double the result will be multiplied
+## by 255 and converted to uint8, and if the input is of class uint16 the
+## image will be divided by 257 and converted to uint8.
+## @seealso{im2bw, im2uint16, im2double}
+## @end deftypefn
+
+function im2 = im2uint8(im1)
+  ## Input checking
+  if (nargin < 1)
+    print_usage();
+  endif
+  if (!isgray(im1) && !isrgb(im1))
+    error("im2uint8: input must be an image");
+  endif
+  
+  ## Take action depending on the class of the data
+  switch (class(im1))
+    case "double"
+      im2 = uint8(255*im1);
+    case "uint8"
+      im2 = im1;
+    case "uint16"
+      im2 = uint8(im1/257);
+    otherwise
+      error("im2uint8: unsupported image class");
+  endswitch
+endfunction