Mercurial > octave
changeset 20656:175aed5acb85
ntsc2rgb.m: scale output values to the [0 1] range (patch #8709)
author | Hartmut Gimpel <hg_code@gmx.de> |
---|---|
date | Sun, 25 Oct 2015 19:18:01 +0000 |
parents | 96653365eb66 |
children | bc51aa0d604a |
files | scripts/image/ntsc2rgb.m |
diffstat | 1 files changed, 12 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/image/ntsc2rgb.m Sun Oct 25 17:22:16 2015 +0000 +++ b/scripts/image/ntsc2rgb.m Sun Oct 25 19:18:01 2015 +0000 @@ -58,6 +58,15 @@ 0.62143, -0.64681, 1.70062 ]; rgb = yiq * trans; + ## truncating / scaling of double rgb values for Matlab compatibility + ## (Other input types are not supported by Matlab. We deal with + ## them anyways, but do not truncate or scale those.) + if (cls == "double") + rgb = max (0,rgb); + idx = find (any (rgb'>1)); + rgb(idx,:) = rgb(idx,:) ./ (max (rgb(idx,:), [], 2) * ones (1,3)); + endif + rgb = colorspace_conversion_revert (rgb, cls, sz, is_im, is_nd, is_int); endfunction @@ -74,6 +83,9 @@ %! rgb_img = rand (64, 64, 3); %! assert (ntsc2rgb (rgb2ntsc (rgb_img)), rgb_img, 1e-3); +## test cropping of rgb output +%!assert (ntsc2rgb ([1.5 0 0]), [1 1 1]); + ## Test input validation %!error ntsc2rgb () %!error ntsc2rgb (1,2)