From: <car...@us...> - 2012-04-11 18:30:33
|
Revision: 10197 http://octave.svn.sourceforge.net/octave/?rev=10197&view=rev Author: carandraug Date: 2012-04-11 18:30:27 +0000 (Wed, 11 Apr 2012) Log Message: ----------- im2single: new function for image package Modified Paths: -------------- trunk/octave-forge/main/image/NEWS trunk/octave-forge/main/image/inst/im2double.m Added Paths: ----------- trunk/octave-forge/main/image/inst/im2single.m Modified: trunk/octave-forge/main/image/NEWS =================================================================== --- trunk/octave-forge/main/image/NEWS 2012-04-11 18:23:09 UTC (rev 10196) +++ trunk/octave-forge/main/image/NEWS 2012-04-11 18:30:27 UTC (rev 10197) @@ -6,6 +6,7 @@ blockproc bwlabeln getrangefromclass + im2single imabsdiff imadd imbothat Modified: trunk/octave-forge/main/image/inst/im2double.m =================================================================== --- trunk/octave-forge/main/image/inst/im2double.m 2012-04-11 18:23:09 UTC (rev 10196) +++ trunk/octave-forge/main/image/inst/im2double.m 2012-04-11 18:30:27 UTC (rev 10197) @@ -41,6 +41,10 @@ ## Input checking (private function that is used for all im2class functions) im_class = imconversion (nargin, "im2double", indexed, im); + ## READ BEFORE MAKE CHANGES: + ## this function is pretty much the same as im2single. Any changes on this code + ## should most likely also be done there + switch im_class case "double" ## do nothing, return the same Added: trunk/octave-forge/main/image/inst/im2single.m =================================================================== --- trunk/octave-forge/main/image/inst/im2single.m (rev 0) +++ trunk/octave-forge/main/image/inst/im2single.m 2012-04-11 18:30:27 UTC (rev 10197) @@ -0,0 +1,68 @@ +## Copyright (C) 2012 Carn\xEB Draug <car...@gm...> +## +## 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} = im2single (@var{im1}) +## @deftypefnx {Function File} @var{im2} = im2single (@var{im1}, "indexed") +## Convert input image @var{im1} to single precision. +## +## The following images type are supported: double, single, uint8, uint16, int16, +## binary (logical), indexed. If @var{im1} is an indexed images, the second +## argument must be a string with the value `indexed'. +## +## Processing will depend on the class of the input image @var{im1}: +## @itemize @bullet +## @item uint8, uint16, int16 - output will be rescaled for the interval [0 1] +## with the limits of the class; +## @item single - output will be the same as input; +## @item double - output will have the same values as input but the class will +## single; +## @item indexed, logical - converted to single class. +## @end itemize +## +## @seealso{im2bw, im2uint16, im2uint8} +## @end deftypefn + +function im = im2single (im, indexed = false) + + ## Input checking (private function that is used for all im2class functions) + im_class = imconversion (nargin, "im2single", indexed, im); + + ## READ BEFORE MAKE CHANGES: + ## this function is pretty much the same as im2double. Any changes on this code + ## should most likely also be done there + + switch im_class + case "single" + ## do nothing, return the same + case {"logical", "double"} + im = single (im); + case {"uint8", "uint16"} + if (indexed) + im = single (im) + 1; + else + im = single (im) / single (intmax (im_class)); + endif + case "int16" + im = (single (im) + single (intmax (im_class)) + 1) / single (intmax ("uint16")); + otherwise + error ("unsupported image class %s", im_class); + endswitch +endfunction + +%!assert(im2single([1 2 3]), single([1 2 3])); # double returns the same +%!assert(im2single(uint8([0 255])), single([0 1])); # basic usage +%!assert(im2single(uint8([1 25]), "indexed"), single([2 26])); # test indexed +%!assert(im2single(int16([-32768 32768])), single([0 1])); # test signed integer This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |