1## Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2005, 2006, 2007, 2008
4## This file is part of Octave.
6## Octave is free software; you can redistribute it and/or modify it
7## under the terms of the GNU General Public License as published by
8## the Free Software Foundation; either version 3 of the License, or (at
9## your option) any later version.
11## Octave is distributed in the hope that it will be useful, but
12## WITHOUT ANY WARRANTY; without even the implied warranty of
13## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14## General Public License for more details.
16## You should have received a copy of the GNU General Public License
17## along with Octave; see the file COPYING. If not, see
18## <http://www.gnu.org/licenses/>.
21## @deftypefn {Function File} {} rgb2ntsc (@var{rgb})
22## Transform a colormap or image from RGB to NTSC.
26## Author: Tony Richardson <arichard@stark.cc.oh.us>
30function yiq = rgb2ntsc (rgb)
36 ## If we have an image convert it into a color map.
37 if (ismatrix (rgb) && ndims (rgb) == 3)
40 rgb = [rgb(:,:,1)(:), rgb(:,:,2)(:), rgb(:,:,3)(:)];
41 ## Convert to a double image.
44 low = double (intmin (C));
45 high = double (intmax (C));
46 rgb = (double (rgb) - low) / (high - low);
52 if (! ismatrix (rgb) || columns (rgb) != 3)
53 error ("rgb2ntsc: argument must be a matrix of size Nx3 or NxMx3");
57 trans = [ 0.299, 0.596, 0.211;
58 0.587, -0.274, -0.523;
59 0.114, -0.322, 0.312 ];
63 ## If input was an image, convert it back into one.
65 yiq = reshape (yiq, Sz);