Mercurial > hg > octave-image
changeset 606:20f20769cd9f
rgb2gray: use isimage and iscolormap function
author | carandraug |
---|---|
date | Mon, 24 Sep 2012 14:57:19 +0000 |
parents | 764d78294156 |
children | dde719c94995 |
files | inst/rgb2gray.m |
diffstat | 1 files changed, 5 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/inst/rgb2gray.m +++ b/inst/rgb2gray.m @@ -15,8 +15,7 @@ ## -*- texinfo -*- ## @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. +## Convert RGB image or colormap to a grayscale. ## ## If the input is an RGB image, the conversion to a gray image ## is computed as the mean value of the color channels. @@ -32,10 +31,10 @@ print_usage(); endif - if (ismatrix (rgb) && ndims(rgb) == 2 && columns(rgb) == 3) + if (iscolormap (rgb)) ntscmap = rgb2ntsc (rgb); - gray = ntscmap (:, 1) * ones (1, 3); - elseif (ismatrix(rgb) && ndims(rgb) == 3) + gray = ntscmap (:, 1) * ones (1, 3); + elseif (isimage (rgb) && ndims(rgb) == 3) switch(class(rgb)) case "double" gray = mean(rgb,3); @@ -47,6 +46,6 @@ error("rgb2gray: unsupported class %s", class(rgb)); endswitch else - error("rgb2gray: the input must either be an RGB image or a color map"); + error("rgb2gray: the input must either be an RGB image or a colormap"); endif endfunction