Mercurial > hg > octave-nkf
changeset 15717:3d2357969627
NTSC images can only be of class double.
* ntsc2rgb.m: Validate input is only of class double. Remove code
for conversion of integer input. Remove FIXME note.
* rgb2ntsc.m: Document that NTSC output is always of class double.
Convert inputs of class single to double. Remove FIXME note.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 02 Dec 2012 22:36:07 -0800 |
parents | e8a4b99f8bd8 |
children | d1285ebe60ca |
files | scripts/image/ntsc2rgb.m scripts/image/rgb2ntsc.m |
diffstat | 2 files changed, 7 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/image/ntsc2rgb.m +++ b/scripts/image/ntsc2rgb.m @@ -45,9 +45,8 @@ print_usage (); endif - cls = class (yiq); - if (! any (strcmp (cls, {"uint8", "uint16", "single", "double"}))) - error ("ntsc2rgb: invalid data type '%s'", cls); + if (! isa (yiq, "double")) + error ("ntsc2rgb: YIQ must be of type double"); endif ## If we have an image convert it into a color map. @@ -55,12 +54,6 @@ is_image = true; sz = size (yiq); yiq = [yiq(:,:,1)(:), yiq(:,:,2)(:), yiq(:,:,3)(:)]; - ## Convert to a double image. - if (isinteger (yiq)) - low = double (intmin (cls)); - high = double (intmax (cls)); - yiq = (double (yiq) - low) / (high - low); - endif else is_image = false; endif @@ -80,8 +73,6 @@ rgb = yiq * trans; - ## FIXME: ntsc2rgb does not preserve class of image. - ## Should it also convert back to uint8, uint16 for integer images? ## If input was an image, convert it back into one. if (is_image) rgb = reshape (rgb, sz); @@ -106,6 +97,6 @@ %% Test input validation %!error ntsc2rgb () %!error ntsc2rgb (1,2) -%!error <invalid data type 'cell'> ntsc2rgb ({1}) +%!error <YIQ must be of type double> ntsc2rgb (uint8 (1)) %!error <must be a matrix of size Nx3 or NxMx3> ntsc2rgb (ones (2,2))
--- a/scripts/image/rgb2ntsc.m +++ b/scripts/image/rgb2ntsc.m @@ -20,7 +20,8 @@ ## @deftypefn {Function File} {@var{yiq_map} =} rgb2ntsc (@var{rgb_map}) ## @deftypefnx {Function File} {@var{yiq_img} =} rgb2ntsc (@var{rgb_img}) ## Transform a colormap or image from red-green-blue (RGB) color space to -## luminance-chrominance (NTSC) space. +## luminance-chrominance (NTSC) space. The input may be of class uint8, +## uint16, single, or double. The output is of class double. ## ## Implementation Note: ## The reference matrix for the transformation is @@ -67,6 +68,8 @@ low = double (intmin (cls)); high = double (intmax (cls)); rgb = (double (rgb) - low) / (high - low); + elseif (isa (rgb, "single")) + rgb = double (rgb); endif else is_image = false; @@ -86,8 +89,6 @@ ## Convert data. yiq = rgb * trans; - ## FIXME: rgb2ntsc does not preserve class of image. - ## Should it also convert back to uint8, uint16 for integer images? ## If input was an image, convert it back into one. if (is_image) yiq = reshape (yiq, sz);