changeset 10012:e61b0817b578 octave-forge

im2int16: new function for image package and updated list of functinos on seealso help text
author carandraug
date Wed, 11 Apr 2012 19:11:07 +0000
parents db7e79437688
children 14e7cf93112a
files main/image/NEWS main/image/inst/im2double.m main/image/inst/im2int16.m main/image/inst/im2single.m main/image/inst/im2uint16.m main/image/inst/im2uint8.m
diffstat 6 files changed, 71 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/main/image/NEWS	Wed Apr 11 18:30:27 2012 +0000
+++ b/main/image/NEWS	Wed Apr 11 19:11:07 2012 +0000
@@ -6,6 +6,7 @@
       blockproc
       bwlabeln
       getrangefromclass
+      im2int16
       im2single
       imabsdiff
       imadd
--- a/main/image/inst/im2double.m	Wed Apr 11 18:30:27 2012 +0000
+++ b/main/image/inst/im2double.m	Wed Apr 11 19:11:07 2012 +0000
@@ -33,7 +33,7 @@
 ## @item indexed, logical - converted to double class.
 ## @end itemize
 ##
-## @seealso{im2bw, im2uint16, im2uint8}
+## @seealso{im2bw, im2int16, im2single, im2uint8, im2uint16}
 ## @end deftypefn
 
 function im = im2double (im, indexed = false)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/image/inst/im2int16.m	Wed Apr 11 19:11:07 2012 +0000
@@ -0,0 +1,66 @@
+## Copyright (C) 2012 Carnė Draug <carandraug+dev@gmail.com>
+##
+## 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 3 of the License, 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 program; if not, see <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} @var{im2} = im2int16 (@var{im1})
+## Convert input image @var{im1} to int16 precision.
+##
+## The following images type are supported: double, single, uint8, uint16, int16,
+## binary (logical).
+##
+## Processing will depend on the class of the input image @var{im1}:
+## @itemize @bullet
+## @item int16 - returns the same as input
+## @item uint8, double, single, uint16, logical - output will be rescaled for the
+## interval of the uint16 class [0 65535]
+## @end itemize
+##
+## @seealso{im2bw, im2double, im2single, im2uint8, im2uint16}
+## @end deftypefn
+
+function im = im2int16 (im)
+
+  ## unlike the others for imconversion, this only accepts 1 argument so we check here
+  if (nargin != 1)
+    print_usage;
+  endif
+  ## Input checking (private function that is used for all im2class functions)
+  im_class = imconversion (nargin, "im2int16", false, im);
+
+  switch im_class
+    case "int16"
+      ## do nothing, return the same
+    case {"single", "double"}
+      im = int16 (double (im * intmax ("uint16")) - double (intmax ("int16")) - 1);
+    case "logical"
+      im(im)  = intmax ("int16");
+      im(!im) = intmin ("int16");
+    case "uint8"
+        ## 257 is the ratio between the max of uint8 and uint16
+        ## double (intmax ("uint16")) / double (intmax ("uint8")) == 257
+        im = int16 (double (257 * uint16 (im)) - double (intmax ("int16")) - 1);
+    case "uint16"
+      im = int16 (double (im) - double (intmax ("int16")) - 1);
+    otherwise
+      error ("unsupported image class %s", im_class);
+  endswitch
+
+endfunction
+
+%!assert(im2int16(int16([-2 2 3])), int16([-2 2 3]));           # uint16 returns the same
+%!assert(im2int16(uint8([0 255])), int16([-32768 32767]));      # basic usage with uint8
+%!assert(im2int16(uint16([0 65535])), int16([-32768 32767]));   # basic usage with uint16
+%!assert(im2int16([0 0.5 1]), int16([-32768 0 32767]));         # basic usage with double
+%!assert(im2int16([1 2]), int16([32767 32767]));                # for double, above 1 is same as 1
--- a/main/image/inst/im2single.m	Wed Apr 11 18:30:27 2012 +0000
+++ b/main/image/inst/im2single.m	Wed Apr 11 19:11:07 2012 +0000
@@ -32,7 +32,7 @@
 ## @item indexed, logical - converted to single class.
 ## @end itemize
 ##
-## @seealso{im2bw, im2uint16, im2uint8}
+## @seealso{im2bw, im2double, im2int16, im2uint8, im2uint16}
 ## @end deftypefn
 
 function im = im2single (im, indexed = false)
--- a/main/image/inst/im2uint16.m	Wed Apr 11 18:30:27 2012 +0000
+++ b/main/image/inst/im2uint16.m	Wed Apr 11 19:11:07 2012 +0000
@@ -32,7 +32,7 @@
 ## the max of the uint16 class (65535).
 ## @end itemize
 ##
-## @seealso{im2bw, im2double, im2uint8}
+## @seealso{im2bw, im2double, im2int16, im2single, im2uint8}
 ## @end deftypefn
 
 function im = im2uint16 (im, indexed = false)
--- a/main/image/inst/im2uint8.m	Wed Apr 11 18:30:27 2012 +0000
+++ b/main/image/inst/im2uint8.m	Wed Apr 11 19:11:07 2012 +0000
@@ -32,7 +32,7 @@
 ## the uint8 class (255).
 ## @end itemize
 ##
-## @seealso{im2bw, im2uint16, im2double}
+## @seealso{im2bw, im2double, im2int16, im2single, im2uint16}
 ## @end deftypefn
 
 function im = im2uint8 (im, indexed = false)