Mercurial > forge
changeset 2765:d17da95fcf7a octave-forge
Compatibility changes
author | hauberg |
---|---|
date | Fri, 24 Nov 2006 16:33:11 +0000 |
parents | 4f9b59086fbf |
children | c52a5711da06 |
files | main/image/inst/isgray.m main/image/inst/rgb2gray.m |
diffstat | 2 files changed, 43 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/main/image/inst/isgray.m Fri Nov 24 11:55:54 2006 +0000 +++ b/main/image/inst/isgray.m Fri Nov 24 16:33:11 2006 +0000 @@ -16,8 +16,12 @@ ## -*- texinfo -*- ## @deftypefn {Function File} @var{bool}= isgray (@var{I}) -## returns true for an intensity image. All intensity values must -## be in the range [0,1]. +## returns true for an intensity image. An variable is a gray scale image +## if it is 2-dimensional matrix, and +## @itemize @bullet +## @item is of class double and all values are in the range [0, 1], or +## @item is of class uint8 or uint16. +## @end itemize ## @end deftypefn ## Author: Kai Habel <kai.habel@gmx.de> @@ -25,16 +29,18 @@ function bool = isgray (I) - bool = 0; - - if !(nargin == 1) - usage ("isgray(I)"); + if (nargin != 1) + print_usage (); endif - if (!is_matrix(I)) - return; + bool = false; + if (ismatrix(I) && ndims(I) == 2) + switch(class(I)) + case "double" + bool = all(I(:) >= 0 && I(:) <= 1); + case {"uint8", "uint16"} + bool = true; + endswitch endif - bool = all (all ((I >= 0) && (I <= 1))); - endfunction
--- a/main/image/inst/rgb2gray.m Fri Nov 24 11:55:54 2006 +0000 +++ b/main/image/inst/rgb2gray.m Fri Nov 24 16:33:11 2006 +0000 @@ -15,33 +15,42 @@ ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## -*- texinfo -*- -## @deftypefn {Function File} @var{I}= rgb2gray (@var{M}) -## converts a color map to a gray map. -## The RGB map is converted into the YIQ space of ntsc. The luminance -## value (Y) is taken to create a gray color map. +## @deftypefn {Function File} @var{gray}= rgb2gray (@var{rgb}) +## Converts an RGB image to a gray scale image, or a color map +## to a gray map. +## +## If the input is an RGB image, the conversion to a gray image +## is computed as the mean value of the color channels. +## +## If the input is a color map it is converted into the YIQ space +## of ntsc. The luminance value (Y) is taken to create a gray color map. ## R = G = B = Y ## @end deftypefn ## Author: Kai Habel <kai.habel@gmx.de> ## Date: 19. March 2000 -function graymap = rgb2gray (rgb) +function gray = rgb2gray (rgb) if (nargin != 1) - usage ("graymap = rgb2gray (map)"); + print_usage(); endif - msg = "rgb2gray: argument must be a matrix of size n x 3"; - if (! is_matrix (rgb)) - error (msg); + if (ismatrix (rgb) && ndims(rgb) == 2 && columns(rgb) == 3) + ntscmap = rgb2ntsc (rgb); + gray = ntscmap (:, 1) * ones (1, 3); + elseif (ismatrix(rgb) && ndims(rgb) == 3) + switch(class(rgb)) + case "double" + gray = mean(rgb,3); + case "uint8" + gray = uint8(mean(rgb,3)); + case "uint16" + gray = uint16(mean(rgb,3)); + otherwise + error("rgb2gray: unsupported class %s", class(rgb)); + endswitch + else + error("rgb2gray: the input must either be an RGB image or a color map"); endif - - nc = columns (rgb); - if (nc != 3) - error (msg); - endif - - ntscmap = rgb2ntsc (rgb); - - graymap = ntscmap (:, 1) * ones (1, 3); endfunction