From: <ha...@us...> - 2010-04-14 22:53:19
|
Revision: 7196 http://octave.svn.sourceforge.net/octave/?rev=7196&view=rev Author: hauberg Date: 2010-04-14 22:53:13 +0000 (Wed, 14 Apr 2010) Log Message: ----------- Add missing division (/) (from Sean Veers) Modified Paths: -------------- trunk/octave-forge/main/image/inst/im2double.m Modified: trunk/octave-forge/main/image/inst/im2double.m =================================================================== --- trunk/octave-forge/main/image/inst/im2double.m 2010-04-14 21:25:13 UTC (rev 7195) +++ trunk/octave-forge/main/image/inst/im2double.m 2010-04-14 22:53:13 UTC (rev 7196) @@ -38,9 +38,9 @@ case "double" im2 = im1; case "uint8" - im2 = double(im1)/255; + im2 = double(im1) / 255; case "uint16" - im2 = double(im1)(pow2(16)-1); + im2 = double(im1) / (pow2(16)-1); otherwise error("im2double: unsupported image class"); endswitch This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-04-11 15:22:30
|
Revision: 10191 http://octave.svn.sourceforge.net/octave/?rev=10191&view=rev Author: carandraug Date: 2012-04-11 15:22:19 +0000 (Wed, 11 Apr 2012) Log Message: ----------- im2double: added support for indexed images and matlab compatibility Modified Paths: -------------- trunk/octave-forge/main/image/inst/im2double.m Modified: trunk/octave-forge/main/image/inst/im2double.m =================================================================== --- trunk/octave-forge/main/image/inst/im2double.m 2012-04-11 14:57:31 UTC (rev 10190) +++ trunk/octave-forge/main/image/inst/im2double.m 2012-04-11 15:22:19 UTC (rev 10191) @@ -1,48 +1,69 @@ -## Copyright (C) 2007 S\xF8ren 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, see <http://www.gnu.org/licenses/>. +## Copyright (C) 2007 S\xF8ren Hauberg <so...@ha...> +## 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} = im2double(@var{im1}) -## Converts the input image to an image of class double. +## @deftypefnx {Function File} @var{im2} = im2double(@var{im1}, "indexed") +## Convert input image @var{im1} to double precision. ## -## 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. +## 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 double - output will be the same as input; +## @item single - output will have the same values as input but the class will +## double; +## @item indexed, logical - converted to double class. +## @end itemize +## ## @seealso{im2bw, im2uint16, im2uint8} ## @end deftypefn -function im2 = im2double(im1) +function im2 = im2double (im1, ind = false) ## Input checking - if (nargin < 1) - print_usage(); - elseif (!isgray(im1) && !isrgb(im1) && !isbw(im1)) - error("im2double: input must be an image"); + if (nargin < 1 || nargin > 2) + print_usage; + elseif (nargin == 2 && (!ischar (ind) || !strcmpi (ind, "indexed"))) + error ("second argument must be a string with the word `indexed'"); endif + if (ind && !isind (im1)) + error ("input should have been an indexed image but it is not"); + endif + ## Take action depending on the class of the data - switch (class(im1)) + in_class = class (im1); + switch in_class case "double" im2 = im1; - case "logical" - im2 = double(im1); - case "uint8" - im2 = double(im1) / 255; - case "uint16" - im2 = double(im1) / (pow2(16)-1); + case {"logical", "single"} + im2 = double (im1); + case {"uint8", "uint16"} + if (ind) + im2 = double (im1) + 1; + elseif (isind (im1)) + im2 = double (im1) / double (intmax (in_class)); + endif + case "int16" + im2 = (double (im1) + double (intmax (in_class)) + 1) / double (intmax ("uint16")); otherwise - error("im2double: unsupported image class"); + error ("unsupported image class"); endswitch endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-04-11 16:45:52
|
Revision: 10192 http://octave.svn.sourceforge.net/octave/?rev=10192&view=rev Author: carandraug Date: 2012-04-11 16:45:41 +0000 (Wed, 11 Apr 2012) Log Message: ----------- im2double: added tests Modified Paths: -------------- trunk/octave-forge/main/image/inst/im2double.m Modified: trunk/octave-forge/main/image/inst/im2double.m =================================================================== --- trunk/octave-forge/main/image/inst/im2double.m 2012-04-11 15:22:19 UTC (rev 10191) +++ trunk/octave-forge/main/image/inst/im2double.m 2012-04-11 16:45:41 UTC (rev 10192) @@ -67,3 +67,8 @@ error ("unsupported image class"); endswitch endfunction + +%!assert(im2double([1 2 3]), [1 2 3]); # double returns the same +%!assert(im2double(uint8([0 255])), [0 1]); # basic usage +%!assert(im2double(uint8([1 25]), "indexed"), [2 26]); # test indexed +%!assert(im2double(int16([-32768 32768])), [0 1]); # test signed integer This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-04-11 17:13:38
|
Revision: 10194 http://octave.svn.sourceforge.net/octave/?rev=10194&view=rev Author: carandraug Date: 2012-04-11 17:13:27 +0000 (Wed, 11 Apr 2012) Log Message: ----------- im2double: fix small bug where isind would be called wrongly Modified Paths: -------------- trunk/octave-forge/main/image/inst/im2double.m Modified: trunk/octave-forge/main/image/inst/im2double.m =================================================================== --- trunk/octave-forge/main/image/inst/im2double.m 2012-04-11 17:01:36 UTC (rev 10193) +++ trunk/octave-forge/main/image/inst/im2double.m 2012-04-11 17:13:27 UTC (rev 10194) @@ -36,10 +36,10 @@ ## @seealso{im2bw, im2uint16, im2uint8} ## @end deftypefn -function im = im2double (im, ind = false) +function im = im2double (im, indexed = false) ## Input checking (private function that is used for all im2class functions) - im_class = imconversion (nargin, "im2double", ind, im); + im_class = imconversion (nargin, "im2double", indexed, im); switch im_class case "double" @@ -47,9 +47,9 @@ case {"logical", "single"} im = double (im); case {"uint8", "uint16"} - if (ind) + if (indexed) im = double (im) + 1; - elseif (isind (im)) + else im = double (im) / double (intmax (im_class)); endif case "int16" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |